Raspberry Pi Autostart: Start the Program automatically

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
with the following content:

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
and test the script by starting it
sudo /etc/init.d/NameOfTheScipt start
and stop right away:
sudo /etc/init.d/NameOfTheScipt stop
So that the script is also accessed when booting, we do the following:
sudo update-rc.d NameOfTheScipt defaults
Now the program should run at startup. Should you one day change your mind and want to take the program out of the Autostart, you can do so with:
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.


2 Responses

  1. 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 ?

  2. 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.)


Leave a Comment

Your email address will not be published.