Pcornel
Linux · systemd & Services

Unit Files

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

Back to the Topic

Answer

A unit file is an INI-style file describing a unit: [Unit] (description, dependencies), a type section such as [Service] (ExecStart, User, Restart) and [Install] (which target enables it).

Remember

Do not edit package files in /usr/lib/systemd/system — create a drop-in with systemctl edit <unit> or a full copy in /etc/systemd/system. Run systemctl daemon-reload after changing files. To clear a list setting such as ExecStart in a drop-in, set it empty first.

First checks

  • 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 enable
systemctl status
systemctl edit <unit>
systemctl edit --full <unit>
systemctl edit

Verify in this order

unit file and drop-ins read → merged → daemon-reload loads them → next start uses them

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=2722

Confirmation

Confirm action

Continue?