Beruflich Dokumente
Kultur Dokumente
com/2011/06/chkconfig-examples/
This article contains 7 practical examples that explains how to use the chkconfig
command.
# vi check.sh
You can also specifically check whether it is configured for a particular run level or
not.
# vi check1.sh
chkconfig network --level 3 && echo "Network service is configured for level 3"
chkconfig network --level 1 && echo "Network service is configured for level 1"
# ./check1.sh
# chkconfig --list
...
To view only the services that are configured to be started during system startup, do
the following. Please note that this assumes that your system startup level is 3.
chkconfig --list | grep 3:on
Note: To view all available system run levels, refer to 6 Stages of Linux Boot Process
To view the startup configuration of a particular service, grep the output of
‘chkconfig –list’ for that service.
The following example shows how to add a new service (for example, iptables) to the
list of services that needs to be started. The ‘chkconfig –add’ command will also turn
on level 2, 3, 4 and 5 automatically as shown below.
Note: “chkconfig –add” only adds an existing service to the list of startup. If the
service doesn’t exist, you should first install it before adding it to the system startup
list. While this is pretty obvious, it is worth to mention it, as a newbie might make
this mistake.
To remove it from the startup list, use the –del option as shown below.
The following example will turn off nfserver service for level 5
You can also combine multiple levels. The following example will turn off nfsserver
for both level 3 and 5.
When chkconfig –add command is executed, it creates a symbolic link file to start
and stop the service under corresponding rc directory.
When chkconfig –del command is executed, it removes the symbolic link file
from the corresponding rc directory.
The following example shows that xinetd is enabled for both run level 3 and 5.
So, xinetd will have two files under rc3.d directory, and two files under rc5.d
directory. The file that starts with K is used during shutdown (K stands for kill). The
file that starts with S is used during startup (S stands for start).
# chkconfig --list | grep xinetd
# cd /etc/rc.d/rc3.d
# ls | grep xinetd
K08xinetd
S14xinetd
# cd /etc/rc.d/rc5.d
# ls | grep xinetd
K08xinetd
S14xinetd
For example, if the nfsserver service doesn’t exist in the chkconfig control, no
nfsserver service startup files would be present under /etc/rc.d/rc*.d directories as
shown below.
After you add the nfsserver service, you’ll see the symbolic links under these
directories.
# cd /etc/rc.d/rc3.d
# ls -l | grep nfsserver
# cd /etc/rc.d/rc5.d
# ls -l | grep nfsserver
When you turn off the service either using –del option or –level option, the
corresponding symbolic link file under rcx.d directory will be deleted as shown
below.