Failed service — separate unit validation from runtime failure
A failed systemd service is a state, not a root cause. Establish the unit, boot and first failure timestamp. Inspect exit code, signal, start-limit status, dependency failures and relevant authorized logs. Compare effective unit/drop-ins with the known-good configuration and verify the candidate. A missing executable requires correcting the path or restoring the trusted package; an application configuration error requires that application's own validator; resource or dependency failure needs separate investigation. Do not loop restarts or reset-failed to conceal a failure. After approved changes, reload unit metadata if needed, restart in a maintenance window and verify the expected state for the unit type and the intended effect. For a long-running service, check endpoint readiness as well; a successful Type=oneshot service without RemainAfterExit need not stay active. Roll back the unit/drop-in and application config together, then verify again. Prevent with unit verification, readiness gates and staged deployments. The lab checks a private invalid service with an absent executable, then a corrected service with /bin/true; no daemon is started or installed. Example prerequisites: Linux, Bash, Python 3; systemd-analyze with offline verify support. Run as a non-root user in a private temporary working directory. Example scope: native configuration validation. Expected output: missing executable rejected; corrected unit verified. No system configuration changes.
Formal Syntax & Structure
systemctl status UNIT; journalctl -u UNIT -b; systemd-analyze verify FILEParameters & Attributes
| Name | Type | Description |
|---|---|---|
| status | diagnostic evidence | Current state and recent diagnostics. |
| journalctl | diagnostic evidence | Authorized logs for the unit and boot. |
| verify | diagnostic evidence | Offline unit checks, not runtime readiness. |
Return Value
Expected normalized laboratory result: missing executable rejected; corrected unit verified. A passing fixture does not prove that a live incident has the same cause.
Working Example
python3 - <<'PY'import subprocess,tempfilefrom pathlib import Pathwith tempfile.TemporaryDirectory() as d: p=Path(d)/'bm-v39-demo.service' missing=Path(d)/'missing-executable' p.write_text(f'[Service]\nType=oneshot\nExecStart={missing}\n') bad=subprocess.run(['systemd-analyze','verify',str(p)],capture_output=True,text=True,timeout=8) assert bad.returncode!=0 and 'not executable' in bad.stderr p.write_text('[Service]\nType=oneshot\nExecStart=/bin/true\n') good=subprocess.run(['systemd-analyze','verify',str(p)],capture_output=True,text=True,timeout=8) assert good.returncode==0 and not good.stderr,good.stderrprint('missing executable rejected; corrected unit verified')PY