0

I've been having a lot of problems trying to get my python script to run at boot. I've essentially narrowed it down to a problem with forking.

I'm running on a RPi3.

In rc.local if I have:

python /home/pi/script.py

It seems to run, however as soon as I add

python /home/pi/script.py &

I get zero results. If I run rc.local manually after boot the fork appears to work as expected. I've also tried to point rc.local to a .sh file in /home/pi with exactly the same results. This even happens with basic echo commands:

echo "Hello world" > /tmp/log.txt

vs

echo "Hello world" > /tmp/log/txt &

Any help would be greatly appreciated.

Luc
  • 1

1 Answers1

0

I'm guessing that this has something to do with the fact that all child processes of the rc.local script get killed as soon as it reaches the end of the script, which is just about instantaneous if the only command in the file is running a python script as a background process.

The fork will get killed before it can do anything useful.

If you want the process to keep running after rc.local has ended, you should run the process as a daemon.

Some examples on how to do this can be found in this question: Run bash script as daemon

Powertieke
  • 2,368
  • 1
  • 14
  • 21