
Systemd Cheatsheet
08 Nov 2020Systemd 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-units
list units and show if they are loaded and/or activesystemctl list-unit-files
list unit files and what status they have (enabled/disabled/static/…)systemctl list-dependencies
list dependency treesystemctl list-dependencies [SERVICE]
list dependencies of a unit
Managing Services
systemctl status [SERVICE]
check status of servicesystemctl show [SERVICE]
show service informationsystemctl start [SERVICE]
start servicesystemctl stop [SERVICE]
stop running servicesystemctl restart [SERVICE]
restart servicesystemctl reload [SERVICE]
reload service without stopping itsystemctl enable [SERVICE]
enable service to start at bootsystemctl disable [SERVICE]
disable service
Viewing Logs
journalctl
View all logsjournalctl -u [SERVICE]
see logs of a single servicejournalctl -u [SERVICE] -u [SERVICE 2]
see logs of more servicesjournalctl -u [SERVICE] -f
follow the logs of a single service
Filter by time with:
journalctl --since "1 hour ago"
entries logged in the last hourjournalctl --since "2 days ago"
entries logged in the last two daysjournalctl --since "2 days ago" --until "1 day ago"
entries between two days ago and one day agojournalctl --since "2020-01-01 00:00:00" --until "2020-01-05 12:30:00"
entries between two dates
Output arguments:
-o short-iso
show dates in ISO 8601 time format-o short-iso-precise
show dates in ISO 8601 time format including full microsecond precision-o cat
show only entries without timestamps-o json
show each entry formatted as JSON line-o json-pretty
display as pretty formatted JSON
Further arguments:
-b
show entries since last boot-r
show entries in reverse chronological order-n 50
show last 50 entries--utc
show timestamps in UTC time--no-hostname
don’t show hostname field
References
- https://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