Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Linux chkconfig Command: Managing System Services Across Runlevels

Tech May 10 2

Overview

The chkconfig command provides a way to query and modify system services across different runlevels. Developed by Red Hat under GPL, this tool manages the services that execute during various system boot stages, including persistent daemons. It is important to note that chkconfig does not immediately enable or disable a service—rather, it modifies symbolic links to control service behavior at the next boot or runlevel change.

Syntax

chkconfig [options]

Options

--add <service>     Adds the specified service to chkconfig management and updates system startup files
--del <service>     Removes the specified service from chkconfig management and deletes related entries
--level <levels>    Specifies which runlevels the service should be started or stopped in

Runlevel Reference

Red Hat-based distributions use the following runlevel designations:

Level Purpose
0 Halt/Shutdown
1 Single-user mode
2 Multi-user without NFS
3 Full multi-user mode (text interface)
4 Reserved for custom use
5 Full multi-user with X11 (graphical interface)
6 Reboot

The --level option accepts a combination of runlevel numbers. The tool operates independently of the current runlevel—it can query or modify service status for any runlevel configuration. When changing runlevels, init does not restart serviecs already running nor stop services already halted.

Service Script Requirements

Each service managed by chkconfig requires a script in /etc/rc.d/ (or /etc/init.d/) with a header containing at least two comment lines:

# chkconfig: 2345 20 80
# description: Manages the example service daemon \
# for handling background tasks

The first line specifies the default runlevels (where the service starts) and its start/stop priority. A hyphen indicates the service should not start by default. The description can span multiple lines using backslash continuation.

Usage Examples

chkconfig --add nginx          # Register nginx service with chkconfig
chkconfig --del nginx          # Remove nginx service from chkconfig

chkconfig --level 235 nginx on    # Enable nginx for runlevels 2, 3, and 5
chkconfig --list                  # Display all services and their runlevel states
chkconfig --list postfix          # Show postfix service configuration

chkconfig --level 35 postfix off  # Disable postfix at runlevels 3 and 5
chkconfig postfix on              # Enable postfix at all applicable levels (2,3,4,5)

chkconfig --level 2345 redis on   # Activate redis across runlevels 2, 3, 4, 5

Adding a New Service

To register a new service with chkconfig:

  1. Place the service init script in /etc/init.d/
  2. Ensure the script conatins the proper chkconfig header comment
  3. Execute chkconfig --add servicename to register it—this creates the appropriate K/S symlinks in /etc/rc.d/rcN.d/
  4. Configure default runlevel behavior with chkconfig --level 35 servicename on
Tags: Linux

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.