I am used to autostart with rc.local, after making my program called "test3.py" executable (sudo chmod a+x test3.py). I failed to get it autostarted, means as the first program which the Raspi-stretch has to run. Can anybody tell me how to do it right? Attention please: I am a beginner (though 76 years old). Thanks in anticipation! Klaus
I don't know what you mean with
I failed to get it autostarted, means as the first program which the Raspi-stretch has to run.
I don't believe that you really want it but will assume it so you will see the implications.
/etc/rc.local is not the best place to start programs on bootup. With old style
SysV init system rc.local was meant to start programs as last program after startup. But even that is not guaranteed because with Raspbian Stretch (and Jessie)
SysV is replaced by
systemd and only emulated by
systemd. You have to note that using
/etc/rc.local has limitations due to Compatibility with SysV. Following the recommendation of the developers from systemd you should avoid using it.
To run your
test3.py program as first program isn't possible because the first program that runs is
/sbin/init and that is needed to start all other programs. You have to decide what other programs from the operating system have to run that your program needs to start. You can look at System bootup process what programs when start. A very early point to start your script is just after
But very common to start user scripts on bootup is after
multi-user.target, provided it has only text output and not using graphics. This ensures that all programs and setups from the operating system are available to run the script. To do it you create a new service with a unit file. A very simple unit file for your script you can create with:
rpi ~$ sudo systemctl --force --full edit test3.service
In the empty editor insert these statements (adopted to your needs), save them and quit the editor:
[Unit] Description=My Test3 program After=multi-user.target [Service] ExecStart=/usr/bin/python3 /full/path/to/test3.py [Install] WantedBy=multi-user.target
Enable the new service and reboot:
rpi ~$ sudo systemctl enable test3.service rpi ~$ sudo systemctl reboot
It would help to troubleshoot your problem if you give us a bit more detail regarding what you have tried to so far.
What line did you add to rc.local?
Can you start the script manually?
If everything works, are you using absolute paths for python in rc.local?
If not, make sure your script starts with
in the first line. Then try to start your script in rc.local with
Just a few suggestions until you can provide more details.