When a service refuses to start, the answer is almost always in systemctl status and journalctl -xeu. These two commands give the state of the
service, the exit code and the last log lines. Most of the time, the
error comes from an invalid configuration file, a port already in use, a
missing permission or a missing dependency.
What you will learn
- Apply a diagnostic method in 5 steps
- Read and interpret the output of
systemctl status - Pinpoint the error with
journalctl -xeu - Fix the 7 most frequent causes of failure
- Understand systemd exit codes
- Restart a service cleanly after a fix
In what context?
Troubleshooting services is a daily skill for an administrator:
- You have just installed Nginx or PostgreSQL, and the service does not start on the first try
- After a package update, a service refuses to restart because of a configuration change
- A service worked yesterday and is failed this morning with no apparent intervention
- You changed a configuration file and the service no longer restarts
- After a reboot, several services are failed and you must diagnose quickly
5-step diagnostic method
-
Check the state of the service
Terminal window systemctl status nginx● nginx.service - A high performance web server and a reverse proxy serverLoaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: enabled)Active: failed (Result: exit-code) since Wed 2026-04-16 08:15:32 CEST; 2min agoProcess: 1234 ExecStart=/usr/sbin/nginx (code=exited, status=1/FAILURE)Main PID: 1234 (code=exited, status=1/FAILURE)CPU: 12msavr. 16 08:15:32 srv01 nginx[1234]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)avr. 16 08:15:32 srv01 systemd[1]: nginx.service: Main process exited, code=exited, status=1/FAILUREavr. 16 08:15:32 srv01 systemd[1]: nginx.service: Failed with result 'exit-code'.The key information is:
- Active: failed, the service has failed
- Result: exit-code, the process ended with an error
- status=1/FAILURE, the exit code
- The last log lines, here, port 80 is already in use
-
Read the detailed logs
Terminal window journalctl -xeu nginxThe
-xflag adds explanations,-ejumps to the end,-ufilters by unit. It is the most useful command to understand a failure.To see the logs of the last start attempt:
Terminal window journalctl -u nginx --since "5 min ago" -
Check the service configuration
Terminal window # Test the configuration syntaxnginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successfulMost services offer a test command:
Service Test command Nginx nginx -tApache apachectl configtestSSH sshd -tPostfix postfix checkNamed named-checkconf -
Identify the cause and fix it
Fix the configuration file, free the port, adjust the permissions or install the missing dependency (see the common causes below).
-
Restart and verify
Terminal window # If the unit file was changedsudo systemctl daemon-reload# Restart the servicesudo systemctl restart nginx# Verifysystemctl status nginx
The 7 most frequent causes of failure
1. Syntax error in the configuration
Symptom: the service stops immediately after starting.
nginx: [emerg] unknown directive "server_nam" in /etc/nginx/sites-enabled/default:3Fix: correct the typo and test the syntax before restarting.
2. Port already in use
Symptom: bind() failed (98: Address already in use).
# Find which process holds the portsudo ss -tlnp | grep :80LISTEN 0 511 0.0.0.0:80 0.0.0.0:* users:(("apache2",pid=5678,fd=4))Fix: stop the competing service or change the port.
3. Missing file or directory
Symptom: No such file or directory in the logs.
[emerg] open() "/var/log/nginx/access.log" failed (2: No such file or directory)Fix:
sudo mkdir -p /var/log/nginxsudo systemctl restart nginx4. Insufficient permissions
Symptom: Permission denied in the logs.
# Check the file ownerls -la /etc/nginx/ssl/Fix: adjust the permissions or the owner of the files concerned.
5. Missing dependency (package, library)
Symptom: error while loading shared libraries or command not found.
# Check for missing librariesldd /usr/sbin/nginx | grep "not found"Fix: install the missing package.
6. Incorrect unit file
Symptom: Failed to parse service type or Invalid argument.
# Show the content of the unit filesystemctl cat nginx.serviceFix: correct the unit file, then:
sudo systemctl daemon-reloadsudo systemctl restart nginx7. Dependency between services (ordering)
Symptom: the service starts too early, before the network or the database is ready.
# Check the dependenciessystemctl cat monapp.service | grep -E "After|Requires|Wants"Fix: add the ordering and dependency directives in the [Unit] section.
Careful, network.target does not guarantee that the network is
configured: to wait for a usable IP address, you must target
network-online.target, ordering it with After= and pulling it in with
Wants= (systemd documentation, systemd.special).
[Unit]Wants=network-online.targetAfter=network-online.target postgresql.serviceRequires=postgresql.serviceUnderstanding exit codes
The systemctl status output shows an exit code that helps the diagnosis:
Codes below 125 come from the program itself. From 200 upwards, it is systemd that failed to prepare the execution environment: the error is then in the unit, not in the program. Each code points precisely to the faulty directive, which speeds up the diagnosis a lot.
| Code | systemd name | What failed |
|---|---|---|
0 | Success | |
1 | Generic error: the program failed on its own | |
2 | Incorrect use of the command | |
200 | EXIT_CHDIR | The WorkingDirectory= cannot be found or accessed |
203 | EXIT_EXEC | The ExecStart= binary cannot be found, is not executable, or its interpreter is missing |
209 | EXIT_STDOUT | Could not set up the output (StandardOutput=) |
216 | EXIT_GROUP | The Group= does not exist, or the group change failed |
217 | EXIT_USER | The User= does not exist, or the user change failed |
219 | EXIT_CGROUP | The service could not be placed in its cgroup |
226 | EXIT_NAMESPACE | An isolation directive failed (PrivateTmp=, ProtectSystem=…) |
The two most frequent codes are 203 (the ExecStart= path is wrong, or
the script lacks the execute bit) and 217 (the user declared in the unit
does not exist on the machine, typical of a unit copied from another
server).
To find the exact code of a failure, query the ExecMainStatus property:
# Show the exact exit codesystemctl show nginx -p ExecMainStatusService states
systemctl list-units --state=failed| State | Meaning |
|---|---|
active (running) | The service runs normally |
active (exited) | The process ended successfully (normal for oneshot services) |
inactive (dead) | Stopped cleanly |
failed | The process ended with an error |
activating | Starting |
deactivating | Stopping |
Reset the failed state
After a fix, if the service stays marked failed:
sudo systemctl reset-failed nginxsudo systemctl start nginxAdvanced diagnosis
Increase a service's verbosity
A service has no universal "debug mode": each program has its own setting.
The systemd daemons (systemd-resolved, systemd-networkd…) all read the
SYSTEMD_LOG_LEVEL variable. For other software, look for the equivalent
in its documentation (-d option, LogLevel directive, error_log … debug
for Nginx). The temporary change goes through an override:
sudo systemctl edit systemd-resolved.serviceAdd an override:
[Service]Environment=SYSTEMD_LOG_LEVEL=debugsudo systemctl restart systemd-resolved# Once the diagnosis is done, remove the overridesudo systemctl revert systemd-resolved.serviceCheck resource limits
A service can fail because of system limits (number of open files, memory):
systemctl show nginx -p LimitNOFILE,LimitMEMLOCK,MemoryMaxTest a service by hand
To run the ExecStart command directly and see the full error:
# Get the start commandsystemctl cat nginx.service | grep ExecStart
# Run it by handsudo /usr/sbin/nginx -tQuick troubleshooting
The table starts from the message shown by systemctl status or by the
journal, and gives the likely cause then the action that confirms it.
The Result: field is the first clue: it tells whether the program failed on
its own, was killed, or ran out of time.
| Symptom | Likely cause | Solution |
|---|---|---|
Active: failed (Result: exit-code) | Invalid config or missing dependency | journalctl -xeu service + fix |
Active: failed (Result: timeout) | Service too slow to start | Increase TimeoutStartSec in the unit file |
Active: failed (Result: oom-kill) | Memory exhausted: the OOM Killer killed a process of the service | Check journalctl -k | grep -i oom |
Active: failed (Result: signal) | Process killed by a signal (SEGV or ABRT crash, manual kill) | Read the signal in status= and the journal |
code=exited, status=203/EXEC | Binary not found or not executable | Check the path in ExecStart |
code=exited, status=200/CHDIR | Missing working directory | Check WorkingDirectory |
| Service starts then stops | Wrong Type (forking vs simple) | Check Type= in the [Service] section |
Job failed, see journalctl | Generic message | Run journalctl -xeu service |
# Quick diagnostic scriptsystemctl status "$1" # Current statejournalctl -xeu "$1" --no-pager --lines=20 # Latest logssystemctl cat "$1" # Unit filesystemctl show "$1" -p ExecMainStatus # Exit codeGood practices
These five reflexes sum up the page. They avoid the two most costly mistakes: restarting blindly a service whose configuration is broken, and letting failed units pile up that nobody looks at any more in the monitoring.
- Always start with
systemctl status+journalctl -xeu, these two commands answer most questions - Test the configuration before restarting,
nginx -t,sshd -t,apachectl configtest - Run
daemon-reloadafter changing a.servicefile - Do not ignore failed services,
systemctl list-units --state=failedmust be checked regularly - Document the fixes, note the cause in a comment of the configuration file or in a runbook
Put it into practice
Diagnosing a healthy service teaches nothing: you need a real failure. This lab
gives you a VM where a systemd service goes into a crash loop; it is up
to you to run the systemctl status then journalctl -xeu method, fix
the cause and prove that the service still holds after a reboot of the
machine.
Key points
systemctl statusgives the state, the exit code and the last log lines, it is the starting pointjournalctl -xeu serviceshows the detailed logs of the service, it is the main diagnostic command- The 3 most frequent errors: invalid configuration, port in use, missing permission
- After changing a unit file:
daemon-reloadthenrestart - Exit codes (203, 200, 217…) point straight to the cause
systemctl reset-failedclears the failed state after a fixsystemctl list-units --state=failedgives the overall view of all services in error
Knowledge check
Check that the essentials of this guide are acquired. The questions only cover what has just been explained here.
Knowledge check
Check what you have learned with this interactive quiz
How it works
- The timer starts when you click Start
- Multiple choice, true/false and short answer questions
- You can move between questions
- Detailed results are shown at the end
Starts the quiz and the timer
Review
(0/0)Result saved on this device. It will be sent to your account at the next sync. Sync now
Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.
Weak areas
No topic below the pass mark.
Recommended next
Hints before you try again?
Continue the course: An active service that does not respond
A new full quiz with random questions
Work again only on the questions you missed