How to execute a command, program or script at startup (init mini-howto)

This is a (very) simple guide to adding a command or script to the debian / ubuntu startup sequence. There is obviously much more to it, but if you need to do very simple stuff, this can be useful.

1. Put the script in /etc/init.d – do not forget to give it execute permissions (’chmod a+x foobar’)
2. Run :

root@box:~# update-rc.d foobar defaults

‘foobar’ being the name of the script (must be in /etc/init.d)

This starts service (invoking script with start argument) in boot sequence with execution order 20 for runlevels 2,3,4,5 (= all multiuser levels) and stops it on runlevels 1 and 6 (reboot/shutdown/single user).

If you need fine tuning, you can specify execution order and runlevels, eg :

root@box:~# update-rc.d foobar start 30 2 3 4 5 . stop 70 0 1 6 .

(note the full stop character)

To remove script from startup sequence :
1. Delete script from /etc/init.d
2. Run :

root@box:~# update-rc.d foobar remove

To remove script from boot sequence while leaving script in /etc/init.d, use :

root@box:~# update-rc.d -f foobar remove

Alternatively, you can also use the all-in-one tool :

root@box:~# apt-get install sysv-rc-conf
root@box:~# sysv-rc-conf

Leave a Reply

Your email address will not be published. Required fields are marked *