norboten · cheat sheet

Enabled, masked, wanted — and none of them the same thing — cheat sheet

boot-systemd
# what is this unit, really
systemctl cat UNIT                     # vendor file + every drop-in, with paths
systemctl show UNIT                    # every resolved property
systemctl show -p ExecStart --value UNIT
systemctl show -p Wants -p Requires -p After UNIT
systemd-delta                          # everything overridden or extended on this machine

# state, on both axes
systemctl is-active UNIT               # now
systemctl is-enabled UNIT              # next boot: enabled/disabled/masked/static
systemctl status UNIT                  # both, plus the last log lines and the Drop-In: block
systemctl list-unit-files --state=masked
systemctl list-units --failed

# changing state
systemctl start|stop|restart UNIT      # now
systemctl enable|disable UNIT          # next boot (a symlink from [Install])
systemctl enable --now UNIT            # both
systemctl mask|unmask UNIT             # veto / lift the veto (unmask does not enable)
systemctl reset-failed UNIT            # clear the failure and the start-rate counter

# editing
systemctl edit UNIT                    # create/edit a drop-in, then reload automatically
systemctl edit --full UNIT             # copy the vendor unit into /etc and edit that
mkdir -p /etc/systemd/system/UNIT.d && vi /etc/systemd/system/UNIT.d/deps.conf
systemctl daemon-reload                # after ANY unit file change

# dependencies (in [Unit])
Wants=other.service                    # pull it in; do not care if it fails
Requires=other.service                 # pull it in; fail with it
After=other.service                    # ordering only — pulls in NOTHING
# the usual correct pair: Wants= + After=

# targets
systemctl get-default
systemctl set-default multi-user.target        # next boot
systemctl isolate multi-user.target           # now
systemctl list-dependencies multi-user.target

# logs (as root, or as a member of adm / systemd-journal — otherwise journalctl shows nothing)
journalctl -u UNIT -b                  # this unit, this boot
journalctl -u UNIT -f                  # follow
journalctl -xb -p err                  # this boot's errors, explained
journalctl --since '10 min ago'
journalctl -b -1                       # the previous boot
systemd-analyze blame                  # what made the boot slow