systemctl - control the systemd system and service manager
systemctl [COMMAND] [UNIT...]
Options you will use
status UNIT- Show runtime status, the cgroup tree and the last log lines.
start / stop / restart UNIT- Start, stop or restart a unit now.
reload UNIT- Ask the unit to reload its config (needs ExecReload=).
enable / disable UNIT- Create or remove the symlink that starts it at boot. --now also starts/stops it.
mask / unmask UNIT- Link the unit to /dev/null so it cannot start at all, even as a dependency.
is-active / is-enabled / is-failed UNIT- One-word answer, script friendly.
cat UNIT- Print the unit file and every drop-in, with their paths.
show [-p PROP] [--value] UNIT- Dump the parsed properties systemd actually uses.
edit UNIT- Create a drop-in override. --full copies the whole unit to /etc instead.
revert UNIT- Throw away drop-ins and /etc copies, back to the vendor unit.
daemon-reload- Re-read unit files from disk. Needed after ANY manual edit.
daemon-reexec- Re-execute the systemd binary itself (after a systemd upgrade).
reset-failed [UNIT]- Clear the failed state and the start-rate-limit counter.
list-units [--type=] [--state=] [--failed]- Units currently loaded into memory.
list-unit-files- Every installed unit file and its enablement state.
list-timers [--all]- Timers with their NEXT and LAST trigger times.
list-dependencies [--reverse] UNIT- The dependency tree, or who depends on this unit.
set-property UNIT NAME=VALUE- Change a resource-control property at runtime (persists via /etc/systemd/system.control).
get-default / set-default / isolate TARGET- The boot target, and switching to one now.
kill [-s SIGNAL] UNIT- Send a signal to a unit's processes.
--no-pager- Do not pipe the output into a pager (less). Handy in scripts and when you want it in the scrollback.
--now- With enable/disable/mask: also start/stop the unit right away.
--failed- List only units in the failed state (list-units --failed).
--all, -a- Show all units, also inactive ones, or all properties.
-t, --type TYPE- Only units of this type: service, timer, socket, target, mount...
--state STATE- Only units in this state: running, failed, active, inactive, enabled...
-p, --property NAME- With show: only this property (repeat -p or comma-separate for several).
--value- With show -p: print just the value, no NAME= in front. Script friendly.
-q, --quiet- Print nothing; only the exit status says the answer (is-active, is-enabled).
--full, -l- Do not cut long lines. With edit: copy the whole unit to /etc instead of a drop-in.
--reverse- With list-dependencies: show the units that depend on this one.
-s, --signal SIGNAL- With kill: which signal to send (default SIGTERM).
--user- Talk to your own user service manager instead of the system one.
Examples
$ systemctl cat sshthe real file, plus drop-ins, plus their paths
$ systemctl show -p MainPID --value demojust the PID, for scripting
$ sudo systemctl edit demodrop-in in /etc/systemd/system/demo.service.d/override.conf
$ systemctl list-units --type=service --state=failedwhat is broken
Gotchas
- Precedence, highest first: /etc/systemd/system > /run/systemd/system > /usr/lib/systemd/system. Never edit the file under /usr/lib - a package upgrade overwrites it. Drop-ins under <unit>.d/ add to the vendor unit instead of replacing it.
Taught in
Try systemctl in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.