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?

iDev247
  • 751
  • 1
  • 11
  • 23

2 Answers2

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.

EEAA
  • 108,414
  • 18
  • 172
  • 242
  • Thanks for the great response! `chmod` is an easy solution! I started reading http://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 Jun 28 '12 at 02: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 Jun 28 '12 at 03:05
10
$ sudo update-rc.d -f servicename remove
Falcon Momot
  • 24,975
  • 13
  • 61
  • 92
  • 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.” http://manpages.ubuntu.com/manpages/xenial/en/man8/update-rc.d.8.html – Melebius Jan 31 '18 at 07:10