Image from Systemd
Systemd Cheat Sheet
08 Nov 2020Table of Contents
Systemd is an init system in Linux used for system intialization and service management. It is fairly useful to manage and monitor services. In this cheatsheet you will find a collection of common commands used with the command line tools systemctl and journalctl.
Managing Systemd
-
systemctl list-unitslist units and show if they are loaded and/or active-
--type=serviceonly show services (for other typessystemctl --type=help) -
--state=runningonly show running units (for other statessystemctl --state=help)
-
-
systemctl list-unit-fileslist unit files and what status they have (enabled/disabled/static/…) -
systemctl list-dependencieslist dependency tree -
systemctl list-dependencies [SERVICE]list dependencies of a unit
Managing Services
-
systemctl status [SERVICE]check status of service -
systemctl show [SERVICE]show service information -
systemctl start [SERVICE]start service -
systemctl stop [SERVICE]stop running service -
systemctl restart [SERVICE]restart service -
systemctl reload [SERVICE]reload service without stopping it -
systemctl enable [SERVICE]enable service to start at boot -
systemctl disable [SERVICE]disable service
Viewing Logs
-
journalctlView all logs -
journalctl -u [SERVICE]see logs of a single service -
journalctl -u [SERVICE] -u [SERVICE 2]see logs of more services -
journalctl -u [SERVICE] -ffollow the logs of a single service
Filter by time with:
-
journalctl --since "1 hour ago"entries logged in the last hour -
journalctl --since "2 days ago"entries logged in the last two days -
journalctl --since "2 days ago" --until "1 day ago"entries between two days ago and one day ago -
journalctl --since "2020-01-01 00:00:00" --until "2020-01-05 12:30:00"entries between two dates
Output arguments:
-
-o short-isoshow dates in ISO 8601 time format -
-o short-iso-preciseshow dates in ISO 8601 time format including full microsecond precision -
-o catshow only entries without timestamps -
-o jsonshow each entry formatted as JSON line -
-o json-prettydisplay as pretty formatted JSON
Further arguments:
-
-bshow entries since last boot -
-rshow entries in reverse chronological order -
-n 50show last 50 entries -
--utcshow timestamps in UTC time -
--no-hostnamedon’t show hostname field
References
- systemd.io
- man page for journalctl
- man page for systemctl
- Understanding Systemd Units and Unit Files
- How To Use Systemctl to Manage Systemd Services and Units
- How To Use Journalctl to View and Manipulate Systemd Logs
- systemd for Administrators, Part 1, Part 2, Part 3 by Lennart Poettering, the creator of systemd