Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Systemd and Logging (Read-Only)

systemctl status

Reference for systemctl status: how to read the Active, Loaded, Main PID and log lines, exit codes of is-active and is-failed, and use status in scripts. Read-only.

systemctl status prints a snapshot of one systemd unit (usually a service): whether it is loaded, enabled and running, its main process and control group, resource use, and the last few log lines from the journal. It is the first command to run when a service misbehaves.

This page is read-only: the example sandbox has no systemd, so the console output below is shown as sample text, and the live examples work with that text and with the exit-code conventions that scripts rely on.

Terminal
systemctl status nginx
systemctl status --no-pager -l ssh
systemctl is-active nginx

Try it

Bash Parsing status output (sample text)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Exit codes and a status helper (works without systemd)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
systemctl [--user] status [UNIT...|PID...] [--no-pager] [-l] [-n LINES]
Option Description
UNIT Unit name; .service is assumed if you omit the suffix.
PID Show the unit that owns that process.
no argument Show overall system state and a tree of running units.
--no-pager Print directly instead of opening less.
-l, --full Do not shorten long lines (default in recent versions).
-n N Number of journal lines to show (default 10).
--user Query the per-user service manager.

Reading the key lines:

Line Meaning
Loaded: Unit file path and whether it is enabled (starts at boot), disabled, static (no install section) or masked (blocked).
Active: active (running), active (exited) for one-shot jobs, activating, inactive (dead), or failed.
Main PID: The process systemd tracks; (code=exited, status=1/FAILURE) shows why it stopped.
CGroup: All processes of the unit, as a tree.
Log lines Recent journal messages for the unit.

Usage notes

  • Exit status: status returns 0 when the unit is running and 3 when it is not, so it works in scripts, but systemctl is-active and is-failed are cleaner (they print one word and have the same codes).
  • Truncated logs: only the newest lines show. Use journalctl -u UNIT for the full history, and -b for the current boot.
  • failed states: Result=exit-code, signal, timeout or start-limit-hit tells you the category. After fixing the cause, clear it with sudo systemctl reset-failed UNIT.
  • Does not need root to read, but some log lines may be hidden unless you are in the systemd-journal or adm group.
  • Pager: output goes through less; use --no-pager in scripts, or set SYSTEMD_PAGER=cat.
  • active (exited) is normal for services that run a command once and leave state behind, such as mounting or firewall rule loaders.
  • Containers often have no systemd; see service for older init systems.