8.8. Troubleshooting Service Failures
Sections 8.2 and 8.3 met individual failure results; this section works the diagnosis systematically: validate before starting, run the program in the open when the journal is ambiguous, then read the three classic failure families - permissions, dependencies, ports - and the three noisier ones: timeouts, restart loops, and core dumps.
8.8.1. Configuration Validation and Foreground Diagnostics
The cheapest failure is the one caught before systemctl start.
systemd-analyze verify checks a unit file the way a compiler checks
source: syntax, executables, paths. The heartbeat unit passed it silently
in Section 8.3.1. Its broken sibling from Section 8.2.3 does not:
# systemd-analyze verify /etc/systemd/system/handbook-bad-exec.service
handbook-bad-exec.service: Command /opt/handbook-heartbeat/missing.py is not executable: No such file or directory
The command exits 1 and names the exact defect that later showed up as
status=203/EXEC in Section 8.2.3. The same discipline applies to every
configuration touched in this chapter: rsyslogd -N1 before restarting
rsyslog (Section 8.6.2), postfix check before sending mail
(Section 8.7.1), and logrotate --debug before forcing rotation
(Section 8.5.2). None of these restart anything; all of them catch
typos before they become outages.
When a unit fails and the journal is not enough, run the failing command
yourself, as the service account, in the foreground. The permission
failure in the next subsection is the model case: the journal showed
touch: cannot touch ...: Permission denied, and running
sudo -u handbook-app touch /var/lib/handbook-restricted/state
reproduces it interactively, where options like strace or a shell can be
added. Foreground execution also separates "the program fails when
systemd runs it" from "the program fails everywhere" - the first points
at the unit's environment, the second at the program. Two reading aids
complete the toolkit: systemctl status exits 3 for a failed unit and 0
for an active one, so scripts can branch without parsing; and
journalctl -xeu UNIT - the extended view with explanatory context that
systemctl's own failure messages suggest - is the fastest route from
"failed" to "why".
8.8.2. Permissions, Missing Dependencies, and Port Conflicts
The first family: a service that cannot write where it tries to write.
Contents of /etc/systemd/system/handbook-perm.service:
[Unit]
Description=Handbook permission failure demonstration
[Service]
Type=oneshot
User=handbook-app
ExecStart=/usr/bin/touch /var/lib/handbook-restricted/state
Prepare an unfriendly directory, load the unit, and start it - as root:
# install -d -m 755 -o root -g root /var/lib/handbook-restricted
# systemctl daemon-reload
# systemctl start handbook-perm.service
Job for handbook-perm.service failed because the control process exited with error code.
See "systemctl status handbook-perm.service" and "journalctl -xeu handbook-perm.service" for details.
The journal carries the application's own error:
# journalctl -u handbook-perm.service -n 8 --no-pager
Nov 19 09:11:20 client1 systemd[1]: Starting handbook-perm.service - Handbook permission failure demonstration...
Nov 19 09:11:20 client1 touch[68875]: touch: cannot touch '/var/lib/handbook-restricted/state': Permission denied
Nov 19 09:11:20 client1 systemd[1]: handbook-perm.service: Main process exited, code=exited, status=1/FAILURE
Nov 19 09:11:20 client1 systemd[1]: handbook-perm.service: Failed with result 'exit-code'.
Nov 19 09:11:20 client1 systemd[1]: Failed to start handbook-perm.service - Handbook permission failure demonstration.
Permission denied from touch itself, then the familiar failure chain.
Which step of the path denied? namei walks every component of the path
and shows who owns it:
# namei -l /var/lib/handbook-restricted
f: /var/lib/handbook-restricted
drwxr-xr-x root root /
drwxr-xr-x root root var
drwxr-xr-x root root lib
drwxr-xr-x root root handbook-restricted
Every directory is traversable, but the target is owned by root while
the service runs as handbook-app - the write fails at the last step.
The fix follows the diagnosis; as root:
# chown handbook-app:handbook-app /var/lib/handbook-restricted
# systemctl reset-failed handbook-perm.service
# systemctl start handbook-perm.service
All three silent, and the last now succeeds (exit 0, no restart loop: a
oneshot that completes is done). The lesson generalizes: when a service
fails at a file operation, compare the running user from the unit with
the ownership shown by namei -l or ls -ld at every level of the path.
The second family: a dependency that cannot be found. Contents of
/etc/systemd/system/handbook-missing-dep.service:
[Unit]
Description=Handbook missing dependency demonstration
Requires=handbook-nonexistent.service
[Service]
Type=oneshot
ExecStart=/bin/true
After a daemon-reload, starting it fails before any process runs:
# systemctl start handbook-missing-dep.service
Failed to start handbook-missing-dep.service: Unit handbook-nonexistent.service not found.
The exit status is 5 - "unit not found" - rather than 1. The status confirms nothing ran:
$ systemctl status handbook-missing-dep.service --no-pager
○ handbook-missing-dep.service - Handbook missing dependency demonstration
Loaded: loaded (/etc/systemd/system/handbook-missing-dep.service; static)
Active: inactive (dead)
Inactive, not failed: the job was refused at dependency resolution. Fix by removing the impossible requirement and reloading:
# sed -i "/^Requires=/d" /etc/systemd/system/handbook-missing-dep.service
# systemctl daemon-reload
# systemctl start handbook-missing-dep.service
The final start is silent and succeeds. Missing dependencies most often
mean a package was never installed or a companion unit was renamed -
systemctl list-unit-files | grep fragment finds what actually exists.
The third family is the sneaky one: a port conflict that systemctl
start does not report. Two identical units each run a small HTTP server
on the same address; contents of
/etc/systemd/system/handbook-port-a.service (and handbook-port-b
differs only in its description and name):
[Unit]
Description=Handbook port conflict demonstration A
[Service]
Type=simple
User=nobody
ExecStart=/usr/bin/python3 -m http.server 8080 --bind 127.0.0.1 --directory /srv/handbook-port
Prepare the served directory, load, and start both, as root:
# install -d /srv/handbook-port
# systemctl daemon-reload
# systemctl start handbook-port-a.service
# systemctl start handbook-port-b.service
Both starts printed nothing and exited 0 - yet the second unit is dead:
# systemctl is-failed handbook-port-b.service
failed
This is the trap of Type=simple from Section 8.3.1's table: the start
job completes when the process is forked, and the bind failure happens
milliseconds later. The journal shows it:
# journalctl -u handbook-port-b.service -n 10 --no-pager
Nov 19 09:11:46 client1 python3[69107]: ~~~~~~~~~~~~~~~~~~~^^
Nov 19 09:11:46 client1 python3[69107]: File "/usr/lib/python3.13/http/server.py", line 136, in server_bind
Nov 19 09:11:46 client1 python3[69107]: socketserver.TCPServer.server_bind(self)
Nov 19 09:11:46 client1 python3[69107]: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
Nov 19 09:11:46 client1 python3[69107]: File "/usr/lib/python3.13/socketserver.py", line 478, in server_bind
Nov 19 09:11:46 client1 python3[69107]: self.socket.bind(self.server_address)
Nov 19 09:11:46 client1 python3[69107]: ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
Nov 19 09:11:46 client1 python3[69107]: OSError: [Errno 98] Address already in use
Nov 19 09:11:46 client1 systemd[1]: handbook-port-b.service: Main process exited, code=exited, status=1/FAILURE
Nov 19 09:11:46 client1 systemd[1]: handbook-port-b.service: Failed with result 'exit-code'.
Errno 98, Address already in use - and who holds it:
# ss -ltnp "sport = :8080"
State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 0 5 127.0.0.1:8080 0.0.0.0:* users:(("python3",pid=69087,fd=3))
The filter expression "sport = :8080" selects the local server port;
the holder is the python3 from unit A. Resolve by stopping the first
unit, clearing the second's failure, and starting it:
# systemctl stop handbook-port-a.service
# systemctl reset-failed handbook-port-b.service
# systemctl start handbook-port-b.service
# systemctl stop handbook-port-b.service
All four silent; the last returns the machine to a clean state. The
discipline this family teaches: for any Type=simple service that binds
a port or opens a resource, systemctl start's success proves nothing -
follow it with is-active or is-failed, every time.
8.8.3. Timeouts, Restart Loops, and Core Dumps
A timeout looks different from the families above: the unit's process
is still running when the failure is declared. The readiness timeout of
Section 8.3.4 was a Type=notify unit that never became ready; the
same mechanism governs any start that takes too long. Contents of
/etc/systemd/system/handbook-timeout.service:
[Unit]
Description=Handbook startup timeout demonstration
[Service]
Type=oneshot
ExecStart=/bin/sleep 10
TimeoutStartSec=3
After a daemon-reload, as root:
# systemctl start handbook-timeout.service
Job for handbook-timeout.service failed because a timeout was exceeded.
See "systemctl status handbook-timeout.service" and "journalctl -xeu handbook-timeout.service" for details.
$ systemctl status handbook-timeout.service --no-pager
× handbook-timeout.service - Handbook startup timeout demonstration
Loaded: loaded (/etc/systemd/system/handbook-timeout.service; static)
Active: failed (Result: timeout) since Thu 2026-11-19 09:12:04 UTC; 3s ago
Invocation: 3bd2c529c5674cb1aaff332b7dff89b6
Process: 69216 ExecStart=/bin/sleep 10 (code=killed, signal=TERM)
Main PID: 69216 (code=killed, signal=TERM)
Mem peak: 1.7M
CPU: 9ms
Nov 19 09:12:01 client1 systemd[1]: Starting handbook-timeout.service - Handbook startup timeout demonstration...
Nov 19 09:12:04 client1 systemd[1]: handbook-timeout.service: start operation timed out. Terminating.
Nov 19 09:12:04 client1 systemd[1]: handbook-timeout.service: Main process exited, code=killed, status=15/TERM
Nov 19 09:12:04 client1 systemd[1]: handbook-timeout.service: Failed with result 'timeout'.
Nov 19 09:12:04 client1 systemd[1]: Failed to start handbook-timeout.service - Handbook startup timeout demonstration.
Result: timeout, and the still-running sleep was terminated with
SIGTERM. The fix depends on which side is wrong: the service is slow
(raise TimeoutStartSec), or it is stuck (fix the stuckness - the
journal lines before the timeout are the evidence). Restart loops were
demonstrated in Section 8.3.4 with handbook-crash.service, including the
start limit that stops them. What remains is the loop you cannot fix
yet and must quiet: the drop-in. Contents of
/etc/systemd/system/handbook-crash.service.d/10-fixed.conf:
[Service]
ExecStart=
ExecStart=/bin/true
Restart=no
The empty ExecStart= resets the vendor list (Section 8.1.2's pattern),
the second line installs a command that succeeds instantly, and
Restart=no removes the loop. After writing the drop-in, reload and
start:
# systemctl daemon-reload
# systemctl start handbook-crash.service
Both silent; the start succeeds this time, and the state confirms the loop is gone:
$ systemctl show -p Result -p ActiveState handbook-crash.service
Result=success
ActiveState=inactive
Success and a clean exit - the override broke the cycle without touching
the vendor file, and systemctl revert handbook-crash.service will undo
it when the real fix arrives.
The last family leaves the largest artifacts: core dumps. Debian's
systemd-coredump intercepts crashing processes through the kernel's
core handler, stores the dump under /var/lib/systemd/coredump, and
indexes it in the journal. The demonstration unit raises the core limit -
system services do not dump by default - and runs a program that kills
itself with SIGSEGV. Contents of
/etc/systemd/system/handbook-crashdump.service:
[Unit]
Description=Handbook core dump demonstration
[Service]
Type=simple
User=handbook-app
LimitCORE=infinity
ExecStart=/opt/handbook-heartbeat/crash.py
And of /opt/handbook-heartbeat/crash.py:
#!/usr/bin/env python3
import os
import signal
print("about to crash", flush=True)
os.kill(os.getpid(), signal.SIGSEGV)
Make it executable, then load and start the unit after a daemon-reload:
# chmod 755 /opt/handbook-heartbeat/crash.py
# systemctl daemon-reload
The start itself succeeds - Type=simple, and the crash follows - so
confirm the state:
# systemctl start handbook-crashdump.service
# systemctl is-failed handbook-crashdump.service
failed
Now the dump tooling. coredumpctl list shows every stored dump:
# coredumpctl list --no-pager
TIME PID UID GID SIG COREFILE EXE SIZE
Thu 2026-11-19 10:21:00 UTC 76955 999 989 SIGSEGV present /usr/bin/python3.13 765.9K
One crash: PID 76955, running as UID 999 (handbook-app), terminated by
SIGSEGV, dump present, 765.9 kilobytes. The details:
# coredumpctl info --no-pager
PID: 76955 (python3)
UID: 999 (handbook-app)
GID: 989 (handbook-app)
Signal: 11 (SEGV)
Timestamp: Thu 2026-11-19 10:20:59 UTC (2s ago)
Command Line: python3 /opt/handbook-heartbeat/crash.py
Executable: /usr/bin/python3.13
Control Group: /system.slice/handbook-crashdump.service
Unit: handbook-crashdump.service
Slice: system.slice
Boot ID: b1a896bcffd84283bb0806857c472fbb
Machine ID: 2f296ddb676141cd878f55748e26134a
Hostname: client1
Storage: /var/lib/systemd/coredump/core.python3.999.b1a896bcffd84283bb0806857c472fbb.76955.1795083659000000.zst (present)
Size on Disk: 765.9K
Message: Process 76955 (python3) of user 999 dumped core.
Every fact an investigation needs: which program, under which unit, from which boot, stored compressed where. Export the dump for analysis elsewhere - into john's workspace, so the file belongs to the reader:
# coredumpctl dump -o /home/john/debian-handbook/services-logs/crash.core --no-pager
PID: 76955 (python3)
UID: 999 (handbook-app)
GID: 989 (handbook-app)
Signal: 11 (SEGV)
Timestamp: Thu 2026-11-19 10:20:59 UTC (2s ago)
Command Line: python3 /opt/handbook-heartbeat/crash.py
Executable: /usr/bin/python3.13
Control Group: /system.slice/handbook-crashdump.service
Unit: handbook-crashdump.service
Slice: system.slice
Boot ID: b1a896bcffd84283bb0806857c472fbb
Machine ID: 2f296ddb676141cd878f55748e26134a
Hostname: client1
Storage: /var/lib/systemd/coredump/core.python3.999.b1a896bcffd84283bb0806857c472fbb.76955.1795083659000000.zst (present)
Size on Disk: 765.9K
Message: Process 76955 (python3) of user 999 dumped core.
dump prints the metadata listing once more - the same fields info
shows - and writes the raw core to the named file. chown hands the
artifact to john:
# chown john:john /home/john/debian-handbook/services-logs/crash.core
# file /home/john/debian-handbook/services-logs/crash.core
/home/john/debian-handbook/services-logs/crash.core: ELF 64-bit LSB core file, x86-64, version 1 (SYSV), SVR4-style, from 'python3 /opt/handbook-heartbeat/crash.py', real uid: 999, effective uid: 999, real gid: 989, effective gid: 989, execfn: '/usr/bin/python3', platform: 'x86_64'
The file command confirms a genuine ELF core carrying the crashing
command line. From here coredumpctl debug can open the dump in gdb on
a machine with the debugging symbols installed - the interactive path is
documented in coredumpctl(1). Dumps are large, so systemd-coredump
caps their storage in coredump.conf and prunes by size and age.
Close any troubleshooting session with the fleet view. This chapter's demonstrations left several units in the failed state:
# systemctl --failed --no-legend --no-pager
● handbook-crashdump.service loaded failed failed Handbook core dump demonstration
● handbook-notify-demo.service loaded failed failed Handbook notification demonstration
● handbook-notready.service not-found failed failed handbook-notready.service
● handbook-timeout.service loaded failed failed Handbook startup timeout demonstration
The third row shows a subtlety: handbook-notready.service was deleted in
Section 8.3.4, but its failed state persists in the manager until
cleared - not-found in the first column is the tell. Clear them all at
once:
# systemctl reset-failed
Silent, and --failed is empty afterwards. The demonstration units,
scripts, and configuration files from this chapter can be removed the same
way they were created: systemctl disable --now the still-enabled
practice units, delete the handbook-* unit files from
/etc/systemd/system and /usr/local/lib/systemd/system, remove
/opt/handbook-heartbeat, /etc/handbook-heartbeat, and the
/etc/logrotate.d/handbook-app fragment, then finish with
systemctl daemon-reload, systemctl reset-failed, and deletion of the
~/debian-handbook/services-logs workspace - each removal bounded to a
file this chapter created.