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 ?
crontab -e and append
@reboot path/to/script or navigate to
/etc/rc.local and put it in there like this
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.
You can use cron:
This approach doesn't restart your scripts if they exit with an error, though.