Tuesday, 11 August 2009

How-To: Don't Start Unneeded Services on Start-Up in Debian

By default, Debian uses run level 2, which means that in normal, multi-user mode Debian will automatically run scripts located in the /etc/init.d/ directory. But how does it do it? First, it will look in the corresponding directory of the run level, /etc/rcN.d/ (which, in the case of run level 2 will be /etc/rc2.d/) and run all the scripts which are pointed to by the symbolic links starting with letter S in this directory.

So all the symbolic links in /etc/rc2.d/ actually point out to executable scripts in /etc/init.d/.

If you perform an ls -l /etc/rc2.d you will see an output which can look something like this:
As you can see, all of them are symlinks to scripts in /etc/init.d/. The links which start with a K will determine the respective script not to start, while the ones starting with S will run it with the start argument. All the scripts in /etc/init.d can be run as:

/etc/init.d/script_name start|stop|restart

Now, in order to prevent a daemon from running at system start-up, for example S20ircd-ircu (the ircu IRC server), all you have to do is rename it to a name which starts with K, then a two-digit number made up from the difference between 100 and the number which follows S, and then its name. For our example, that would be (as root):

mv S20ircd-ircu K80ircd-ircu

The next time you reboot your Debian box, the IRC daemon will not be started automatically, but you'll be able to rename it back to S20ircd-ircu or start it manually, as root, like this:

/etc/init.d/ircd-ircu start

A simple and clear explanation on how things work can be found in the files /etc/rc2.d/README and /etc/init.d/README.

One of the popular uses of this is to prevent display managers from starting up, for example gdm or kdm:

mv S99kdm K01kdm

This will prevent kdm (KDE display manager) from starting up, leaving you at a shell login prompt. Useful when you only need a server, or want to live in command-line only for a while. To start it up, just use, as root:

/etc/init.d/kdm start


Nat said...

man update-inetd

If the 'sysv-rc' package is installed: "man update-rc.d"

Jonathas Rodrigues said...

or you can install rcconf and all of that will be much simpler.