Disable a startup of service in Ubuntu

Hi! If you're new here, you may want to subscribe to the Unix Tutorial RSS feed to get regular tips & tricks for all flavors of Unix. You can follow me on Twitter, too! Thanks for visiting!

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 ...
/etc/rc0.d/K50proftpd
/etc/rc1.d/K50proftpd
/etc/rc2.d/S50proftpd
/etc/rc3.d/S50proftpd
/etc/rc4.d/S50proftpd
/etc/rc5.d/S50proftpd
/etc/rc6.d/K50proftpd

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!

Related books

If you want to learn more, here's a great book:


ubuntu-kung-fu-practical-guide

Ubuntu Kung Fu

See also:

Unix glossary

Please share:
  • Digg
  • del.icio.us
  • Netvouz
  • BlinkList
  • Fark
  • Furl
  • kick.ie
  • Netscape
  • Reddit
  • StumbleUpon
  • Technorati
  • YahooMyWeb

3 comments ↓

#1 manu on 02.14.09 at 4:25 pm

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

#2 Chhama on 02.16.09 at 10:17 am

How will i re-enable the service?

#3 Dmitriy Altuhov on 04.01.09 at 6:35 am

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

Leave a Comment