How to ask systemd why a service was stopped
I would like to know why a given service was stopped. I can think of several reasons:
- The service crashed
- The service exited by itself
- The service was explicitly stopped through
systemctl stop
- The service was explicitly killed through
systemctl kill
- The service was
PartOf
another service that was stopped - The service was in conflict with another service that was started.
I am sure there are others I am forgetting.
Is there a way to ask systemd what caused a service to stop?
I would use:
To check the service status:
# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: man:httpd.service(8)
Feb 25 06:56:00 docker systemd[1]: httpd.service: Main process exited, code=exited, status=1/FAILURE
Feb 25 06:56:00 docker systemd[1]: httpd.service: Failed with result 'exit-code'.
Feb 25 06:56:00 docker systemd[1]: Failed to start The Apache HTTP Server.
Feb 25 06:56:32 docker systemd[1]: Starting The Apache HTTP Server...
Feb 25 06:56:32 docker httpd[18908]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::5054:ff:fef5:a1f5%enp1s0. Set the 'ServerName' directive globally to suppress this message
Feb 25 06:56:33 docker httpd[18908]: Server configured, listening on: port 80
Feb 25 06:56:33 docker systemd[1]: Started The Apache HTTP Server.
Feb 25 07:02:15 docker systemd[1]: Stopping The Apache HTTP Server...
Feb 25 07:02:16 docker systemd[1]: httpd.service: Succeeded.
Feb 25 07:02:16 docker systemd[1]: Stopped The Apache HTTP Server.
To check the log of the service(journalctl --unit=service_name):
# journalctl --unit=httpd
Feb 25 06:56:00 docker systemd[1]: httpd.service: Main process exited, code=exited, status=1/FAILURE
Feb 25 06:56:00 docker systemd[1]: httpd.service: Failed with result 'exit-code'.
Feb 25 06:56:00 docker systemd[1]: Failed to start The Apache HTTP Server.
Feb 25 06:56:32 docker systemd[1]: Starting The Apache HTTP Server...
Feb 25 06:56:32 docker httpd[18908]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::5054:ff:fef5:a1f5%enp1s0. Set the 'ServerName' directive globally to suppress this message
Feb 25 06:56:33 docker httpd[18908]: Server configured, listening on: port 80
Feb 25 06:56:33 docker systemd[1]: Started The Apache HTTP Server.
Feb 25 07:02:15 docker systemd[1]: Stopping The Apache HTTP Server...
Feb 25 07:02:16 docker systemd[1]: httpd.service: Succeeded.
Feb 25 07:02:16 docker systemd[1]: Stopped The Apache HTTP Server.