Using systemctl in centos7 to list services that failed to start

Time:2021-7-1

This tutorial describes how to use the systemctl tool to list the services managed by SYSTEMd that failed to start
List the services that failed to start
[[email protected] ~]# systemctl list-units –state failed
UNIT LOAD ACTIVE SUB DESCRIPTION
● httpd.service loaded failed failed The Apache HTTP Server

LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.

1 loaded units listed. Pass –all to see loaded but inactive units, too.
To show all installed unit files use ‘systemctl list-unit-files’.
Systemctl is used in centos7 to list services that failed to start. Systemctl is used in centos7 to list services that failed to start
It can be found that one service failed to start.

Is failed option
You can use the is failed option to check whether the specified service failed to start. If the startup fails, the result is failed. If there is no problem starting, the result is active.

[[email protected] ~]# systemctl is-failed httpd
failed
[[email protected] ~]# systemctl is-failed vsftpd
active
Systemctl is used in centos7 to list services that failed to start. Systemctl is used in centos7 to list services that failed to start

Check the status of the service
You can use the status option to check the cause of service startup failure. The following status information tells us that there is a syntax error in line 354 of httpd.conf configuration file.

May 26 09:22:05 localhost httpd[2958]: httpd: Syntax error on line 354 of /etc/httpd/conf/httpd.conf: /…osed.
[[email protected] ~]# systemctl status httpd
● httpd.service – The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Tue 2020-05-26 09:22:05 CST; 18min ago

 Docs: man:httpd(8)
       man:apachectl(8)

Main PID: 2958 (code=exited, status=1/FAILURE)

May 26 09:22:05 localhost systemd[1]: Starting The Apache HTTP Server…
May 26 09:22:05 localhost httpd[2958]: httpd: Syntax error on line 354 of /etc/httpd/conf/httpd.conf: /…osed.
May 26 09:22:05 localhost systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
May 26 09:22:05 localhost kill[2959]: kill: cannot find process “”
May 26 09:22:05 localhost systemd[1]: httpd.service: control process exited, code=exited status=1
May 26 09:22:05 localhost systemd[1]: Failed to start The Apache HTTP Server.
May 26 09:22:05 localhost systemd[1]: Unit httpd.service entered failed state.
May 26 09:22:05 localhost systemd[1]: httpd.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
Systemctl is used in centos7 to list services that failed to start. Systemctl is used in centos7 to list services that failed to start

Using journalctl to view the service startup log
If the reason for service startup failure is not found by using systemctl status [unit], you can use journalctl to view more startup logs.

The following operation is to filter out all the lines with error to find the service that failed to start.

[[email protected] ~]# journalctl |grep ‘error’
May 26 09:22:05 localhost httpd[2958]: httpd: Syntax error on line 354 of /etc/httpd/conf/httpd.conf: /etc/httpd/conf/httpd.conf:354: was not closed.
Systemctl is used in centos7 to list services that failed to start. Systemctl is used in centos7 to list services that failed to start
You can also use journalctl – u [unit] to view only the startup log of a service

[[email protected] ~]# journalctl -u httpd.service
— Logs begin at Sun 2020-05-24 06:52:52 CST, end at Tue 2020-05-26 09:48:03 CST. —
May 26 09:22:05 localhost systemd[1]: Starting The Apache HTTP Server…
May 26 09:22:05 localhost httpd[2958]: httpd: Syntax error on line 354 of /etc/httpd/conf/httpd.conf: /etc/httpd/conf/httpd.conf:354: was not closed.
May 26 09:22:05 localhost systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
May 26 09:22:05 localhost kill[2959]: kill: cannot find process “”
May 26 09:22:05 localhost systemd[1]: httpd.service: control process exited, code=exited status=1
May 26 09:22:05 localhost systemd[1]: Failed to start The Apache HTTP Server.
May 26 09:22:05 localhost systemd[1]: Unit httpd.service entered failed state.
May 26 09:22:05 localhost systemd[1]: httpd.service failed.

Filter out the wrong information.

[[email protected] ~]# journalctl -u httpd.service |grep ‘error’
May 26 09:22:05 localhost httpd[2958]: httpd: Syntax error on line 354 of /etc/httpd/conf/httpd.conf: /etc/httpd/conf/httpd.conf:354: was not closed.
Systemctl is used in centos7 to list services that failed to start. Systemctl is used in centos7 to list services that failed to start
In line 354 of the / etc / httpd / conf / httpd.conf configuration file, the directory tag is not closed. If the reason is returned, please modify it immediately.

summary
We learned how to use the systemctl command to display services / units that failed to run on Linux. For more information, see the systemctl manual.