Lab: systemd Failures¶
Pairs with: Understanding systemd
Environment: A single disposable VM.
Starting conditions¶
- Create a test service, exactly as in the parent article's exercise:
# /etc/systemd/system/labapp.service
[Unit]
Description=Lab Test Application
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/sleep infinity
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
- Confirm
systemctl status labappshowsactive (running).
Instructions¶
Part 1 — Break it, deliberately¶
Introduce one of the following faults:
- Crash loop: change
ExecStartto a command that fails immediately and consistently, e.g./bin/false, keepingRestart=on-failureand a shortRestartSec. Rundaemon-reloadand restart the unit. - Dependency failure: add
Requires=nonexistent.serviceto the[Unit]section (referencing a unit that doesn't exist),daemon-reload, then try to start it. - Wrong user: add
User=nonexistentuserto[Service](a user account that doesn't exist on this system),daemon-reload, restart.
Part 2 — Diagnose it¶
Using systemctl status labapp and journalctl -u labapp, determine:
- Is the unit considered
failed, or is it stuck in some other state? - What specific error does
journalctlshow, and does it point at the actual root cause directly, or do you need to reason about it?
Expected results¶
- Crash loop fault:
systemctl statuswill show rapid restart attempts; if restarts exceed the defaultStartLimitBurst(5 within 10 seconds, by default) within the window, systemd gives up and the unit ends infailedstate withStart request repeated too quicklyin the journal — a very specific, greppable message. - Dependency failure fault:
systemctl start labappfails immediately with the dependency unit reported as not found;journalctlwill reference the missing unit by name directly. - Wrong user fault: the service fails to start with a
status=217/USER(or similar) exit code visible insystemctl status's own output, without needing to dig intojournalctlat all for this particular one — the exit code itself is the diagnostic.
Diagnosis checklist¶
- [ ] Did you check
systemctl statusfor the specificstatus=<code>/<reason>on the last exit, not just whether it saysfailed? - [ ] For the crash-loop fault: did you recognize
StartLimitBurst/StartLimitIntervalSecas the mechanism that eventually stops the thrashing, rather than it looping forever? - [ ] Did
journalctl -u labapp --since "5 min ago"show enough history to see the pattern (rapid repeated starts), or did you need--sinceadjusted to capture it?
Success criteria¶
Given any of the three faults (without being told which), you can state the specific root cause — not just "it's failed" — using only systemctl status and journalctl -u labapp, within one minute.
Cleanup / rollback¶
sudo systemctl disable --now labapp.service
sudo rm /etc/systemd/system/labapp.service
sudo systemctl daemon-reload
sudo systemctl reset-failed labapp.service # clear any lingering "failed" state record
Confirm systemctl status labapp now reports Unit labapp.service could not be found before considering the environment cleaned up.