Replacing chkconfig Command on Modern Linux

0
16


chkconfig is a command-line utility used in Unix-like operating systems to manage which services start automatically when the system boots up.

chkconfig tool was widely used in older Linux distributions like CentOS 6 and earlier. chkconfig allowed administrators to easily enable or disable services across different runlevels.

Why Was chkconfig Important?

Before we dive into the modern replacement, let’s understand why chkconfig was useful:

  • Service Management: It provided a simple way to manage startup services without needing to manually create or delete symbolic links in the /etc/rc.d/ directories.
  • Runlevel Control: It allowed administrators to specify which services should run at different runlevels. Runlevels are different modes of operation for Unix-like systems, such as single-user mode, multi-user mode, etc.
  • Convenience: It streamlined service management with straightforward commands to list, add, or remove services from automatic startup.

Basic chkconfig Commands

This is our ongoing Linux command series where we are going to review how we can use the chkconfig command efficiently with its available parameters.

The chkconfig command tool allows us to configure services to start and stop automatically in the /etc/rc.d/init.d scripts through the command line.

Let’s see some common commands used with chkconfig:

1. List All Services

Using ‘--list‘ parameter will display all services and their current start-up status in each run-level configuration.

chkconfig --list

NetworkManager  0:off   1:off   2:on    3:on    4:on    5:on    6:off
abrt-ccpp       0:off   1:off   2:off   3:on    4:off   5:on    6:off
abrt-oops       0:off   1:off   2:off   3:on    4:off   5:on    6:off
...

2. Check the Status of Specific Service

The command below displays the startup configuration for a specific service called HTTP, which is turned off in all runlevels.

chkconfig --list | grep httpd

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

3. How Do I Start a Particular Service on Run Levels

The following `chkconfig` commands demonstrate how to configure HTTP services to start only on run levels 3 and 5 using the `--level` parameter.

The first command starts the `httpd` services on run levels 3 and 5, while the second command checks the status of `httpd` services running on those run levels.

chkconfig --level 35 httpd on
chkconfig --list | grep httpd

Sample Output:

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

4. How to Check Which Services are On/Off

The following command will display all the services which are On and Off in specific run level 5.

chkconfig --list | grep 5:on

Sample Output:

NetworkManager  0:off   1:off   2:on    3:on    4:on    5:on    6:off
abrt-ccpp       0:off   1:off   2:off   3:on    4:off   5:on    6:off
abrt-oops       0:off   1:off   2:off   3:on    4:off   5:on    6:off
abrtd           0:off   1:off   2:off   3:on    4:off   5:on    6:off
acpid           0:off   1:off   2:on    3:on    4:on    5:on    6:off
...
chkconfig --list | grep 5:off

Sample Output:

dnsmasq         0:off   1:off   2:off   3:off   4:off   5:off   6:off
dovecot         0:off   1:off   2:off   3:off   4:off   5:off   6:off
firstboot       0:off   1:off   2:off   3:off   4:off   5:off   6:off
kdump           0:off   1:off   2:off   3:off   4:off   5:off   6:off
mysqld          0:off   1:off   2:off   3:off   4:off   5:off   6:off
netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
nfs             0:off   1:off   2:off   3:off   4:off   5:off   6:off
...

5. How Do I Stop a Particular Service on Run Levels

The following command will turned Off a service called postfix for a just single run level. Similarly, we can turn Off a particular service in multiple run levels in one go as shown under.

chkconfig --level 3 postfix off
chkconfig --level 2345 postfix off

6. How to Enable or Disable a Service

To enable a service to start automatically at boot.

chkconfig servicename on

To disable a service from starting automatically at boot.

chkconfig servicename off

The Shift to systemctl Command

As Linux systems evolved, the init system (used by chkconfig) was replaced by systemd, which is a modern system and service manager for Linux operating systems.

It offers more features and better performance. With this change, chkconfig became deprecated, and systemctl took its place.

Why Use systemctl?

systemctl is the command-line tool used to control the systemd system and service manager. It offers a more powerful and flexible way to manage services.

Here are some key advantages:

  • Unified Interface: It provides a single command to manage both system services and runlevels (now called targets in systemd).
  • Enhanced Performance: systemd starts services in parallel, improving boot times.
  • More Features: It supports modern features like service dependencies, on-demand service start, and more.

Basic systemctl Commands

Let’s look at how to perform similar tasks with systemctl that you would have done with chkconfig:

How to List Active Services

This command lists all active services managed by systemd on the system by providing more information about the status and properties of each service.

systemctl list-units --type=service
List Linux Services
List Linux Services

How to Enable or Disable a Service

To enable a service to start automatically at boot.

systemctl enable servicename

To disable a service from starting automatically at boot.

systemctl disable servicename

How to Start, Stop, and Restart Service

To start a service immediately.

systemctl start servicename

To stop a service immediately.

systemctl stop servicename

To restart a service immediately.

systemctl restart servicename

How to Check Service Status

To check the status of a service.

systemctl status servicename
Conclusion

While chkconfig was a valuable tool for managing services in older Linux distributions, the transition to systemd and the systemctl command has brought numerous improvements in terms of functionality and performance.

Understanding how to use systemctl is essential for modern Linux administration. The commands may be different, but they offer more control and better integration with the system as a whole.

If you’re familiar with chkconfig, learning systemctl will help you manage services more efficiently in today’s Linux environments.



Source link