Managing units

Essential systemctl & journalctl commands for managing units

4 min read

The commands you’ll actually run after writing a unit. Most need sudo for system units; drop sudo and add --user for user units.

Lifecycle

sudo systemctl daemon-reload                 # ALWAYS after editing a unit file
sudo systemctl enable --now myapp.service    # start now + on boot
sudo systemctl disable --now myapp.service   # stop now + don't start on boot
sudo systemctl restart myapp.service
sudo systemctl reload myapp.service          # re-read config without a full restart (if supported)
sudo systemctl reload-or-restart myapp.service

Inspect

systemctl status myapp.service               # state, PID, recent log lines
systemctl is-active myapp.service            # active / inactive / failed
systemctl is-enabled myapp.service           # enabled / disabled
systemctl --failed                           # everything currently failed
systemctl list-units --type=service          # all loaded services
systemctl list-timers --all                  # next/last run of every timer
systemctl cat myapp.service                  # the effective unit (with drop-ins)
systemctl show myapp.service -p MainPID -p ActiveState

Logs (journalctl)

journalctl -u myapp.service -f               # follow live (like tail -f)
journalctl -u myapp.service -e               # jump to the end
journalctl -u myapp.service --since "1 hour ago"
journalctl -u myapp.service -p err           # errors and worse only
journalctl -u myapp.service -b               # this boot only
journalctl --disk-usage                      # how much the journal is using

Override safely (drop-ins)

Never hand-edit a package’s unit in /lib/systemd/system — it’ll be overwritten on upgrade. Use a drop-in:

sudo systemctl edit myapp.service

This opens an override at /etc/systemd/system/myapp.service.d/override.conf; put only the lines you change there, e.g.:

[Service]
Environment=LOG_LEVEL=debug
Restart=always

systemctl edit runs daemon-reload for you. To replace the whole unit instead, sudo systemctl edit --full myapp.service. Reset to the package default with sudo systemctl revert myapp.service.

Validate before you trust it

systemd-analyze verify /etc/systemd/system/myapp.service   # syntax & ordering check
systemd-analyze calendar 'Mon..Fri 18:00'                  # what an OnCalendar elapses to
systemctl reset-failed myapp.service                       # clear a failed/rate-limited state

Most-forgotten step: daemon-reload after every edit (or systemctl edit, which does it for you) — otherwise systemd runs the old file. Tip: systemctl cat shows the merged result of the unit plus all drop-ins, which is what’s actually running.

Open the full version (with copy buttons) ↗

← All recipes