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
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.
“systemd starts services in parallel, improving boot times.”
That may be an advantage for Windows-based systems. Considering that Linux systems stay up for months, if not years, at a time, a few seconds (or even minutes) save on boot-up are totally irrelevant.
Systemd is an init that wants to be a distro and violates the basic principle of *nix – Do one job but do it well. Systemd is an octopus that wants to control each and every app.
Guys, I have not tested this command on my Ubuntu 20.04.2 so excuse me. I see this article is a bit old.
I have been using systemctl now as SystemD replaced SystemV. Is still valid? Well, the easiest way to find out is to go to the terminal but my CPU fan is not cleaned lately and my laptop overheated so it’s off now.
And BTW I wanted to “buy you a coffee” but Stripe ( do not have a PayPal account ) refuses payments from the EU to India.
I did not try on your site but on another one more than 5 times.
@Jimmy,
Please check this article – How to Manage ‘Systemd’ Services and Units Using ‘Systemctl’ in Linux
Is the run level 0 and 6 require for service?
Ex: chkconfig –level 02356 servicename on
May I know the reason for 0 and 6 levels to assign the particular service.
Thanks & Regards,
Nagarajan J
@Nagarajan,
No only run level 3 and 5 required for service to auto start and run…
wrong path has been gives, please correct it to /etc/rc.d/init.d/
Sir, I need to know the way to find out the service name and daemon name for a particular package. Example for samba package alone, it has to show the service name smb and daemon name smbd.
Thanks in advance
very informative article and simple to understand
Nice post, thanks.
Nice post…Its so easy to understand!
Thank you very much for the hardwork :)
Current Introduction typo to be corrected for directory path of RC scripts; /etc/rd.d/init.d
The Chkconfig command tool allows to configure services start and stop automatically in the /etc/rd.d/init.d scripts through command line. Let’s see some examples.
Corrected directory path of RC scripts; /etc/rc.d/init.d
#2 could be better written as…
$ chkconfig httpd –list
6 less keystrokes is a win in my book :)
Makes sense!
Thanks for sharing