8.2. Operating Services
The verbs in this section - start, stop, reload, restart, enable, mask -
apply to any service. They are demonstrated on one small local service,
handbook-heartbeat.service, which Section 8.3 builds step by step;
readers following the examples hands-on should build it there first, or
substitute a service of their own. The heartbeat's unit file lives in
/usr/local/lib/systemd/system and its program in /opt/handbook-heartbeat;
Section 8.3.1 shows every file's contents.
One convention keeps the sequence honest: journal records for other users' processes and for the system as a whole are root-readable only at this point, so the journal reads in this section run as root. Section 8.4.3 grants john's account the access and explains the mechanism.
8.2.1. Starting, Stopping, Reloading, and Restarting
The four state verbs, and when each fits:
| Operation | Effect |
|---|---|
start |
Activates the unit now; a transient change that does not survive reboot |
stop |
Deactivates the unit and terminates its processes |
restart |
Stop followed by start; the process identity changes |
reload |
Runs the unit's ExecReload= only; the process keeps running |
As root on client1, start the heartbeat:
# systemctl start handbook-heartbeat.service
The command returns when the job is complete and prints nothing. The machine-checkable form of "is it up":
$ systemctl is-active handbook-heartbeat.service
active
is-active prints one word and exits 0 when the unit is active; the exit
status matters in scripts. The full picture:
$ systemctl status handbook-heartbeat.service --no-pager
● handbook-heartbeat.service - Handbook heartbeat service
Loaded: loaded (/usr/local/lib/systemd/system/handbook-heartbeat.service; disabled; preset: enabled)
Active: active (running) since Thu 2026-11-19 11:27:06 UTC; 4s ago
Invocation: c7d3eb1037b841d486e245f768b09dc3
Docs: file:/opt/handbook-heartbeat/heartbeat.py
Main PID: 91404 (python3)
Status: "heartbeat running"
Tasks: 1 (limit: 806)
Memory: 5.3M (peak: 7M)
CPU: 37ms
CGroup: /system.slice/handbook-heartbeat.service
└─91404 python3 /opt/handbook-heartbeat/heartbeat.py
Read the header in order: the unit file is loaded, its enablement state is
disabled (Section 8.2.2 changes that); the unit is active; the
Invocation line identifies this particular start - the ID changes on
every restart and appears in the journal; Main PID is the process
systemd supervises; and Status: shows a text the process itself
published through the notify protocol (Section 8.3.1). status exits 0 for
an active unit and non-zero for a failed one. No log lines follow the
header because john cannot read the system journal yet - the access rule
this section's opening stated; Section 8.4.3 grants it.
Reloading runs only the unit's ExecReload= command - here a SIGHUP to
the main process:
# systemctl reload handbook-heartbeat.service
Silent again; the journal is where a reload becomes visible. Read the reload's own records by matching message text rather than by reading a fixed tail window - the heartbeat adds a journal line every five seconds, which would push the reload records out of a small tail window within moments:
# journalctl -u handbook-heartbeat.service -g "reloaded" -n 2 --no-pager
Nov 19 11:27:13 client1 systemd[1]: Reloaded handbook-heartbeat.service - Handbook heartbeat service.
Nov 19 11:27:13 client1 handbook-heartbeat[91404]: reloaded interval=5s
-g selects records whose message matches a pattern - a lowercase
pattern matches case-insensitively, which is why the manager's Reloaded
line is caught as well - and -n 2 keeps the two newest matches, newest
first (-n implies reverse order when combined with -g; Section 8.4.1
tabulates both options). The second line is the application acknowledging
the signal; Section 8.3.2 makes the reload actually re-read its
configuration. Note the PID the acknowledgement carries: it is the same
one the Main PID property reports below, because a reload never changes
the process. A restart does - capture the identity before and after one:
$ systemctl show -p MainPID --value handbook-heartbeat.service
91404
# systemctl restart handbook-heartbeat.service
$ systemctl show -p MainPID --value handbook-heartbeat.service
91523
Same unit, new process. Stopping is the mirror of starting:
# systemctl stop handbook-heartbeat.service
$ systemctl is-active handbook-heartbeat.service
inactive
is-active prints inactive and exits 3; the exit status distinguishes
"not running" from "running" without parsing words.
8.2.2. Enabling, Disabling, Masking, and Presets
start changes now; enable changes next boot. Enabling a unit creates a
symlink in a .wants/ directory so its target pulls the unit in, and
--now applies the same decision to the running system:
# systemctl enable --now handbook-heartbeat.service
Created symlink '/etc/systemd/system/multi-user.target.wants/handbook-heartbeat.service' → '/usr/local/lib/systemd/system/handbook-heartbeat.service'.
The symlink is the entire mechanism - WantedBy=multi-user.target in the
unit's [Install] section names the directory. Query the decision:
$ systemctl is-enabled handbook-heartbeat.service
enabled
is-enabled exits 0 for enabled units. Disabling removes the symlink and
leaves the running state alone unless --now is added:
# systemctl disable handbook-heartbeat.service
Removed '/etc/systemd/system/multi-user.target.wants/handbook-heartbeat.service'.
$ systemctl is-enabled handbook-heartbeat.service
disabled
is-enabled exits 1 for a disabled unit - the word on screen and the exit
status carry the same fact. Disabling does not stop anything, and enabling
does not start anything, unless --now says so; keeping "now" and "next
boot" as separate decisions is exactly what makes rollbacks safe.
Masking goes further: it links the unit name to /dev/null so nothing -
no start request, no dependency, no activation - can bring it up:
# systemctl mask handbook-heartbeat.service
Created symlink '/etc/systemd/system/handbook-heartbeat.service' → '/dev/null'.
$ systemctl is-enabled handbook-heartbeat.service
masked
Starting it now fails with a precise error:
# systemctl start handbook-heartbeat.service
Failed to start handbook-heartbeat.service: Unit handbook-heartbeat.service is masked.
The typical use is a vendor unit that some other unit keeps pulling in but
that must never run on this machine - masking is stronger than disable
because even a Wants= elsewhere cannot resurrect a masked unit. Undo it
with unmask, which removes the /dev/null symlink and restores whatever
enablement state existed before:
# systemctl unmask handbook-heartbeat.service
Removed '/etc/systemd/system/handbook-heartbeat.service'.
$ systemctl is-enabled handbook-heartbeat.service
disabled
Presets are the distribution's enablement policy. Debian packages ship
preset files under /usr/lib/systemd/system-preset/ that say which units a
fresh install should have enabled; systemctl preset unit resets a unit to
exactly that policy, undoing local changes in either direction:
# systemctl preset handbook-heartbeat.service
Created symlink '/etc/systemd/system/multi-user.target.wants/handbook-heartbeat.service' → '/usr/local/lib/systemd/system/handbook-heartbeat.service'.
$ systemctl is-enabled handbook-heartbeat.service
enabled
The heartbeat unit matches no preset rule, and systemd's documented
default for unmatched units is to enable them - which is why preset
recreated the symlink even though this unit came from local software rather
than a package; the preset: enabled note in its status header said the
same thing. Leave the demonstration fleet consistent by disabling and
stopping it again:
# systemctl disable --now handbook-heartbeat.service
Removed '/etc/systemd/system/multi-user.target.wants/handbook-heartbeat.service'.
8.2.3. Reading Status, Dependencies, and Failure Results
Every unit carries a small set of result properties that say how its last
job ended. With the heartbeat stopped by disable --now:
$ systemctl show -p ActiveState -p SubState -p Result -p ExecMainStatus -p NRestarts handbook-heartbeat.service
Result=success
NRestarts=0
ExecMainStatus=0
ActiveState=inactive
SubState=dead
Result= records how the unit reached its current state: success here
means the stop job completed cleanly. ExecMainStatus is the main process's
exit status, and NRestarts counts automatic restarts since the last clean
start or stop (Section 8.3.4 exercises both). To see failure values, use a
unit that cannot work: a one-shot whose ExecStart points at a program
that does not exist. Contents of
/etc/systemd/system/handbook-bad-exec.service:
[Unit]
Description=Handbook missing executable demonstration
[Service]
Type=oneshot
ExecStart=/opt/handbook-heartbeat/missing.py
Load it and start it, as root:
# systemctl daemon-reload
# systemctl start handbook-bad-exec.service
Job for handbook-bad-exec.service failed because the control process exited with error code.
See "systemctl status handbook-bad-exec.service" and "journalctl -xeu handbook-bad-exec.service" for details.
The start job itself failed, and systemctl printed the two commands that
explain it. Follow the first:
$ systemctl status handbook-bad-exec.service --no-pager
× handbook-bad-exec.service - Handbook missing executable demonstration
Loaded: loaded (/etc/systemd/system/handbook-bad-exec.service; static)
Active: failed (Result: exit-code) since Thu 2026-11-19 08:59:28 UTC; 2s ago
Invocation: abf947274ab442faa7b1503b1178d333
Process: 64938 ExecStart=/opt/handbook-heartbeat/missing.py (code=exited, status=203/EXEC)
Main PID: 64938 (code=exited, status=203/EXEC)
Mem peak: 1.7M
CPU: 6ms
status exits 3 for a failed unit. The decisive field is
status=203/EXEC: 203 is systemd's code for "could not execute" - the
binary is missing, not executable, or its interpreter is unusable. A
failed unit stays in the failed state so it can be inspected; the
fleet-wide view is a single flag:
$ systemctl --failed --no-legend --no-pager
● handbook-bad-exec.service loaded failed failed Handbook missing executable demonstration
And the failure values in machine-readable form:
$ systemctl show -p Result -p ExecMainStatus handbook-bad-exec.service
Result=exit-code
ExecMainStatus=203
The common Result= values an administrator meets are success,
exit-code (the process returned non-zero), signal (killed by a signal),
timeout (Section 8.3.4), and core-dump (Section 8.8.3). A failed unit
stays failed even after the underlying problem is fixed - so that
--failed keeps listing it - until it is either started again or cleared:
# systemctl reset-failed handbook-bad-exec.service
Silent; reset-failed forgets the failure record without touching the
unit's file or configuration. Dependencies were covered with
list-dependencies and show -p Requires -p Wants -p After in
Section 8.1.1; both work on any unit and are the first stop when a service
starts in the wrong order.