Linux – How to remove/backup script from /etc/init.d/

init.dlinuxUbuntuubuntu-11.04

I've been working with linux for a while but in a rather simple manner.

I understand that scripts in init.d are executed when the os starts but how exactly does it works?

What if I want to keep a script but don't want it to start automaticly?

Say I have a /etc/init.d/varnish and want to disable it temporary. How do I make sure it doesn't start if the os reboots? I don't want to delete the script. What if I want to add it again?

Best Answer

There are a couple ways. If you just want to do this temporarily, you can remove the execute bit from the file:

$ chmod -x /etc/init.d/varnish

Then re-add it when appropriate:

$ chmod +x /etc/init.d/varnish

The "official" way in Ubuntu (as well as in Debian and other Debian derivatives), though, is to use the update-rc.d command:

$ update-rc.d varnish disable

This will remove all of the symlinks from the /etc/rcX.d folders, which take care of starting and stopping the service when appropriate.

See the update-rc.d man page for more information.