About this article
This article was created using an automated generation flow utilizing generative AI. We reviewed the specifications of systemd and organized it so that the human-orientedsystemctland the machine-orientedstatuscan be compared for the same service.showVerification status: 📘 Official systemd specification checked, actual Ubuntu device not checked.
is convenient for humans to read, but if you want to determine the status using a script, the property output of
systemctl status might be easier to handle.systemctl showFirst, look at the same service.
The first is the human-oriented display including log fragments, and the second is the display narrowed down to
systemctl status nginx --no-pager systemctl show nginx -p ActiveState -p SubState -p MainPID
format values.key=valueCheck this part
Notice how the value you want to check is independent, as in . PIDs vary depending on the environment.
ActiveState=active SubState=running MainPID=1234
Try changing one place
Please change
MainPID to ExecMainStatus.
systemctl show nginx -p ActiveState -p ExecMainStatus
You can see that "whether it is running" and "the exit status of the most recent main process" are different perspectives.
If you use it for work
In monitoring, pre-backup checks, and post-deployment checks, explicitly retrieving necessary properties makes it easier to leave your processing intent clear compared to grepping the output text of status. However, service-specific health cannot be guaranteed by the systemd state alone; combine it with application-layer checks such as HTTP responses for web applications.
