Dec 21

Raspbian: Run a Program at Startup

There are many directions out there that don’t work on Raspbian. Specifically the “upstart” scripts, as Raspbian doesn’t come with upstart, and will mess things up greatly if you install it. Raspbian uses init.d. It’s fairly simple to get things going since a nice script was provided at the link below, mirrored here.

Create script in /etc/init.d

The following is an example based on starting up the no-ip service [/usr/local/bin/noip], but change the name of the script and the command to start and stop it and it would work for any command.

Warning – Its important you test your script first and make sure it doesn’t need a user to provide a response, press “y” or similar, because you may find it hangs the raspberry pi on boot waiting for a user (who’s not there) to do something!

Make script executable

Test starting the program

Test stopping the program

Register script to be run at start-up
To register your script to be run at start-up and shutdown, run the following command:

Note – The header at the start is to make the script LSB compliant and provides details about the start up script and you should only need to change the name. If you want to know more about creating LSB scripts for managing services, see http://wiki.debian.org/LSBInitScripts

If you ever want to remove the script from start-up, run the following command:

Credit: Big huge thanks to: http://www.stuffaboutcode.com/2012/06/raspberry-pi-run-program-at-start-up.html. The words above are his.

Big note from me:
In my case I needed my script to wait for the network to become available, so I modified the script to say:

For more variables you could use, see: https://wiki.debian.org/LSBInitScripts

Leave a Reply