Disable a startup of service in Ubuntu

If for whatever reason you stop using a certain service in your Ubuntu install and would like to disable automatic restarting for it upon system reboot, all it takes to do it is just one command line.

Startup and shutdown scripts in Unix

In most Unix distros, the startup and shutdown sequences of various system services are managed using a set of startup and shutdown scripts.

Startup scripts a're usually located either in /etc/init.d or in /etc/rc.d/init.d/ directories (sometimes /etc/init.d is a symlink to /etc/rc.d/init.d). On top of these directories, they're also a set of directories for each of your system runlevels: /etc/rc0.d, /etc/rc1.d, /etc/rc3.d, etc.

The reason scripts are organized this way is because in runlevel specific directories you only have symbolic links referring to the original script in /etc/init.d. Each of the scripts in this directory usually caters for a number of scenarios: starting a service up, stopping it, and, optionally, restarting it (which is the same as stopping/starting sequence in most cases).

As your Unix OS goes from one runlevel to another following a startup or shutdown, it looks for symlinks in /etc/rc*.d directories and uses them to ensure the services specified there are started or stopped accordingly.

Promise: One day, I will certainly spend more time talking about the Unix OS startup process itself, but for today I just want to concentrate on the scripts for a particular service.

So, for the FTP service, I have the /etc/init.d/proftpd startup/shutdown script plus the following set of symlinks referring to it:

/etc/rc0.d/K20proftpd -> ../init.d/proftpd
/etc/rc1.d/K20proftpd -> ../init.d/proftpd
/etc/rc6.d/K20proftpd -> ../init.d/proftpd
/etc/rc2.d/S20proftpd -> ../init.d/proftpd
/etc/rc3.d/S20proftpd -> ../init.d/proftpd
/etc/rc4.d/S20proftpd -> ../init.d/proftpd
/etc/rc5.d/S20proftpd -> ../init.d/proftpd

If you look at any of them, you can see that they really are symlinks:

ubuntu# ls -l /etc/rc3.d/S20proftpd
lrwxrwxrwx 1 root root 17 Jan 13 03:39 /etc/rc3.d/S20proftpd -> ../init.d/proftpd

Disabling startup of a service in Ubuntu

The procedure for disabling a service in Ubuntu is very simple: all you have to do is remove the symlinks from all the runlevel-specific directories, /etc/rc*.d, so that no links are pointing to the original /etc/init.d script for your service. That original script will be kept, so you can re-enable the startup/shutdown of the service whenever you feel like using it again.

This example below shows how a service called "proftpd" was disabled on my system:

ubuntu# update-rc.d -f proftpd remove
Removing any system startup links for /etc/init.d/proftpd ...

You obviously don't have to reboot your system just to stop your service though, so instead you can simply do this:

ubuntu# /etc/init.d/proftpd stop
 * Stopping ftp server proftpd

That's all there is to it! Good luck with disabling the unused services!

Recommended books:

See also:

Unix glossary

  • manu

    doesn't the package manager recreate the links next time the package is updated?

  • How will i re-enable the service?

  • A common system administration error is to delete the links with the thought that this will "disable" the service,
    i.e., that this will prevent the service from being started. However, if all links have been deleted then the next
    time the package is upgraded, the package’s postinst script will run update-rc.d again and this will reinstall
    links at their factory default locations. The correct way to disable services is to configure the service as
    stopped in all runlevels in which it is started by default. In the System V init system this means renaming the
    service’s symbolic links from S to K.

    man update-rc.d

  • Pingback: Misterdom’s World » Blog Archive » Removing a Service from Init.d in Linux()

  • Given Dmitriy's comment it sounds another approach would be to use:

    # update-rc.d proftpd disable

    This should prevent the upgrade scripts from putting the symlinks back.

  • Following Dmitriy's comment, that's precisely what the -disable- option does in the update-rc.d command(renames the service's symbolic links from S to K) , and to re-enable the service…well just use the -enable- option in the update-rc.d command =-)

  • Agree with Dmitriy. But I only investigated the man after reading this post. Was going to post the very same quote about it, that Dmitriy already posted 😉

  • In Ubuntu's community, however:

    To deactivate a script (meaning that it will not be executed at bootup), remove the corresponding symlink from /etc/rc?.d. Do not use the update-rc.d command for this purpose! It is only used in package installation scripts, and not designed for this kind of runlevel management.

    However, there is a problem:
    * To restore the links with the right S?? or K?? values you have to look up those values on another system or take a look at the deb-Package install scripts …


  • Pedro

    Where are the ln examples?
    For both the soft link and the hard link the examples of how to actually use ln to create the links appear to be missing.

  • Pingback: Désactiver un service Ubuntu()

  • Pingback: Deactavate service | Intspaces()

  • Pingback: Do I need rpcbind, nmbd and smbd ?()

  • Pingback: Ubuntu XP » Désactiver un service Ubuntu()