I was also looking to run my python script on boot so I did a couple things 
that worked as a a short term solution. I added 2 lines to my crontab, an 
@reboot line to run the program when the device starts up as well as a bash 
script to ensure the program is still running.

(Replace main.py with your program name and make sure it doesn't match 
anything else that may be running)

crontab -e

# Runs when the system boots:
@reboot sudo python /path/to/program.py

# Runs every minute and checks that your program is running:
* * * * * sudo bash /path/to/check_process.bash


(Just a note, if you need multiple programs to run on boot, replace 
"@reboot sudo python /path/to/program.py" with a bash script, and place the 
things you need to run on boot in that bash file.)



check_process.bash:

#!/bin/bash

process_id=`ps aux | grep "YOURPROGRAM.py" | grep -v "grep"`;

if [ -z "$process_id" ]; then

    echo "process not running for certain."

    cd /PATH/TO
    cd /PATH/TO/YOURPROGRAM.py &

else 

    echo "YOURPROGRAM.py seems to be running";

fi

The only down side is that if your program crashes, you have to wait up to 
a minute for the crontab to run the check_processes.bash, but otherwise is 
pretty solid.

Now I am also looking for how to run my script as a system service. 




On Thursday, April 7, 2016 at 9:18:43 PM UTC-7, John Baker wrote:
>
> My program runs fine but requires that I use putty.exe and type sudo 
> python myprog.py to run it. I have been reading about systemctl and have 
> written a service file and put it in /lib/systemd/system. It's called 
> paint-flow.service, listing below. I have.. enabled it with systemctl 
> enable paint-flow.service with no errors and tried systemctl start 
> paint-flow.service with no errors but my program doesn't seem to start. 
> When I check the status I get "code=exited, status = 203/EXEC" which 
> doesn't tell me anything, at least nothing that I understand.
>
> Also I tried the same thing with a one-line Hello.py program and same 
> results.
>
> Any help with this newbie problem, please?
>
> [Unit]
> Description=Paint flow control program
>
> [Service]
> WorkingDirectory=/home/debian/Desktop/
> ExecStart=/home/debian/Desktop/python SimB.py
> SyslogIdentifier=SimB
> Restart=on-failure
> RestartSec=5
>
> [Install]
> WantedBy=multi-user.targetI am using Debian 3.8.13
>
>
>
> John
>

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to beagleboard+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to