Pcornel
Linux · systemd & Services

Services

Cheat sheet · https://pcornel.dk/topic.php?topic=2719

Back to the Topic

Answer

A systemd service unit (.service) runs and supervises a process: how to start it (ExecStart), as which user, how to restart it, and what it depends on.

Remember

Read the journal, not just status. Common causes: wrong path in ExecStart, missing permissions for User=, a port already in use, a config error (test with the program's own check, e.g. nginx -t). Restart=on-failure hides crashes — check the restart count.

First checks

  • systemctl show <svc> -p NRestarts — how often it restarted
  • systemctl status <unit> — state, main PID, recent log lines
  • systemctl list-units --failed — failed units
  • journalctl -u <unit> -b — the unit's log since boot
  • systemctl cat <unit> — unit file plus drop-ins
  • systemd-analyze verify <unit> — unit file errors

Commands

systemctl is-active <unit>
Returns concise unit active state.
systemctl start

Verify in this order

service started → ExecStart runs as User= → main process stays up → systemd restarts it per policy → logs to the journal

Where it usually breaks

First mismatch in persistent unit/config/generator → dependency/order graph → systemd state → process/cgroup → socket/resource dependency → journal → consumer check; preserve identity/native diagnostic/pre-state before mutation.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=2719

Confirmation

Confirm action

Continue?