68

I have a service foo which currently starts at runlevel 3 and above. How can I stop it from doing so, without using update-rc.d foo stop 3 ., which (if I understand it correctly) would turn off the service at each runlevel change.

(ie., if I was at runlevel 1 and enabled foo, then when I changed to runlevel 3 it would be disabled, no?)

Running Debian GNU/Linux Lenny.

lfaraone
  • 1,581
  • 2
  • 17
  • 22

11 Answers11

63

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.

PEra
  • 2,825
  • 17
  • 14
  • 2
    Any ideas how to do it on Debian 8? `sudo update-rc.d -f sunrpc remove` does not work; its still present after a reboot. –  Jun 08 '17 at 12:52
  • Debian 9 This wasn't working for me, and then I realized, oh derp, need sudo. update-rc.d gives no feedback if you forget to sudo. I confirmed the links were gone with `ls /etc/rc*.d` – Jason Dunkelberger Apr 29 '18 at 16:55
  • The command failed on Ubuntu `16.04` – Stephane Jul 13 '18 at 09:20
  • Make sure you pass the correct service name, update-rc.d does not give you any feedback if it doesn't exist. – marcovtwout Dec 12 '18 at 13:40
  • What if you want to re-enable it later? Below @"Not Now"'s answer is better, as you can disable and re-enable after. `update-rc.d apache2 disable` – Wadih M. Mar 12 '19 at 18:09
  • About `remove`, the [docs](https://manpages.debian.org/buster/init-system-helpers/update-rc.d.8.en.html) says, "The script must have been deleted already", and, "update-rc.d is usually called from a package's post-removal script when that script is given the purge argument." As for removing symlinks by hand, at least if you want to disable a service on all run levels it's best to use `update-rc.d SERVICE disable`, or else the symlinks will be restored on subsequent package upgrade. – x-yuri Feb 07 '21 at 19:56
60

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.

rubo77
  • 2,282
  • 3
  • 32
  • 63
Not Now
  • 3,532
  • 17
  • 18
16

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
Robert Siemer
  • 543
  • 9
  • 19
  • 1
    +1 This is such a helpful answer - and if I hadn't happened upon it I would have been stung later on - thanks! –  Jun 14 '12 at 10:36
  • Can you just ````unlink xyz.service```` as well? – jaggedsoft Nov 27 '15 at 06:48
  • @NextLocal, I forgot why I wrote that, but I believe if a service has System V init scripts, `systemd` will use them. – So the link tells it not to look for them. – Robert Siemer Nov 30 '15 at 00:17
  • Note that editing the `/etc/default/xyz` file to add an `exit` will not prevent the packager to overwrite the file with the correct version on the next upgrade. (The package saves configuration files, and in most cases init scripts are not viewed as such.) So in most cases that would not help. – Alexis Wilke Apr 23 '17 at 18:26
  • Devuan comes to the rescue: instead of systemd it embraces the classic SysV rc.d/init.d system (or openrc as well if someone opts for that). – Csaba Toth Sep 01 '18 at 20:12
6

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.

Mark Levinsky
  • 61
  • 1
  • 1
3

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 .
freiheit
  • 14,334
  • 1
  • 46
  • 69
3

I think this would do the job: insserv -r foo

user38551
  • 31
  • 1
1

Start using insserv from Debian7

Output all services and it runlevel information

insserv --showall

Remove the listed scripts from all runlevels

insserv --remove [specify_script]
cocoa
  • 11
  • 1
1
sudo update-rc.d SERVICE disable

If you want to specify run levels.

sudo update-rc.d SERVICE disable|enable [S|2|3|4|5]

Remember to change service to the name of the program.

sudo service SERVICE restart
Eddie
  • 111
  • 3
1

Why don't you backup the startup script somewhere else and remove it in the /etc/init.d/ ? If the update-rc.d doesn't work.

0

On a red hat based system you could use

chkconfig httpd off
chkconfig httpd --del

to remove the server from runlevels

on debian based system all services are supposed to be started by the files found in the /etc/rc?.d/ directories these files then have a symbolic link to the corresponding files in the /etc/init.d/ directory. If you wish for a service not to start by default then you can rename/remove it from the /etc/rc?.d directory and your change will be preserved on package upgrade as long as one of the start links still appear in one of the other (3,4 and 5) directories. Or you can use the update-rc.d command to change the link(s) and if you want to start the service after then you can use /etc/init.d/service_name start if you leave the start off the end it will give you the options that can be used like stop, restart, reload ...

I think you can use sysv-rc-conf to disable it though.

Warren P
  • 1,195
  • 7
  • 20
  • 35
Rodent43
  • 697
  • 3
  • 11
0

Ubuntu's Bootup Manager is kind of sysv-rc-conf light, a more friendly, GUI version, and many folks reading this thread will appreciate that.

http://www.marzocca.net/linux/bum.html