31

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?

2 Answers 2

45

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.

2
  • Thanks for the great response! chmod is an easy solution! I started reading manpages.ubuntu.com/manpages/precise/man8/update-rc.d.8.html and is helping me understand init. Got me thinking... I should read more of the manual.
    – iDev247
    Commented Jun 28, 2012 at 2:36
  • 1
    Glad to help. I should note that the chmod solution should only be used very temporarily. I haven't verified this, but I could see the Upstart system (what Ubuntu uses to start/stop processes automatically) getting confused by this.
    – EEAA
    Commented Jun 28, 2012 at 3:05
10
$ sudo update-rc.d -f servicename remove
1
  • 1
    This answer does not match the question which wants to keep the script. “When invoked with the remove option, update-rc.d removes any links in the /etc/rcrunlevel.d directories to the script /etc/init.d/name. The script must have been deleted already.” manpages.ubuntu.com/manpages/xenial/en/man8/update-rc.d.8.html
    – Melebius
    Commented Jan 31, 2018 at 7:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .