I have a python3 script running on a Raspberry Pi on Debian 10 Buster, I can run in a terminal window but not on start up?
I am using the following line of code at the end of the file in /etc/profile
nohup python3 statlogger.py -db=stat_logger_db -sn=test
whilst the line of code works in the terminal window when I run it manually it will not work on starting the pi
I have also tried
nohup python3 statlogger.py & -db=stat_logger_db -sn=test
The python code needs to run at startup and then continuously whilst the pi is powered on, any thought
2
Answers
I spent around 1 day and test 4 solutions for Linux/raspberry startup run script issues. Then here is the solution (I choose crontab)
pi@ crontab -e
Then choose nano and edit like this… It is tricky, ı found after test may be more than 10x times:
My code is waiting for me under /home/pi/beetool. If you don’t change the directory that occurs error.
And my code uses infinite loop so I have to finish with "&" as you see above.
So I hope that helps someone, too …
I aslo shared in: Run Terminal Commands on Raspberry Startup
The best way I have found to run a program on Raspberry Pi at startup is to use the systemd files.
Open a new sample unit file using the following command:
python file path to your file):
Save and exit using "CTRL+E" then when asked to save "Y" and "Enter"
source:
https://www.dexterindustries.com/howto/run-a-program-on-your-raspberry-pi-at-startup/#systemd