Chkconfig Command

Managing services on a Linux System

chkconfig


The chkconfig command is a popular package that can be installed that allows you to enable or disable system services. chkconfig allows you to easily manipulate the services that start under certain runlevels. Issuing the command by itself with no additional parameters will result in any known services to be displayed along with their current state and runlevel. Any service that is configured in a run level will have a status of "on". Any services that are not configure in a runlevel will have the status of "off". chkconfig comes as standard with Red hat based systems and SUSE systems.



Listing services defined in a runlevel


To display all services we can simply issue the command "chkconfig" or "chkconfig --list" to display the current status of services and their relation to the relevant runlevel:



john@john-desktop:~$ chkconfig ntop
ntop  on
john@john-desktop:~$ chkconfig --list ntop
ntop                      0:off  1:off  2:on   3:on   4:on   5:on   6:off

"chkconfig" issued on its own only supplies information to your current runlevel. For a more detailed listing you can pass the "--list" parameter. Under Red Hat based and SUSE based systems you can issue "chkconfig" on its own an you will receive a detailed output by default. The output has been cut short in the example as it is quite large in size:


john@john-desktop:~$ chkconfig --list
acpi-support              0:off  1:off  2:on   3:on   4:on   5:on   6:off
acpid                     0:off  1:off  2:off  3:off  4:off  5:off  6:off
alsa-restore              0:off  1:off  2:off  3:off  4:off  5:off  6:off
alsa-store                0:off  1:off  2:off  3:off  4:off  5:off  6:off
anacron                   0:off  1:off  2:off  3:off  4:off  5:off  6:off
apparmor                  0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
apport                    0:off  1:off  2:off  3:off  4:off  5:off  6:off
atd                       0:off  1:off  2:off  3:off  4:off  5:off  6:off
atop                      0:off  1:off  2:on   3:on   4:on   5:on   6:off
avahi-daemon              0:off  1:off  2:off  3:off  4:off  5:off  6:off
binfmt-support            0:off  1:off  2:off  3:off  4:off  5:off  6:off
bluetooth                 0:off  1:off  2:off  3:off  4:off  5:off  6:off
bootlogd                  0:off  1:off  2:off  3:off  4:off  5:off  6:off
brltty                    0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
console-setup             0:off  1:off  2:off  3:off  4:off  5:off  6:off
cron                      0:off  1:off  2:off  3:off  4:off  5:off  6:off
cryptdisks                0:on   1:off  2:off  3:off  4:off  5:off  6:off
cryptdisks-early          0:on   1:off  2:off  3:off  4:off  5:off  6:off
cryptdisks-enable         0:off  1:off  2:off  3:off  4:off  5:off  6:off
cryptdisks-udev           0:off  1:off  2:off  3:off  4:off  5:off  6:off
cups                      0:off  1:off  2:off  3:off  4:off  5:off  6:off
dbus                      0:off  1:off  2:off  3:off  4:off  5:off  6:off
dmesg                     0:off  1:off  2:off  3:off  4:off  5:off  6:off

To list on a particular runlevel, we can use the same command in conjunction with "grep":



john@john-desktop:~$ chkconfig --list | grep 3:on
acpi-support              0:off  1:off  2:on   3:on   4:on   5:on   6:off
atop                      0:off  1:off  2:on   3:on   4:on   5:on   6:off
dns-clean                 0:off  1:on   2:on   3:on   4:on   5:on   6:off
grub-common               0:off  1:off  2:on   3:on   4:on   5:on   6:off
kerneloops                0:off  1:off  2:on   3:on   4:on   5:on   6:off
ntop                      0:off  1:off  2:on   3:on   4:on   5:on   6:off
ondemand                  0:off  1:off  2:on   3:on   4:on   5:on   6:off
pppd-dns                  0:off  1:on   2:on   3:on   4:on   5:on   6:off
pulseaudio                0:off  1:off  2:on   3:on   4:on   5:on   6:off
rc.local                  0:off  1:off  2:on   3:on   4:on   5:on   6:off
rsync                     0:off  1:off  2:on   3:on   4:on   5:on   6:off
saned                     0:off  1:off  2:on   3:on   4:on   5:on   6:off
speech-dispatcher         0:off  1:off  2:on   3:on   4:on   5:on   6:off
sudo                      0:off  1:off  2:on   3:on   4:on   5:on   6:off
sysstat                   0:off  1:off  2:on   3:on   4:on   5:on   6:off
vboxballoonctrl-service   0:off  1:off  2:on   3:on   4:on   5:on   6:off
vboxdrv                   0:off  1:off  2:on   3:on   4:on   5:on   6:off
vboxweb-service           0:off  1:off  2:on   3:on   4:on   5:on   6:off

The above lists only the services that are "on" for runlevel "3". This output will differ on your system depending on what services you are running and also what distribution you are running.


Switching Services "on" and "off"


Sometimes you may want to disable a particular service from starting in a given runlevel. To do this we can use the "chkconfig" command with the level parameter. First we list the service we are going to alter to check what runlevels it is activated on. Then we issue: chkconfig --level 3 MyService off . Obviously you will need to modify the name "MyService" to that of the service we are modifying and change the runlevel accordingly. Please note, you will either have to use sudo or run these commands as root:



root@john-desktop:~# chkconfig --list | grep ntop
ntop                      0:off  1:off  2:on   3:on   4:on   5:on   6:off

root@john-desktop:~# chkconfig --level 2345 ntop off

root@john-desktop:~# chkconfig --list | grep ntop
ntop                      0:off  1:off  2:off  3:off  4:off  5:off  6:off

root@john-desktop:~# chkconfig --level 2345 ntop on

root@john-desktop:~# chkconfig --list | grep ntop
ntop                      0:off  1:off  2:on   3:on   4:on   5:on   6:off

In this example, we looked at what runlevels the service "ntop" would be normally started at. In the example it is set to run at run levels "2,3,4 and 5".

Next we issued "chkconfig --level 2345 ntop off". This resulted in ntop now being disabled.

An finally we added it back to its original state. You will notice that we can concatenate multiple runlevels together.


Adding and Deleting a Service


chkconfig can also be used for adding and removing services into a runlevel. One point to remember is that you can only add a service after it has been installed.



# chkconfig --del ntop

# chkconfig --add ntop