Disable a service from starting at all runlevels?

Solution 1:

Configure Linux Startup Applications with sysv-rc-conf:

apt-get install sysv-rc-conf

As others have pointed out, here is also update-rc.d for the cmd line.

For example, run

update-rc.d apache2 disable

to disable apache2 from all run levels.

Solution 2:

The "stop" term does not prevent the daemon from starting but rather shuts it down while entering the specified runlevel.

If you just want to remove a service/daemon from a single runlevel, update-rc.d as pointed out bei freiheit or simply remove the symlink from /etc/rcX.d/, where X is your runlevel. If you don't want the service to start automatically, update-rc.d -f foo remove will do the trick.


Solution 3:

Short:

There is no reliable way to do this quickly.

Long:

Current Debian (Debian unstable as of 2012-06-01) has currently no reliable short way to consistently disable a service/daemon. – Because an upgrade of a daemon package unconditionally runs “/etc/init.d/package restart”, having it disabled for this runlevel or not.

To make sure a daemon doesn’t start, you could:

  • uninstall it
  • make a local divert of the /etc/init.d/xyz script (this way, no tools will find it)
  • use/abuse a config file of the corresponding package to provoke an early exit of that script (e.g. put an “exit” early in /etc/default/xyz in case it is sourced from the init script)
  • look in that init-script for predefined “official” ways to not start that daemon

There is/was(?) some init-policy-something step for init scripts in Debian, which was supposed to fill this missing functionality. – I tried to use it, found it complicated, found a bug, and never touched it again.

Update:

Switch to “systemd”, an alternative to “initd”. A debian package exists, and you can disable a service with something like this:

cd /etc/systemd/system
ln -s /dev/null xyz.service

Solution 4:

Run this command

apt-get install rcconf

Once installed, run rcconf in SSH and you will receive a dialog box displaying all services set to run on boot. Select the ones by pressing Space to disable/enable the particular and you're done, simpley click on Ok and that service wont bother to start again on next boot. Being using this for years. Very handy tool for Debian/Ubuntu users like me.


Solution 5:

I'm confused what you're trying to accomplish.

What run levels do you want foo running in?

If you always want it running, use update-rc.d foo defaults; that will stop it in 0, 1 and 6, while leaving it running in 2, 3, 4 and 5. (1 shouldn't run anything but a shell, 0 and 6 are halt and reboot)

If you want to specify exactly what run levels to run in:

update-rc.d foo stop 0 1 6 3 . start 2 4 5 .