Problem overview
On a Linux VPS or Linux dedicated server running Ubuntu Server, a systemd service can fail in several visible ways: a Failed to start message, Unit entered failed state, a non-zero exit status, a restart loop, or a service that is down after a reboot. Usually systemd is only reporting a failure caused by the unit file, the executable, a missing file or user, or a dependency. Examples use SERVICE_NAME; replace it with your unit, such as nginx.
Four verbs are easy to confuse:
- start: starts the service now, not at reboot.
- restart: stops then starts it, dropping connections.
- reload: asks a running service to re-read its configuration, if supported.
- enable: starts it at boot, not now.
daemon-reload re-reads unit files, not application configuration.
| Note: Repeated restarts destroy evidence. Each attempt buries useful log lines and can trigger the start limit. Read first, then restart once. |
Check service status
sudo systemctl status SERVICE_NAMEIn the status output, the Loaded: line shows whether the unit file was found (not-found or masked points at the unit itself) and whether it is enabled. The Active: line shows failed, or activating (auto-restart) during a restart loop. The Main PID line carries the result, for example code=exited, status=203/EXEC.
| Status | Meaning | First check |
|---|---|---|
| 1, 2, other low numbers | The application itself reported an error | Application lines in the journal |
| 200/CHDIR | WorkingDirectory= is missing or inaccessible | ls -ld DIRECTORY |
| 203/EXEC | ExecStart= program is missing, not executable or has a bad interpreter line | ls -l PROGRAM |
| 216/GROUP, 217/USER | The Group= or User= account does not exist | getent passwd USER |
| 226/NAMESPACE | Sandbox mount setup failed, often a missing ReadWritePaths= directory | Paths in the unit file |
| signal=KILL | Process was killed, often by the out-of-memory killer | sudo journalctl -k | grep -i oom |
Decode any code with systemd-analyze exit-status 203. If the state reads start-limit-hit, fix the cause, then run sudo systemctl reset-failed SERVICE_NAME.
| Note: A service that shows active (running) for a second and then fails started correctly; the application exited. Look at the application's own messages, not the unit file. |
Inspect logs
Read the journal
sudo journalctl -u SERVICE_NAME -n 100 --no-pagersudo journalctl -u SERVICE_NAME -b --no-pagersudo journalctl -p err -b --no-pagerThese print the last 100 lines, everything since boot, and all error-level messages since boot. Read upward from the newest failed attempt. Watch for No such file or directory, Permission denied, Address already in use and Dependency failed for. Add -b -1 for the previous boot; this needs a persistent journal (ls /var/log/journal).
Inspect the unit and its dependencies
sudo systemctl cat SERVICE_NAMEsystemd-analyze verify /etc/systemd/system/SERVICE_NAME.servicesudo systemctl list-dependencies SERVICE_NAMEcat prints the unit file and every drop-in override. verify flags syntax errors and missing executables. list-dependencies shows what must run first.
| Note: Look for a drop-in directory such as /etc/systemd/system/SERVICE_NAME.service.d/ in the cat output. A forgotten override often explains unexpected behaviour. |
Identify and correct the root cause
Precaution: the fixes below change the server. Back up any file first (sudo cp -a FILE FILE.bak) and apply them in a quiet window, because a restart drops connections.
| Cause | Diagnose (read-only) | Fix (modifies server) |
|---|---|---|
| Missing or non-executable program | command -v PROGRAM ls -l /full/path | Use an absolute ExecStart= path; install the missing package; for scripts add a shebang and sudo chmod 755 /full/path |
| Ownership or permissions | namei -l /path/to/file (owner and mode of each directory) | sudo chown SERVICE_USER:SERVICE_GROUP /path; use 640 for files, 750 for directories. Never 777. |
| Configuration error | sudo nginx -t, sudo apachectl configtest | Correct the reported line, then retest |
| Missing environment variables | systemctl show SERVICE_NAME -p Environment -p EnvironmentFiles | Systemd ignores shell profiles; use Environment= or EnvironmentFile= |
| Port already in use | sudo ss -ltnp | grep ':PORT' | Stop the conflicting process or change the listen port |
| Dependency not ready | systemctl list-dependencies SERVICE_NAME | Add After= and Wants=; for network needs use network-online.target |
Edit units with sudo systemctl edit SERVICE_NAME, which writes an override that survives package updates. Then:
sudo systemctl daemon-reloadIf AppArmor blocks the service (sudo journalctl -k | grep -i apparmor), adjust its profile. Never disable AppArmor or the firewall as a fix.
| Note: Tests run as root can pass while the service account fails. Check as that user: sudo -u SERVICE_USER ls /path. |
Restart and verify
sudo systemctl restart SERVICE_NAMEsudo systemctl status SERVICE_NAMEsudo journalctl -u SERVICE_NAME -fExpect Active: active (running) and no new error lines; press Ctrl+C to stop following the log. A Type=oneshot service normally shows active (exited). Confirm the application responds (for example ss -ltn). To start at boot:
sudo systemctl enable SERVICE_NAMEsystemctl is-enabled SERVICE_NAMEThe second command should print enabled.
| Note: Failures only after reboot usually mean a dependency or mount was not ready. Verify after a planned reboot too. |
Prevent recurring failure
- Set Restart=on-failure with RestartSec=5 so transient crashes recover.
- Use absolute paths, a dedicated service user and StateDirectory= for writable data.
- Declare dependencies with After= and Wants=, and run systemd-analyze verify after every unit edit.
- Monitor disk and memory (df -h, free -h).
If you would rather not administer services yourself, a managed VPS or managed dedicated server moves OS-level maintenance to ICSDC engineers.