Run and troubleshoot Linux services with systemd

8 steps · about 3 h 45 min · Intermediate

  1. Get the systemd mental model (guide, ArchWiki, 30 min)

    See units, targets and dependencies as one picture before running individual commands.

  2. Control services with systemctl (reference, freedesktop.org, 25 min)

    Practise start, stop, enable, status and is-failed on a real service and learn what each state means.

  3. Read the shape of a unit file (reference, freedesktop.org, 30 min)

    Learn the [Unit] and [Install] sections, ordering versus requirement, and where override files go.

  4. Write your own service unit (reference, freedesktop.org, 35 min)

    Choose the right Type=, ExecStart= and Restart= values to keep a small program running after crashes.

  5. Filter logs with journalctl (reference, freedesktop.org, 25 min)

    Narrow logs by unit, boot, priority and time so a failing service explains itself.

  6. Keep the journal persistent and bounded (guide, ArchWiki, 20 min)

    Make logs survive reboots and cap their disk use so troubleshooting data is there when you need it.

  7. Schedule jobs with timers (guide, ArchWiki, 25 min)

    Replace a cron entry with a timer and service pair whose runs and failures appear in the journal.

  8. Sandbox the service (reference, freedesktop.org, 35 min)

    Finish by adding User=, ProtectSystem= and PrivateTmp= so a compromised service can reach less of the host.