How to choose between systemctl status and show: Programmatically determining service status

Linux・CLI・DevOpsカテゴリを表すパンダのイラスト Linux / CLI / DevOps

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-oriented systemctl and the machine-oriented status can 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.

Official Information / Primary Sources

Document information

Article title
How to choose between systemctl status and show: Programmatically determining service status
Published
Updated
Source
https://papanda925.com/?p=16004&lang=en

License: Text and original figures for which this site holds the relevant rights are available under CC BY 4.0 , unless otherwise noted. This article may include content created or edited with generative AI. If code has a separate license notice or a linked GitHub repository license, that license takes precedence for the code. Quotations, third-party materials, images, and trademarks are excluded from this license. Usage policy

Copied title and URL