Skip to content
Français
Sync not enabled: your progress stays in this browser My learning
Select theme
Français

Troubleshoot a Linux service that will not start with systemd

By updated

Improve this page

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

  1. Check the state of the service

    Terminal window
    systemctl status nginx
    ● nginx.service - A high performance web server and a reverse proxy server
    Loaded: 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 ago
    Process: 1234 ExecStart=/usr/sbin/nginx (code=exited, status=1/FAILURE)
    Main PID: 1234 (code=exited, status=1/FAILURE)
    CPU: 12ms
    avr. 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/FAILURE
    avr. 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
  2. Read the detailed logs

    Terminal window
    journalctl -xeu nginx

    The -x flag adds explanations, -e jumps to the end, -u filters 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"
  3. Check the service configuration

    Terminal window
    # Test the configuration syntax
    nginx -t
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful

    Most services offer a test command:

    ServiceTest command
    Nginxnginx -t
    Apacheapachectl configtest
    SSHsshd -t
    Postfixpostfix check
    Namednamed-checkconf
  4. 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).

  5. Restart and verify

    Terminal window
    # If the unit file was changed
    sudo systemctl daemon-reload
    # Restart the service
    sudo systemctl restart nginx
    # Verify
    systemctl 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:3

Fix: correct the typo and test the syntax before restarting.

2. Port already in use

Symptom: bind() failed (98: Address already in use).

Terminal window
# Find which process holds the port
sudo ss -tlnp | grep :80
LISTEN 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:

Terminal window
sudo mkdir -p /var/log/nginx
sudo systemctl restart nginx

4. Insufficient permissions

Symptom: Permission denied in the logs.

Terminal window
# Check the file owner
ls -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.

Terminal window
# Check for missing libraries
ldd /usr/sbin/nginx | grep "not found"

Fix: install the missing package.

6. Incorrect unit file

Symptom: Failed to parse service type or Invalid argument.

Terminal window
# Show the content of the unit file
systemctl cat nginx.service

Fix: correct the unit file, then:

Terminal window
sudo systemctl daemon-reload
sudo systemctl restart nginx

7. Dependency between services (ordering)

Symptom: the service starts too early, before the network or the database is ready.

Terminal window
# Check the dependencies
systemctl 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.target
After=network-online.target postgresql.service
Requires=postgresql.service

Understanding 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.

Codesystemd nameWhat failed
0Success
1Generic error: the program failed on its own
2Incorrect use of the command
200EXIT_CHDIRThe WorkingDirectory= cannot be found or accessed
203EXIT_EXECThe ExecStart= binary cannot be found, is not executable, or its interpreter is missing
209EXIT_STDOUTCould not set up the output (StandardOutput=)
216EXIT_GROUPThe Group= does not exist, or the group change failed
217EXIT_USERThe User= does not exist, or the user change failed
219EXIT_CGROUPThe service could not be placed in its cgroup
226EXIT_NAMESPACEAn 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:

Terminal window
# Show the exact exit code
systemctl show nginx -p ExecMainStatus

Service states

Terminal window
systemctl list-units --state=failed
StateMeaning
active (running)The service runs normally
active (exited)The process ended successfully (normal for oneshot services)
inactive (dead)Stopped cleanly
failedThe process ended with an error
activatingStarting
deactivatingStopping

Reset the failed state

After a fix, if the service stays marked failed:

Terminal window
sudo systemctl reset-failed nginx
sudo systemctl start nginx

Advanced 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:

Terminal window
sudo systemctl edit systemd-resolved.service

Add an override:

[Service]
Environment=SYSTEMD_LOG_LEVEL=debug
Terminal window
sudo systemctl restart systemd-resolved
# Once the diagnosis is done, remove the override
sudo systemctl revert systemd-resolved.service

Check resource limits

A service can fail because of system limits (number of open files, memory):

Terminal window
systemctl show nginx -p LimitNOFILE,LimitMEMLOCK,MemoryMax

Test a service by hand

To run the ExecStart command directly and see the full error:

Terminal window
# Get the start command
systemctl cat nginx.service | grep ExecStart
# Run it by hand
sudo /usr/sbin/nginx -t

Quick 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.

SymptomLikely causeSolution
Active: failed (Result: exit-code)Invalid config or missing dependencyjournalctl -xeu service + fix
Active: failed (Result: timeout)Service too slow to startIncrease TimeoutStartSec in the unit file
Active: failed (Result: oom-kill)Memory exhausted: the OOM Killer killed a process of the serviceCheck 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/EXECBinary not found or not executableCheck the path in ExecStart
code=exited, status=200/CHDIRMissing working directoryCheck WorkingDirectory
Service starts then stopsWrong Type (forking vs simple)Check Type= in the [Service] section
Job failed, see journalctlGeneric messageRun journalctl -xeu service
Terminal window
# Quick diagnostic script
systemctl status "$1" # Current state
journalctl -xeu "$1" --no-pager --lines=20 # Latest logs
systemctl cat "$1" # Unit file
systemctl show "$1" -p ExecMainStatus # Exit code

Good 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-reload after changing a .service file
  • Do not ignore failed services, systemctl list-units --state=failed must 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 status gives the state, the exit code and the last log lines, it is the starting point
  • journalctl -xeu service shows 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-reload then restart
  • Exit codes (203, 200, 217…) point straight to the cause
  • systemctl reset-failed clears the failed state after a fix
  • systemctl list-units --state=failed gives 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

6 questions
6 min
70% to pass

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