Kiet Nguyen logo
NotesNotesResumeResume
© 2026 Kiet Nguyen
← All categories

08

systemd Services

  • Service not responding — status first
  • Enable on boot vs start now
  • restart vs reload; drop-ins survive package upgrades
systemctl — lifecyclesystemctl — boot enablementsystemctl — inspect & editsystemctl — global / output

Must-know cold

  • systemctl status UNIT · start · stop · restart · reload
  • systemctl enable --now UNIT · is-active · is-enabled
  • systemctl cat UNIT · daemon-reload after unit edits
  • systemctl reset-failed UNIT after crash loop fixed
  • Never first-move: restart without reading status/logs

Active vs enabled

Definition: Two independent axes. ActiveState = now. UnitFileState = how/whether it is hooked for boot. Masked is a UnitFileState that also blocks start.

StateAxisMeaning
active (running)ActiveStateService process is up
active (exited)ActiveStateStill active (typical Type=oneshot + RemainAfterExit=) — no long-running PID
inactive (dead)ActiveStateNot started
failedActiveStateLast start/run failed (crash, non-zero, timeout, start-limit)
enabledUnitFileState[Install] symlinks in place — usually start at boot
disabledUnitFileStateNo [Install] links. Can still start via socket/timer/dbus/Wants=
staticUnitFileStateNo [Install] section — cannot enable; pulled in by deps
maskedUnitFileState/etc/systemd/system/UNIT → /dev/null; no start until unmask

Commands

systemctl — lifecycle

Definition: Start, stop, restart, reload, or query a systemd service unit.

Option / verbArgumentMeaningExample
statusUNITState, PID, recent logs snippetsystemctl status nginx
status -lUNITFull (untruncated) linessystemctl status -l nginx
startUNITStart nowsudo systemctl start nginx
stopUNITStop nowsudo systemctl stop nginx
restartUNITStop then start; starts it if it was downsudo systemctl restart nginx
reloadUNITReload app config (ExecReload=). Not the unit filesudo systemctl reload nginx
try-restartUNITRestart only if already runningsudo systemctl try-restart nginx
reload-or-restartUNITReload if ExecReload= exists, else restart; starts if downsudo systemctl reload-or-restart nginx
killUNITSignal the unit’s processes (default cgroup/all, not only MainPID)sudo systemctl kill nginx
kill -sSIG UNITSpecific signal. Main only: --kill-whom=mainsudo systemctl kill -s HUP nginx

Flag combos

ComboMeaningExample
systemctl status UNIT --no-pager -lPasteable full statusTickets / CI
systemctl restart UNIT && systemctl is-active UNITRestart + verify

systemctl — boot enablement

Definition: Control whether a unit starts at boot (enable/disable/mask).

Option / verbArgumentMeaningExample
enableUNITCreate [Install] symlinks (boot hook). Also daemon-reload. Needs an [Install] sectionsudo systemctl enable nginx
disableUNITRemove those symlinks (and manual aliases). Does not stop unless --nowsudo systemctl disable nginx
enable --nowUNITEnable + start nowsudo systemctl enable --now nginx
disable --nowUNITDisable + stop nowsudo systemctl disable --now nginx
is-enabledUNITPrints enabled / disabled / masked / static / indirect / … Exit 0 for enabled and staticsystemctl is-enabled nginx
is-activeUNITPrints ActiveState (active / inactive / failed / activating…). Exit 0 only if active (includes exited)systemctl is-active nginx
is-failedUNITExit 0 if that unit failed. No args: any failed unitsystemctl is-failed nginx
maskUNITPrevent all startssudo systemctl mask nginx
unmaskUNITUndo masksudo systemctl unmask nginx
reenableUNITDisable then enable (refresh links)sudo systemctl reenable nginx

Flag combos

ComboMeaningExample
enable --nowBoot + immediateNew service deploy
mask then fix then unmask + startStop restart stormsNoisy crash loop

systemctl — inspect & edit

Definition: Show unit files, properties, and create drop-in overrides.

