Updated: May 8, 2009
If you want to manage the services in your Linux distribution without manually hacking the scripts in runlevel directories, you may want to use the chkconfig and sysv-rc-conf utilities. chkconfig is used on RedHat-based distros, sysv-rc-conf is for Debian variants.
The utility is included by default with RedHat (and sons) and SUSE. This means that system administration is a simple affair on these distributions. All you have to do is learn the basic chkconfig syntax. The commands must be run as root.
--levels <levels> defines the runlevels in which you want the particular service switch to be turned. The runlevels are listed one next to another without spaces, commas or any other delimiter. Simply a string of numbers, e.g. 34 - signifies runlevels 3 and 4.
<service> is the actual service we want enabled/disabled for the listed runlevels.
<switch> is on/off, meaning enabled/disabled service for the particular runlevels.
Let's see a practical example:
Here, we turned the SSH service (daemon called sshd) off and on in runlevel 2. Simple, eh?
And we can also list all services using the --list flag:
Let's see what sysv-rc-conf offers:
Let's take a look on sysv-rc-conf on Ubuntu.
By default, the utility is not installed. We will install it via Synaptic.
The usage model is practically identical to chkconfig. The only difference is that sysv-rc-conf also has a text-based GUI. You can use a simple, table-like interface to manage services, using Spacebar to toggle their status (enable/disable), with letter X as the switch.
The other functions are identical, including --list and --levels:
One important thing: please note in the screenshot above that I've written ssh instead of sshd. This is a mistake, but there was no alert from the system. Indeed, both chkconfig and sysv-rc-conf will ignore your attempts for non-existent services, so pay attention to possible mistakes!
You may be asking yourselves what these tools do. Well, without getting too technical, I'll try to portray a simple enough picture.
Using a classic model for example, Linux works in runlevels, sets of modes similar somewhat to Windows Safe mode with/without command prompt and/or networking. Runlevels define what runs when the system boots. Runlevel 1 is the maintenance mode, also known as single mode, with root access only and minimal shell. Runlevel 3 is the system level with networking and no GUI. Modern desktop distros usually boot in runlevel 5, which is the full system level, with networking and GUI. And so forth.
Definitions for what services should boot in each runlevel are listed under /etc/rcX.d/ directories, where X signifies the runlevel. Inside these directories, you will find scripts, starting with letter S and a two-digit number, e.g. S04somescript. These are the Start scripts for relevant services. Starting according to their number, from the lowest to the highest, the scripts are invoked and run on startup.
There is also a set of Kill scripts, which begin with K and are used to stop the services when the system is being shut down, rebooted or runlevels switched.
What the chkconfig and sysv-rc-conf do is merely create or remove these scripts from relevant directories. Simple and beautiful.
For more details, you may want to read the man pages.
Admining Linux systems is a serious, difficult task. You can do without the tedious, futile tasks like manually configuring scripts for the system services, worrying about spelling mistakes or bad syntax. Let the machine work hard, instead of you.
chkconfig and sysv-rc-conf are a must in the hands of even the most bored system administrator. They can greatly simplify the routine of properly configuring the systems for your environment.