Diagnose a Failed Linux systemd Service
Before you begin
- Applies to:Linux hosts where systemd manages the failing service.
- Where to start:Open a shell on the affected host. Set the unit name in Step 1 and keep the same shell open for the remaining checks.
- What you need:Have the exact unit name and sudo access for journal checks. For stateful services, follow the application's approved recovery and change procedures before retrying a start.
Guide tools
When a Linux service fails to start, systemctl shows its state and systemd records the service’s output and exit status in the journal. Follow the evidence from the failed unit to its recent logs, inspect the unit and its dependencies, then make a targeted correction and verify the recovery.
The examples use example.service; set the unit variable in Step 1 to the actual unit name and keep the same shell open. These steps inspect configuration before restarting anything. For databases, queues, and other stateful services, follow the application’s recovery and change procedures before repeating start attempts.
List Failed Units and Inspect the Target
Initial CheckStart with the failed-unit list, then check the specific service. The status output includes whether the unit is loaded, its active state, the process exit result, and a small amount of recent journal output. Save this information before resetting a failed state or making changes.
systemctl --failedunit=example.servicesystemctl status "$unit" --no-pager --full❯ Illustrative Output (Results Vary)
● example.service - Example application Loaded: loaded (/etc/systemd/system/example.service; enabled) Active: failed (Result: exit-code) Process: 1234 ExecStart=/opt/example/bin/server (code=exited, status=1/FAILURE)Find the First Useful Error Message
LogsRead this boot’s service log without a pager, then narrow it to the recent time window if needed. Look for the first application error before systemd’s final failure message; common causes include invalid configuration, unavailable dependencies, and permission errors.
What you should see · The journal identifies the earliest error tied to the failed start, such as a missing file or dependency.
If you see something else · If the current boot lacks the failure, check the incident time and retained logs. If you find the error, go to Step 3 and compare it with the unit settings before starting the service again.
sudo journalctl -b -u "$unit" --no-pager -n 100sudo journalctl -u "$unit" --since "30 minutes ago" --no-pager❯ Illustrative Output (Results Vary)
Oct 04 11:42:13 host server[1234]: Error: unable to read /etc/example/config.ymlOct 04 11:42:13 host systemd[1]: example.service: Main process exited, code=exited, status=1/FAILURE
Figure 1: A failed unit’s status and journal identify a permission error reading its configuration file.
Check the Unit File, Overrides, and Dependencies
Configurationsystemctl cat shows the main unit and any drop-ins, while systemctl show reports selected effective properties. Confirm the executable path, user, working directory, environment files, and required units exist. Unit files installed by packages usually live under /usr/lib/systemd/system or /lib/systemd/system; local overrides generally belong under /etc/systemd/system.
systemctl cat "$unit"systemctl show "$unit" \ -p FragmentPath -p DropInPaths -p User -p Group -p ExecStart -p WorkingDirectorysystemctl list-dependencies "$unit"❯ Illustrative Output (Results Vary)
FragmentPath=/usr/lib/systemd/system/example.serviceUser=exampleExecStart={ path=/opt/example/bin/server ; argv[]=/opt/example/bin/server ... }Check Unit Syntax and Application Inputs
ValidationAfter correcting a specific issue, validate the unit file if your systemd version provides systemd-analyze verify. Separately run the application’s own configuration check when available; unit syntax validation cannot confirm that the application config, credentials, network dependencies, or data are correct. If a unit file changed, reload systemd’s unit definitions before trying to start the service.
sudo systemd-analyze verify "$unit"# Run the application's documented config-check command here, if available.sudo systemctl daemon-reload❯ Illustrative Output (Results Vary)
No unit-file errors reported.Retry Once and Review the New Logs
RecoveryOnce the cause has been corrected, start the unit and check its state and newest journal entries. Confirm the application is actually serving its expected function; an active systemd state only confirms that the process is running according to the unit. Avoid repeated restarts when the service is failing on persistent data or a dependency that remains unavailable.
sudo systemctl start "$unit"systemctl is-active "$unit"systemctl status "$unit" --no-pager --fullsudo journalctl -u "$unit" --since "5 minutes ago" --no-pager❯ Illustrative Output (Results Vary)
activeActive: active (running)For more detail, see the systemd project’s debugging guide and the systemctl manual.
Your feedback keeps these production procedures accurate and battle-tested.