Understanding chkconfig Runlevels: A Technical Guide for Linux Service Management


3 views

The chkconfig command in Linux uses runlevels (0-6) to define when services should start or stop during system initialization. Each number represents a specific system state:


0 - Halt
1 - Single-user mode
2 - Multi-user without NFS
3 - Full multi-user with networking
4 - Unused (user-definable)
5 - Graphical interface
6 - Reboot

When you execute:

chkconfig --levels 235 httpd on

This configures the Apache HTTP server to start automatically in runlevels 2, 3, and 5. The breakdown:

  • 2: Basic multi-user environment
  • 3: Standard networked server mode
  • 5: Graphical desktop environment

Typical service configurations:


# Database server (run in levels 3,5)
chkconfig --levels 35 mysqld on

# Network services (run in levels 3,5)
chkconfig --levels 35 network on

# GUI-related services (run only in level 5)
chkconfig --levels 5 gdm on

To check current runlevel settings:

chkconfig --list httpd

Output example:


httpd           0:off   1:off   2:on    3:on    4:off   5:on    6:off

To completely disable a service across all runlevels:

chkconfig httpd off

When modifying runlevels, remember:

  • Runlevel changes take effect after reboot
  • Use init or telinit to test runlevel changes
  • Critical services should typically run in levels 3 and 5

When working with chkconfig on Linux systems, the numeric levels represent specific system states during bootup and operation. These runlevels determine when services should automatically start or stop.

# Common runlevels breakdown:
# 0 - Halt (System shutdown)
# 1 - Single user mode
# 2 - Multiuser without NFS
# 3 - Full multiuser mode
# 4 - Unused/custom
# 5 - Graphical interface
# 6 - Reboot

When you execute chkconfig --levels 235 httpd on, you're instructing the system to:

  • Start Apache automatically during runlevels 2, 3, and 5
  • Not start Apache in other runlevels (including single-user mode)

Here's how to verify current settings:

chkconfig --list httpd
# Sample output:
# httpd           0:off   1:off   2:on    3:on    4:off   5:on    6:off

To modify multiple services simultaneously:

for service in httpd mysqld postfix; do
    chkconfig --level 235 $service on
done

For custom service management, create init scripts in /etc/init.d/:

#!/bin/bash
# chkconfig: 2345 90 10
# description: My custom service

case "$1" in
    start)
        /path/to/start_script
        ;;
    stop)
        /path/to/stop_script
        ;;
    *)
        echo "Usage: $0 {start|stop}"
        exit 1
esac

The comment line # chkconfig: 2345 90 10 specifies:

  • Runlevels (2345)
  • Start priority (90)
  • Stop priority (10)

If a service isn't starting at boot:

# Verify symlinks exist:
ls -l /etc/rc.d/rc[235].d/S*httpd*

# Check system default runlevel:
grep :initdefault: /etc/inittab

# Test service manually:
service httpd start

Remember that modern systems using systemd may require different approaches (systemctl enable instead of chkconfig).