systemd Services and logs
Light · Postcard
102 × 152 mm · PDF
Dark · Postcard
102 × 152 mm · PDF
Ink saver · Postcard
102 × 152 mm · PDF
Light · A4 landscape
297 × 210 mm · PDF
Dark · A4 landscape
297 × 210 mm · PDF
Ink saver · A4 landscape
297 × 210 mm · PDF
Light · A3 landscape
420 × 297 mm · PDF
Dark · A3 landscape
420 × 297 mm · PDF
Ink saver · A3 landscape
420 × 297 mm · PDF
Start here
systemctl status <unit>
sudo systemctl start <unit>
sudo systemctl restart <unit>
sudo systemctl enable --now <unit>
systemctl --failed
journalctl -u <unit> -f
journalctl -b -p err
sudo systemctl daemon-reload
Concepts
- Unit file /etc/systemd/system
- Loaded known to systemd
- Active running
- Boot target starts at boot
Control services
systemctl start <unit>
systemctl stop <unit>
systemctl restart <unit>
systemctl reload <unit>
systemctl reload-or-restart <unit>
systemctl try-restart <unit>
systemctl kill -s <signal> <unit>
systemctl reset-failed <unit>
systemctl isolate <target>
systemctl --user <command>
Inspect
systemctl status <unit>
systemctl is-active <unit>
systemctl is-enabled <unit>
systemctl list-units --type=service
systemctl --failed
systemctl list-unit-files
systemctl cat <unit>
systemctl show -p <property> <unit>
systemctl list-dependencies <unit>
systemctl status --full -n 50 <unit>
Boot and unit files
systemctl enable <unit>
systemctl disable <unit>
systemctl enable --now <unit>
systemctl disable --now <unit>
systemctl mask <unit>
systemctl unmask <unit>
systemctl daemon-reload
systemctl edit <unit>
systemctl edit --full <unit>
systemctl revert <unit>
systemctl get-default
systemctl set-default <target>
systemctl reboot
systemctl poweroff
Logs (journalctl)
journalctl -u <unit>
journalctl -u <unit> -f
journalctl -n 100
journalctl -bjournalctl -b -1
journalctl -p err
journalctl --since "<date>" --until
"<date>"
journalctl -g <regex>
journalctl -ejournalctl -rjournalctl -o json-pretty
journalctl -kjournalctl --list-boots
journalctl --disk-usage
journalctl --vacuum-time=<time>
journalctl --no-pager
Unit file basics
# /etc/systemd/system/myapp.service[Unit]Description=My appAfter=network-online.targetWants=network-online.target[Service]ExecStart=/usr/local/bin/myapp --serveRestart=on-failureUser=myapp[Install]WantedBy=multi-user.target
| Directive | Meaning |
|---|---|
ExecStart= |
Command to run (absolute path) |
Restart= |
on-failure, always, no |
After= / Before= |
Ordering only |
Wants= / Requires= |
Pull in other units (weak / hard) |
WantedBy= |
Target that enables it |
Environment= |
Set VAR=value |
WorkingDirectory= |
Start directory |
Type= |
simple, exec, forking, oneshot, notify |
# systemctl edit myapp creates:# /etc/systemd/system/myapp.service.d/override.conf[Service]Environment=LOG_LEVEL=debug# clear a list setting before replacing itExecStart=ExecStart=/usr/local/bin/myapp --debug
systemd-analyze verify <file>
systemd-analyze security <unit>
Timers and one-offs
systemctl list-timers
systemctl list-timers --all
systemd-analyze calendar "<expr>"
systemd-run --user --on-active=<time>
<cmd>
systemd-run --unit=<name> <cmd>
| Expression | Fires |
|---|---|
daily |
Every midnight |
Mon *-*-* 09:00 |
Mondays 09:00 |
*-*-* *:00/15 |
Every 15 min |
weekly |
Monday 00:00 |
Boot analysis
systemd-analyzesystemd-analyze blame
systemd-analyze critical-chain
systemctl --state=failed
Recipes
sudoedit /etc/systemd/system/myapp.servicesystemd-analyze verify /etc/systemd/system/myapp.servicesudo systemctl daemon-reloadsudo systemctl enable --now myappsystemctl status myapp
# backup.service: [Service] Type=oneshot, ExecStart=/usr/local/bin/backup# backup.timer:[Timer]OnCalendar=*-*-* 02:30Persistent=true[Install]WantedBy=timers.target# then:sudo systemctl enable --now backup.timer
systemctl --failedsystemctl status <unit>journalctl -u <unit> -b -ejournalctl -u <unit> --since "10 min ago" -p warning
journalctl --disk-usagesudo journalctl --vacuum-time=2weeks



