Systemctl replaces Chkconfig and Service commands in CentOS 7

Updated on November 10, 2017

From our previous experience of CentOS/RedHat, we all knew that “chkconfig command is used for checking and updating runlevel information for system services. These legacy commands are still included in CentOS 7 for backwards compatibility, but that will be obsolete in future releases. In CentOS 7/Redhat 7  systemctl replaces chkconfig and service commands. Here is a small tutorial to help you understand and learn the systemctl command!

Systemctl replaces Chkconfig and Service commands

Restart system services on CentOS 7/Redhat 7

Since we all used CentOS/Redhat extensively, we shall start/restart a service typically as below:

[root@root ~]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service

But, you may take a note of that little message! telling, ‘Hey, things have changed and for future… start using systemctl command instead of legacy commands”.

Here’s how you can use systemctl commands for start/restart of the service as shown below:

Start the service

# systemctl start mysqld

Restart the service:

# systemctl restart mysqld
How to find the status of a service in CentOS 7/Redhat 7

The above command doesn’t provide any output on whether the service has been started or not. To find out the status use the below command:

# systemctl status mysqld
 mysqld.service - MySQL Server
 Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
 Active: active (running) since Thu 2017-11-09 09:32:57 CST; 1min 57s ago
 Docs: man:mysqld(8)
 http://dev.mysql.com/doc/refman/en/using-systemd.html
 Process: 1660 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
 Process: 1640 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 1662 (mysqld)
 CGroup: /system.slice/mysqld.service
 ââ1662 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mys...

Nov 09 09:32:56 s119957 systemd[1]: Starting MySQL Serv...
Nov 09 09:32:57 s119957 systemd[1]: Started MySQL Server.
Hint: Some lines were ellipsized, use -l to show in full.

Chkconfig in CentOS 7

If you want your services to auto-start at boot, you can’t use chkconfig (legacy command in old CentOS)! Yes, you heard it right. Now  systemctl replaceschkconfig command too…

chkconfig service On – CentOS 7/Redhat 7:

#systemctl enable <service_name>

for eg.,

#systemctl enable mysqld

chkconfig service Off – CentOS7/Redhat 7:

#systemctl disable <service_name>

for eg.,

#systemctl disable mysqld

chkconfig particular service list – CentOS 7/Redhat 7:

#systemctl is-enabled <service_name>

for eg.,

#systemctl is-enabled mysqld
enabled

chkconfig –list – CentOS 7/Redhat 7:

#systemctl list-unit-files --type=service

UNIT FILE                                     STATE
arp-ethers.service                           disabled
auditd.service                               enabled
autovt@.service                              enabled
blk-availability.service                     disabled
brandbot.service                             static
console-getty.service                        disabled
console-shell.service                        disabled
container-getty@.service                     static
cpupower.service                             disabled
...
...

Update yourself and enjoy working on CentOS 7 🙂

Was this article helpful?

Related Articles

Leave a Comment