chkconfig - Linux


Overview

chkconfig is a command-line utility in Linux used to manage system services in conjunction with the SysV init and systemd daemon scripts. Its primary function is to update and query runlevel information for system services. It provides a straightforward method to enable or disable services automatically at startup, making it highly effective for system administrators managing service behaviors across reboots.

Syntax

The basic syntax for using chkconfig is:

chkconfig [options] [service-name] [state]
  • service-name: The name of the system service you want to manage.
  • state: This can be either on, off, or a specific numeric runlevel state.

There are multiple ways to use chkconfig:

  • To list all services managed by chkconfig:
    chkconfig --list
    
  • To set a service to start automatically in certain runlevels:
    chkconfig --level <levels> <service-name> <on|off>
    

Options/Flags

  • --list, -l: Lists the current startup information for all services or a specific service if specified.
  • --add <service-name>: Adds the specified service to the startup configuration, allowing chkconfig management.
  • --del <service-name>, --delete <service-name>: Removes the specified service from the startup configuration.
  • --level <levels> <service-name> <on|off>: Specifies which runlevels a service should be started or stopped in. <levels> is a combination of numbers from 0-7 based on the runlevel definition.
  • --system: Use system mode, allowing it to manage native systemd services in addition to legacy SysV services.

Examples

  • List all services and their runlevel settings:
    chkconfig --list
    
  • Enable sshd to start at runlevels 3, 4, and 5:
    chkconfig --level 345 sshd on
    
  • Disable httpd service from starting automatically:
    chkconfig httpd off
    
  • Add a new service to manage:
    chkconfig --add new-service
    
  • Remove a service from chkconfig management:
    chkconfig --del old-service
    

Common Issues

  • Service not found error: Ensure the service name is correct and the service script exists within /etc/init.d/ or /usr/lib/systemd/.
  • Permission issues: Running chkconfig may require root privileges, especially when altering service settings.

Solution: Always run chkconfig with sudo if you face permission-denied errors.

Integration

chkconfig can be integrated with system boot scripts or used in deployment scripts to ensure necessary services start correctly upon boot. For example, after installing Apache on a new server, a script might automatically enable it:

sudo chkconfig --add httpd
sudo chkconfig --level 235 httpd on

Combined with nc, this setup can verify that the service is listening on its default port after booting.

  • systemctl: The primary command to control systemd services, commonly used in newer Linux distributions.
  • service: A simpler utility for managing running services but does not configure startup settings.

For more information, refer to the official man pages by running man chkconfig or visiting online Linux documentation resources.