• First Steps
  • General
  • Projects
Facebook Twitter YouTube
Tutorials for Raspberry Pi Tutorials for Raspberry Pi
  • Hardware & GPIO
  • Sensors & Components
  • Scale
  • Cases
  • Fingerprint
  • Gas Sensor
  • Heartbeat
  • German
  • French
Tutorials for Raspberry Pi Tutorials for Raspberry Pi
Home»Software»Raspberry Pi Autostart: Start the Program automatically

Raspberry Pi Autostart: Start the Program automatically

Facebook Twitter LinkedIn Tumblr Email Reddit
Raspberry Pi Autostart
Share
Facebook Twitter LinkedIn Email Tumblr Reddit Telegram WhatsApp

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:

Shell
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
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.

 

autostart shell start-up
Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
Previous ArticleInstall and set up Raspberry Pi Wifi Stick
Next Article Fan control for better Overclocking of the Raspberry Pi

Related Posts

Control all GPIOs with the Raspberry Pi REST API via Python

Using TensorFlow Lite with Google Coral TPU on Raspberry Pi 4

Raspberry Pi Samba Server: Share Files in the Local Network

Build Live Text Recognition with the Raspberry Pi (OCR)

3 Comments

  1. Furkan on 26. September 2019 10:47

    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 ?

    Reply
  2. Matt on 12. January 2021 7:44

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

    Reply
  3. Alister Ware on 13. November 2021 17:17

    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/

    Reply

Leave A Reply Cancel Reply

8×8 LED Dot Matrix – Assembly and Installation (Raspberry Pi)

ESP8266: Install Arduino IDE for the ESP32 – Tutorial

MCP3008: Read out Analog Signals on the Raspberry Pi

Raspberry Pi Web Server Installation Part 6 – DNS Server via No-IP

Fan control for better Overclocking of the Raspberry Pi

Wireless communication between Raspberry Pi’s via MQTT broker/client

Subscribe to Blog
Subscribe to Raspberry Pi Tutorials and don't miss any new Tutorial!
Subscribe

Thank you!

We will contact you soon.

Tutorials for Raspberry Pi
Facebook Twitter YouTube
  • Contact & Disclaimer

Type above and press Enter to search. Press Esc to cancel.