Running python script on mac boot

I am trying to run a python script to run on startup. I have the following file: com.test.service.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd >
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.test.service</string>
    <key>ProgramArguments</key>
    <array>
        <string>/bin/sh</string>
        <string>/var/www/html/app/appstart.sh</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

copied to ~ / Library / LaunchAgents /

loaded as

launchctl load -w ~/Library/LaunchAgents/com.test.service.plist

The script has two lines:

/usr/bin/python /var/www/html/app/app.py
echo "hello" >> /var/www/html/app/test.txt

the script is launched (the test.txt file is created using 'hello' in it) however, app.py does not start. for testing purposes, all i did in app.py was:

import os
os.system("echo 'python' >> /var/www/html/app/test.txt")

if i just ran appstart.sh in the terminal then python doesn't run any problems

I have already followed the instructions in this question , but no luck

+4
source share
2 answers

cron, . ,

@reboot /path/to/my/script

cron

script appstart.sh.

, .

crontab -e ( , , nano)

, @reboot /path/to/file

.

+1

, .plist - chmod 644.

" Mac" " ", , . LaunchAgents . .plist /Library/LaunchDaemons root: wheel.

script python, :

<key>ProgramArguments</key>
<array>
    <string>/usr/bin/python</string>
    <string>/var/www/html/app/app.py</string>
</array>
+1

Source: https://habr.com/ru/post/1531387/


All Articles