0

I'm doing a project where raspberry pi runs headless. I have written two python programs, one for swiching off the raspberry pi via gpio push button and the other is a opencv-python program. I need to run both the programs at startup and both are endless scripts . The first program shutdown rpi safely when the button is pressed and other does image processing. How to run both automatically when rpi is started ?

  • Not sure what to do, both are endless scripts. will putting python p1.py & python p2.py & in /etc/rc.local work ? – parthi82 Mar 17 '15 at 14:12
  • I'd either do that or add it as a reboot cron job. Whatever you try make sure you give the full path to the script, e.g. not p2.py but /home/pi/p2.py. – joan Mar 17 '15 at 15:29
  • If you put them in /etc/rc.local and they are persistent, make sure you fork them, e.g. p1.py &. – goldilocks Mar 17 '15 at 15:32
1

Use either crontab -e and append @reboot path/to/script or navigate to /etc/rc.local and put it in there like this script.py &.

3

Look into using Supervisor to manage your scripts. It is available as a package for Raspbian.

Supervisor can restart the scripts if they crash and capture any the output and log it. It can also run the script as a non-privileged user if you want.

2

You can use cron:

crontab -e

and append:

@reboot path/to/your/script

This approach doesn't restart your scripts if they exit with an error, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.