Option / verbArgumentMeaningExample
catUNITConcatenate unit file + drop-ins from disk (stale if you skipped daemon-reload)systemctl cat nginx
showUNITLive properties (key=value)systemctl show nginx
show -pPROP UNITOne property (comma-list OK)systemctl show -p MainPID nginx
list-units—Units in memory. Default: active, jobs, or failed — not every installed filesystemctl list-units --type=service
list-unit-files—Installed files + enablement (enabled/disabled/static/…)systemctl list-unit-files nginx*
list-dependenciesUNITRequires= / Wants= tree (loaded units; targets expanded by default)systemctl list-dependencies nginx
editUNITDrop-in /etc/systemd/system/UNIT.d/override.conf + auto daemon-reloadsudo systemctl edit nginx
edit --fullUNITFull replacement under /etc (masks vendor file) + auto reloadsudo systemctl edit --full nginx
daemon-reload—Reload systemd’s unit files — not the daemon’s app configsudo systemctl daemon-reload
reset-failedUNITClear failed + start-limit + NRestarts. Does not start the unitsudo systemctl reset-failed nginx
daemon-reexec—Reexec systemd (rare)Maintenance

Flag combos

ComboMeaningExample
show -p MainPID,NRestarts,ActiveState UNITPID + restart countCrash loop detect
cat UNIT after editConfirm drop-in merged
daemon-reload && restart UNITAfter a manual unit/drop-in editsystemctl edit already reloads

Useful show properties

Definition: Key systemctl show fields (MainPID, NRestarts, ActiveState, paths, deps).

PropertyMeaning
MainPIDMain process ID
NRestartsRestart counter (crash loop clue)
ExecMainStatusExit status of main process
FragmentPathPath to unit file
DropInPathsDrop-in files
ActiveState / SubStateHigh-level / detailed state
UnitFileStateenabled/disabled/masked
MemoryCurrentcgroup memory if accounting on
Requires / Wants / AfterDependencies
systemctl show nginx -p MainPID -p NRestarts -p ActiveState -p FragmentPath --no-pager

systemctl — global / output

Definition: List units, filter types, user vs system bus, non-pager output.

OptionArgumentMeaningExample
--user—User session manager (not system)systemctl --user status app
--no-pager—No less; good for scriptssystemctl status u --no-pager
--no-legend—Hide headers/legendssystemctl list-units --no-legend
-q / --quiet—Suppress output; use exit codesystemctl is-active -q nginx
--failed—List failed unitssystemctl --failed
-t / --typeTYPEFilter type (service, timer)systemctl -t service
-a / --all—All units including inactivesystemctl list-units -a

Flag combos

ComboMeaningExample
systemctl --failed --no-pagerWhat’s broken nowMorning check
systemctl --user enable --now lab.serviceUser serviceLab without root

Common recipes

GoalCommand
Health snapshotsystemctl status UNIT -l --no-pager
Start + bootsudo systemctl enable --now UNIT
Restart & checksudo systemctl restart UNIT; systemctl is-active UNIT
See effective unitsystemctl cat UNIT
After a manual unit editsudo systemctl daemon-reload && sudo systemctl restart UNIT
Clear failedsudo systemctl reset-failed UNIT
All failedsystemctl --failed
Main PIDsystemctl show -p MainPID --value UNIT

Pitfalls

  • enable ≠ start (boot hook vs now). enable does nothing useful without [Install] (static).
  • disabled can still come up via socket, timer, D-Bus, or another unit’s Wants=/Requires=.
  • active is not always a running process — active (exited) oneshots still make is-active succeed.
  • Vendor units live under /usr/lib/systemd/system (often also /lib/…). Package upgrades overwrite those. Put overrides in /etc via systemctl edit.
  • systemctl edit already runs daemon-reload. You still restart (or reload) for most process settings. Manual vi of a unit file does need daemon-reload.
  • reload is the application config (ExecReload=). daemon-reload is systemd’s unit files. Do not mix them.
  • reload fails if there is no ExecReload= — use restart or reload-or-restart.
  • systemctl kill is not kill $(MainPID) — it signals the cgroup by default.
  • mask blocks every activation (manual and dependency). Remember unmask. Local units already in /etc often cannot be masked that way.
  • User services need systemctl --user and often loginctl enable-linger to start at boot without a login.

For more details, try man <command> in your terminal.

Previous07 Processes & SignalsNext09 Journal & Logs