Skip to content
Search

Chkconfig

lastmod 2018-08-17created 2015-01-155 edits

chkconfig determines which services run automatically at boot by creating/deleting the link files starting with S and the link files starting with K in each directory of /etc/rc.d/rcN.d.

Example

chkconfig --list
Shows what is registered with chkconfig.

Sample code

For reference, the code below is a service script for starting Tomcat automatically. It was written as /etc/init.d/tomcat8.

#!/bin/sh
#don't reomve chkconfig
#chkconfig: 2345 95 20

CATALINA_HOME=/usr/share/tomcat8; export CATALINA_HOME
JAVA_HOME=/usr/java/jdk1.7.0_51; export JAVA_HOME

start() {
    echo -n "starting Tomcat: "
    $CATALINA_HOME/bin/startup.sh
}

stop() {
    echo -n "stopping Tomcat: "
    $CATALINA_HOME/bin/shutdown.sh
}

case "$1" in
start)
    start
    ;;
stop)
    stop
    ;;
restart)
    stop
    start
    ;;
*)
    echo $"Usage: tomcat {start|stop|restart}"
    exit
esac

The important point here is that you must not remove the #chkconfig: 2345 95 20 part, because deleting it produces the following error message.

service a does not support chkconfig

See also

Favorite site