Again and again, it happens that you install Programs, but do not start them automatically when booting. In order to use the Raspberry Pi autostart, all you need to do is to store the information in the /etc/rc.local file in the Linux system.
This is, for example, the case with DNS service noip2. In the following I show how to start a program automatically without much effort, using noip2 as an example.
Raspberry Pi Autostart Script
First of all, a Script has to be created in the Directory /etc/init.d/ which starts the Program, so we create a Script (it must not necessarily have a file extension)
sudo nano /etc/init.d/NameOfTheScipt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#! /bin/sh ### BEGIN INIT INFO # Provides: noip # Required-Start: $syslog # Required-Stop: $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: noip server # Description: ### END INIT INFO case "$1" in start) echo "noip is starting" # Starting Programm /usr/local/bin/noip2 ;; stop) echo "noip is ending" # Ending Programm killall noip2 ;; *) echo "Use: /etc/init.d/noip {start|stop}" exit 1 ;; esac exit 0 |
Instead of noip2, of course, there can be any other Program installed, but be careful that no user interaction is waited (as the confirmation in apt-get), as if it comes to the worst case scenario, it will be waiting for the input at boot time and the Pi will not start.
Next, assign the required rights (Read & Write)
sudo chmod 755 /etc/init.d/NameOfTheScipt
sudo /etc/init.d/NameOfTheScipt start
sudo /etc/init.d/NameOfTheScipt stop
sudo update-rc.d NameOfTheScipt defaults
sudo update-rc.d -f NameOfTheScipt remove
If you want to know more about the topic, you can do it here.
Raspberry Pi Autostart – more options
Another option to start a Script or Program is “Cron”. This makes it possible to start a command (which may be a call to a Program or similar) at a specific time. The time may either be set to e.g. the same time of the day or after the system is booted. Cron offers many customization options, which can be viewed here.
3 Comments
Hello, I have just received a RASPBERRY PI with SD CARD 16 GB. SD CARD has its autostart. Before I changed something:
ps aux | grep test.sh
and I see 2 lines. I select first line. Then,
kill 674 etc.
ps aux | grep project.py
I did same things.
Then, I open project folder, and I changed any code in any .py file. Then, how can I auto start all over again. Do I have to ? Those who gave me this raspberry pi followed the instruction to auto start from this link: https://www.wikihow.com/Execute-a-Script-at-Startup-on-the-Raspberry-Pi
Please help me ?
When I test the script, I receive the following error:
Running Firefox as root in a regular user’s session is not supported. ($XAUTHORITY is /home/pi/.Xauthority which is owned by pi.)
i/ect/init.d is depreciated .
It is better to use systemd for this functionality & it is hardly any more complicated (I find it easier!)
https://www.makeuseof.com/what-is-systemd-launch-programs-raspberry-pi/