The correct way to do this in Ubuntu is:
- Copy /etc/init.d/skeleton to scriptname and edit it to your needs.
- Make it executable.
- Install your script into the Debian runlevels via this command.
sudo update-rc.d scriptname defaults
- Check that links to your script exist in other runlevels, e.g rc2.d, rc3.d. You can also confirm that this script is properly installed through the Administration->Bootup Manager GUI.
Check /etc/init.d/README for more detailed instructions and links to the specification document. You can also impose finer control over which run-levels your scripts runs on, and the priority it should get called at:
$ sudo update-rc.d dummy defaults
Adding system startup for /etc/init.d/dummy ...
/etc/rc0.d/K20dummy -> ../init.d/dummy
/etc/rc1.d/K20dummy -> ../init.d/dummy
/etc/rc6.d/K20dummy -> ../init.d/dummy
/etc/rc2.d/S20dummy -> ../init.d/dummy
/etc/rc3.d/S20dummy -> ../init.d/dummy
/etc/rc4.d/S20dummy -> ../init.d/dummy
/etc/rc5.d/S20dummy -> ../init.d/dummy
$ sudo update-rc.d -f dummy remove
Removing any system startup links for /etc/init.d/dummy ...
/etc/rc0.d/K20dummy
/etc/rc1.d/K20dummy
/etc/rc2.d/S20dummy
/etc/rc3.d/S20dummy
/etc/rc4.d/S20dummy
/etc/rc5.d/S20dummy
/etc/rc6.d/K20dummy
$ sudo update-rc.d -n -f dummy start 20 2 3 4 5 .
Adding system startup for /etc/init.d/dummy ...
/etc/rc2.d/S20dummy -> ../init.d/dummy
/etc/rc3.d/S20dummy -> ../init.d/dummy
/etc/rc4.d/S20dummy -> ../init.d/dummy
/etc/rc5.d/S20dummy -> ../init.d/dummy
$ sudo update-rc.d -n -f dummy stop 20 0 6 .
Adding system startup for /etc/init.d/dummy ...
/etc/rc0.d/K20dummy -> ../init.d/dummy
/etc/rc6.d/K20dummy -> ../init.d/dummy
Edit: The first step initially said to follow a template I provided with the answer, but I later realized that a standardized template exists so I've modified the answer accordingly.
4
This is a question for http://www.superuser.com/
– Ricket – 2009-08-12T13:39:33.920(http://blog.stackoverflow.com/2009/07/super-user-semi-private-beta-begins/)
– Ricket – 2009-08-12T13:40:04.623I agree. voting to close – None – 2009-08-12T13:41:08.880
1
Also, to answer Jim's question: http://embraceubuntu.com/2005/09/07/adding-a-startup-script-to-be-run-at-bootup/
– None – 2009-08-12T13:41:57.803You should change the title to something more appropriate. – None – 2009-08-12T14:41:15.597
Why? You get the best results with the default ondemand policy. – psusi – 2012-04-12T14:05:17.720