Linux services are responsible for running many of the critical components that keep a server operational. Web servers, databases, SSH, DNS services, background applications, monitoring agents, and scheduled tasks all depend on processes that must start, run, and stop correctly.
On most modern Linux distributions, systemd manages these services and controls their startup behavior, dependencies, logging integration, and recovery policies.
When a service fails, simply restarting it does not always solve the problem. The underlying cause might be an invalid unit file, incorrect permissions, a missing executable, an unavailable dependency, a port conflict, or a configuration error.
This guide explains how to troubleshoot systemd service failures step by step using systemctl, journalctl, and systemd-analyze. It includes practical examples for Ubuntu, Debian, and RHEL-based distributions, along with techniques for diagnosing failed startup dependencies, restart loops, and services that do not start during boot.
Whether you manage a single Linux server or maintain production infrastructure, these procedures will help you identify the root cause and restore services safely.
systemd is a system and service manager used by many modern Linux distributions. It is typically the first user-space process started by the kernel and runs as PID 1.
Its responsibilities include:
systemd manages resources through configuration files called unit files.
A unit file describes how a resource should be started, stopped, or managed. The most common unit types include:
| Unit Type | Purpose | Example |
|---|---|---|
.service | Manages a service or process | nginx.service |
.socket | Manages socket-based activation | sshd.socket |
.timer | Schedules an activation | backup.timer |
.mount | Manages a filesystem mount | data.mount |
.target | Groups units into a synchronization point | multi-user.target |
.path | Monitors filesystem paths | myapp.path |
For example, when a Linux server boots, systemd starts the units needed to reach its configured default target. Services may also be started later because another unit requires them or because a socket or timer activates them.
This dependency-based architecture makes service management flexible, but an incorrect dependency or unit configuration can prevent an application from starting.
For the broader administration context, see the Linux Server Administration Complete Guide.
The first step in systemd troubleshooting is to identify which services have failed.
The systemctl command provides information about service states, startup configuration, and dependency relationships.
Run:
sudo systemctl --failed This displays units that systemd currently considers failed.
To show only failed services:
sudo systemctl list-units --type=service --state=failed Example output:
UNIT LOAD ACTIVE SUB DESCRIPTION
nginx.service loaded failed failed A high performance web server
postgresql.service loaded failed failed PostgreSQL database server This gives you an initial view of the problem.
However, a failed service might be a consequence of another failure. For example, an application may fail because its required filesystem was not mounted or its database service did not start.
Do not assume that every failed service needs an independent fix.
Use:
sudo systemctl status nginx.service Replace nginx.service with the name of the affected unit.
The output typically includes:
For more complete output:
sudo systemctl status nginx.service --no-pager -l The -l option prevents long log messages from being truncated.
A systemd service can have several states.
| State | Meaning |
|---|---|
active (running) | The service process is currently running. |
active (exited) | The unit completed successfully and remains considered active, commonly with certain oneshot configurations. |
inactive (dead) | The service is not currently running. |
activating | systemd is in the process of starting the service. |
deactivating | systemd is stopping the service. |
failed | The service encountered a failure. |
A service being inactive does not automatically mean that something is broken. Some services are started only when needed.
Also distinguish between a service being active and being enabled:
active describes its current runtime state.enabled means it is configured to start automatically through its installation links.disabled means it is not configured for automatic startup in the normal way.static means it has no normal installation configuration for direct enabling.masked means the unit has been linked to /dev/null and cannot be started normally.Check whether a service is enabled:
systemctl is-enabled nginx.service Check whether it is running:
systemctl is-active nginx.service These checks answer different questions and should not be treated as interchangeable.
The status output is a useful starting point, but you should examine the service’s result and execution details before changing anything.
For example:
● myapp.service - Example Application
Loaded: loaded (/etc/systemd/system/myapp.service; enabled)
Active: failed (Result: exit-code)
Process: 1234 ExecStart=/opt/myapp/start.sh (code=exited, status=1/FAILURE) This indicates that systemd successfully loaded the unit file and attempted to execute the configured command, but the process exited with an error.
The next step is to investigate why the command failed.
Run:
systemctl show myapp.service \
-p LoadState \
-p ActiveState \
-p SubState \
-p Result \
-p ExecMainStatus These properties help identify whether the unit loaded correctly, what state it is in, and what result systemd recorded.
Run:
systemctl cat myapp.service This displays the main unit file and applicable drop-in configuration files.
It is particularly useful when a service behaves differently from what you expect because an administrator or software package has added an override.
Compare the configured executable, user, working directory, environment files, and dependencies with the actual application installation.
One of the most important tools for diagnosing systemd services is journalctl.
systemd integrates with the system journal, allowing administrators to inspect messages generated by services, the system manager, and the kernel.
A failed service’s status output may show only a few recent messages. The journal provides a more complete view.
Run:
sudo journalctl -u nginx.service To display the most recent 100 entries:
sudo journalctl -u nginx.service -n 100 --no-pager This is useful when a service fails immediately after startup.
For example, an application might report:
nginx: [emerg] bind() to 0.0.0.0:80 failed
Address already in use This indicates that another process may already be listening on the requested address and port.
The correct response is to identify the process using the port rather than repeatedly restarting Nginx.
Use:
sudo journalctl -u nginx.service -b The -b option limits the results to the current boot.
To inspect messages from the previous boot:
sudo journalctl -u nginx.service -b -1 This is particularly useful when a service failed during system startup but was manually started successfully afterward.
Previous-boot logs are available only when the relevant journal records have been retained. Systems using volatile-only journal storage may lose those records after a reboot.
To monitor messages as they arrive:
sudo journalctl -u nginx.service -f This is helpful when testing a configuration change or reproducing a service failure.
To review warning-level and more severe messages from the current boot:
sudo journalctl -b -p warning To inspect recent service-related events with explanatory messages:
sudo journalctl -xeu nginx.service Look for messages that appear immediately before the service transitions to the failed state.
Common clues include:
Permission deniedNo such file or directoryAddress already in useFailed at step EXECFailed to load configurationDependency failedStart request repeated too quicklyThese messages help narrow down the investigation.
For the complete command reference, see the official journalctl documentation.
systemd reports different failure results depending on which stage of service execution fails.
Understanding the error helps identify what to investigate next.
| Error or Exit Code | Meaning | What to Check |
|---|---|---|
1/FAILURE | Application returned a general failure code | Application logs and configuration |
203/EXEC | systemd could not execute the configured program | Executable path, permissions, interpreter, and filesystem |
200/CHDIR | systemd could not change to the configured working directory | WorkingDirectory= and directory permissions |
216/GROUP | systemd could not establish the configured group credentials | Group= and group existence |
217/USER | systemd could not establish the configured user credentials | User= and account configuration |
Result: timeout | A configured startup, stop, or other operation timed out | Application initialization and timeout settings |
Result: dependency | A required dependency prevented startup | Dependency unit status and configuration |
Result: exit-code | The process or a service command exited unsuccessfully | The exact exit status and journal entries |
These systemd-specific codes are different from ordinary application exit codes. A program can also return its own non-zero exit status after starting successfully.
Consider this service status:
Process: 1234 ExecStart=/opt/myapp/start.sh
(code=exited, status=203/EXEC) Possible causes include:
Inspect the file:
ls -l /opt/myapp/start.sh
file /opt/myapp/start.sh Check the first line of a script:
head -n 1 /opt/myapp/start.sh For a Bash script, the shebang should normally reference an available interpreter, such as:
#!/bin/bash Check that the interpreter exists:
command -v bash If the script is intended to be executable, correct its permissions according to the application’s security requirements:
sudo chmod 750 /opt/myapp/start.sh Do not grant unrestricted permissions simply to make the service start. The service’s configured user must have only the access it actually needs.
A service may fail even when its own executable and configuration are correct.
The reason could be a dependency that has not started or a startup ordering problem.
systemd uses several dependency directives, including Requires=, Wants=, After=, and Before=.
Run:
systemctl list-dependencies --all myapp.service This displays units pulled into the service’s dependency tree.
For reverse dependencies:
systemctl list-dependencies --reverse myapp.service You can also inspect selected dependency properties:
systemctl show myapp.service \
-p Requires \
-p Wants \
-p After \
-p Before These directives serve different purposes.
| Directive | Function |
|---|---|
Requires= | Adds a stronger dependency on another unit. If the required unit fails to activate, the requesting unit generally cannot start successfully. |
Wants= | Adds a weaker dependency. systemd attempts to start the wanted unit, but its failure does not normally prevent the requesting unit from starting. |
After= | Controls startup ordering. It does not, by itself, start or require the other unit. |
Before= | Specifies that the current unit should be started before another unit. |
A common mistake is assuming that After=database.service guarantees the database is running. It only establishes ordering when both jobs are part of the same transaction.
If an application genuinely requires a database service, its unit may need both a dependency and an ordering relationship.
For example:
[Unit]
Description=Example Application
Requires=postgresql.service
After=postgresql.service However, this should reflect the application’s real requirements.
For applications that need a database to be available over the network, starting the database service is not necessarily proof that the database is accepting connections. The application may still need connection retries or its own readiness checks.
An application that requires network connectivity may use:
Wants=network-online.target
After=network-online.target The network-online.target unit depends on the network manager’s wait-online implementation and configuration. It should not be treated as a universal guarantee that every remote service is reachable.
If the application connects to a remote database or API, implement appropriate connection retry and timeout handling within the application itself.
Avoid adding unnecessary dependencies to every service. Excessive or circular dependency relationships can make boot behavior more complicated.
A damaged or incorrect unit file is another common cause of failed services.
Unit files are usually stored in one of the systemd unit directories.
Common locations include:
| Location | Purpose |
|---|---|
/etc/systemd/system/ | Administrator-created units and persistent overrides |
/run/systemd/system/ | Runtime units and temporary configuration |
/usr/lib/systemd/system/ | Vendor-supplied unit files on many RHEL-based systems |
/lib/systemd/system/ | Common vendor unit location on Debian-based systems; often linked to /usr/lib on merged-usr installations |
The actual search path can vary by distribution and systemd build.
For an administrator-managed service:
sudo cat /etc/systemd/system/myapp.service For a packaged service:
systemctl cat nginx.service Check for:
User= or Group= values.Use:
sudo systemd-analyze verify /etc/systemd/system/myapp.service This checks the unit file and its referenced units for a range of configuration errors.
It can identify unknown directives, malformed configuration, and missing required dependencies.
A clean verification result does not prove that the application itself will run successfully. Application-level errors, permission problems, and unavailable resources must still be investigated.
For a service provided by a software package, avoid directly editing its original file under /usr/lib/systemd/system/ or /lib/systemd/system/.
Package upgrades may replace vendor-managed files.
A safer method is:
sudo systemctl edit myapp.service This creates or updates a drop-in override under the appropriate configuration directory.
For example, you might add:
[Service]
Environment="APP_MODE=production"
RestartSec=10s After saving the editor’s changes, systemctl edit reloads systemd’s unit configuration automatically.
If you create or modify a unit file manually instead, run:
sudo systemctl daemon-reload This instructs systemd to reload unit definitions.
Remember that daemon-reload does not restart the application process. Restart the service separately when the changed settings require it.
For more details, see the official systemd unit documentation and systemctl documentation.
A service can work correctly when launched manually as root but fail when systemd starts it under a restricted service account.
This often happens because systemd runs the application with a different user, group, environment, working directory, or filesystem view.
Inspect the unit file for:
User=appuser
Group=appgroup Verify that the account exists:
id appuser Check whether the account can access the application directory:
namei -l /opt/myapp/start.sh This command helps identify directory permissions along the path.
The service user needs execute permissions on the directories it must traverse and appropriate permissions on the files it must read or execute.
A service may fail because its configured working directory does not exist.
Inspect the unit:
WorkingDirectory=/opt/myapp Verify the directory:
ls -ld /opt/myapp If systemd reports 200/CHDIR, investigate the configured working directory and its accessibility.
Services do not automatically inherit the same interactive shell environment as an administrator.
A command that works in a terminal because the shell has configured PATH, application variables, or virtual environment settings may fail when started by systemd.
Use an environment file where appropriate:
[Service]
EnvironmentFile=/etc/myapp/myapp.env For an optional environment file that may be absent:
EnvironmentFile=-/etc/myapp/myapp.env The leading - tells systemd not to treat a missing file as a fatal error.
Check that the file exists when required and that the service user has the appropriate access.
Also remember that ExecStart= is not automatically executed through a shell. Shell operators such as pipes, redirection, and shell variable expansion should not be assumed to work directly in the command.
For complicated startup sequences, use a dedicated executable script with an explicit interpreter.
Security frameworks can prevent an application from accessing files or resources even when ordinary Unix permissions appear correct.
On SELinux-enabled systems, check the current mode:
getenforce Review recent denial messages:
sudo ausearch -m AVC,USER_AVC -ts recent On systems using AppArmor, inspect its status and kernel messages:
sudo aa-status
sudo journalctl -k -b Do not disable SELinux or AppArmor as a routine troubleshooting shortcut. Identify the policy denial and correct the application context or policy according to the security requirements.
A service may start successfully when an administrator runs systemctl start, yet fail during the normal boot process.
This can happen because the service starts before a required resource is ready, a mount is unavailable, the network is not initialized, or the service is not enabled for automatic startup.
Run:
systemctl get-default Common default targets include:
multi-user.target for a non-graphical multi-user system.graphical.target for a system configured to start a graphical environment.Inspect whether the service is enabled:
systemctl is-enabled myapp.service If the service is intended to start automatically, enable it:
sudo systemctl enable myapp.service To enable and start it immediately:
sudo systemctl enable --now myapp.service Enabling a service and starting a service are separate operations. enable configures automatic activation, while start activates the service now.
Review messages from the current boot:
sudo journalctl -b To focus on warning and error messages:
sudo journalctl -b -p warning To inspect a particular service:
sudo journalctl -u myapp.service -b --no-pager If the service failed during the previous boot, review:
sudo journalctl -u myapp.service -b -1 Use:
systemd-analyze blame This lists units by the time they took to start, although a long duration does not automatically mean that a unit is broken.
To inspect the critical startup chain:
systemd-analyze critical-chain To inspect the dependency chain for a particular unit:
systemd-analyze critical-chain myapp.service This can help identify ordering relationships that delay service activation.
For troubleshooting services that start inconsistently during boot, Red Hat also documents cases involving systemd ordering cycles and unavailable dependencies in its service startup troubleshooting guidance.
A service that repeatedly starts and stops may enter a restart loop.
This can happen when:
Run:
sudo systemctl status myapp.service
sudo journalctl -u myapp.service -n 100 --no-pager Look for repeated start attempts and messages such as:
Start request repeated too quickly.
Failed with result 'start-limit-hit'. This means systemd’s start rate limit has been reached.
It is a protection mechanism designed to prevent a repeatedly failing service from consuming excessive resources.
A long-running service may use:
[Service]
Restart=on-failure
RestartSec=5s Restart=on-failure instructs systemd to restart the service after eligible failures.
RestartSec=5s sets the delay before a restart attempt.
The correct policy depends on the application. A service that is expected to exit successfully after completing a task should not automatically receive the same restart behavior as a continuously running web server.
A service can also define its start rate limit:
[Unit]
StartLimitIntervalSec=60
StartLimitBurst=5
[Service]
Restart=on-failure
RestartSec=5s This example limits repeated start attempts within the configured time window.
The precise defaults and supported directives can vary with the installed systemd version and distribution.
Do not simply increase StartLimitBurst to hide repeated failures. Identify why the process exits first.
After fixing the underlying issue, clear the recorded failed state and start the service:
sudo systemctl reset-failed myapp.service
sudo systemctl start myapp.service reset-failed clears the unit’s failed state and resets its start-rate limiting counter.
It does not repair the service configuration or fix the underlying error. If the cause remains, the service will likely fail again.
Administrators sometimes confuse reloading systemd’s configuration with reloading an application’s configuration.
These are different operations.
After manually changing a unit file:
sudo systemctl daemon-reload This tells systemd to read the updated unit definitions.
To stop and start a service again:
sudo systemctl restart myapp.service Use this when the application needs a fresh process to apply its configuration.
Some services support reloading their configuration without a full process restart:
sudo systemctl reload nginx.service This works only when the unit and application support a reload operation, typically through an ExecReload= command or another supported mechanism.
To enable a service:
sudo systemctl enable myapp.service To enable and start it immediately:
sudo systemctl enable --now myapp.service When appropriate:
sudo systemctl stop myapp.service
sudo systemctl disable myapp.service Disabling a service does not necessarily stop a service that is already running. Similarly, stopping a service does not remove its automatic startup configuration.
Important: Avoid disabling, masking, or stopping critical system services unless you understand their role and have an appropriate recovery plan.
Consider a Linux server running a custom Python application.
The service is named myapp.service, and it is expected to start automatically after boot.
An administrator notices that the application is unavailable.
Run:
sudo systemctl status myapp.service Suppose the result shows:
Active: failed (Result: exit-code) This confirms that the service is not running successfully.
Run:
sudo journalctl -u myapp.service -n 50 --no-pager Suppose the logs show:
Failed to change to directory /opt/myapp
status=200/CHDIR The issue is related to the configured working directory.
Run:
sudo systemctl cat myapp.service Suppose the unit contains:
[Service]
User=appuser
WorkingDirectory=/opt/myapp-old
ExecStart=/usr/bin/python3 /opt/myapp/app.py The working directory no longer exists because the application was moved.
Run:
ls -ld /opt/myapp
ls -l /opt/myapp/app.py
id appuser Confirm that the directory exists and that the configured service user can access it.
Run:
sudo systemctl edit myapp.service Add:
[Service]
WorkingDirectory=/opt/myapp This creates a drop-in override instead of modifying the original vendor unit.
The systemctl edit operation reloads unit definitions after saving the override. Start the service:
sudo systemctl reset-failed myapp.service
sudo systemctl restart myapp.service Check the result:
sudo systemctl status myapp.service Inspect the latest logs:
sudo journalctl -u myapp.service -n 50 --no-pager If the service is intended to start automatically, verify its enablement:
systemctl is-enabled myapp.service This example demonstrates why reading the service logs and inspecting the unit configuration is more effective than repeatedly restarting a failed service.
Even experienced administrators can waste time by applying changes before identifying the actual failure.
Avoid the following mistakes:
Repeatedly restarting a failed service. A restart cannot fix a missing executable, invalid configuration, or denied permission.
Confusing daemon-reload with application reload. daemon-reload updates systemd’s understanding of unit files. It does not reload the application’s own configuration.
Assuming After= creates a dependency. After= defines ordering, not a requirement to start the other unit.
Editing vendor unit files directly. Package updates can replace those changes. Prefer drop-in overrides for administrator customizations.
Running everything as root. Changing User= to root may appear to solve a permission issue but can create unnecessary security exposure.
Disabling security controls to test a service. SELinux and AppArmor denials should be diagnosed and corrected rather than bypassed without justification.
Ignoring the journal. The most useful explanation is often recorded immediately before the service fails.
Increasing restart limits without investigating. This can hide a recurring application problem instead of fixing it.
After making a correction, verify that the service is healthy.
Check its runtime state:
systemctl is-active myapp.service Check for failed units:
sudo systemctl --failed Review the latest journal messages:
sudo journalctl -u myapp.service -n 50 --no-pager Inspect the unit’s configuration:
systemctl cat myapp.service If the service should start automatically, verify:
systemctl is-enabled myapp.service For critical production services, also verify the application itself. A service can be active while the application is unable to handle requests because of an unavailable database, incorrect network configuration, or another application-level problem.
Consider monitoring:
A successful systemctl status is an important check, but it should not replace an application-level health test.
Use this checklist when a Linux service fails to start or behaves unexpectedly.
Identify failed units with systemctl --failed.
Inspect the affected service with systemctl status.
Review recent service logs using journalctl -u.
Check logs from the current or previous boot.
Inspect the loaded unit file with systemctl cat.
Validate custom unit files with systemd-analyze verify.
Check the executable path and its permissions.
Verify the configured User=, Group=, and WorkingDirectory=.
Inspect environment files and application configuration.
Review Requires=, Wants=, and startup ordering.
Check port conflicts, filesystem mounts, and network availability.
Investigate SELinux or AppArmor denials where applicable.
Check restart policies and start rate limits.
Run daemon-reload after manually editing unit definitions.
Restart the service only after correcting the underlying problem.
Confirm the service starts successfully and performs its intended function.
A service can fail because of an invalid unit file, missing executable, incorrect permissions, unavailable dependency, application configuration error, port conflict, or resource problem. Start by checking systemctl status and journalctl -u.
Run:
sudo systemctl list-units --type=service --state=failed To show failed units of all types, use:
sudo systemctl --failed systemctl reload requests that a particular application reload its own configuration, provided that the service supports it.
systemctl daemon-reload tells systemd to reload unit files and their dependencies. It does not restart the application process.
Use:
sudo journalctl -b -1 For one specific service:
sudo journalctl -u myapp.service -b -1 Previous-boot messages must have been retained by the journal to be available.
First identify and correct the underlying error. Then run:
sudo systemctl reset-failed myapp.service
sudo systemctl start myapp.service Resetting the failed state alone does not repair the cause.
The service may be starting before a required dependency, mount, network resource, or configuration file is ready. Review the boot journal, dependency relationships, and startup ordering.
systemd provides the foundation for managing services on modern Linux servers. When a service fails, the most effective troubleshooting approach is to identify the failure state, inspect the journal, validate the unit configuration, and investigate dependencies, permissions, and startup conditions.
Commands such as systemctl status, journalctl, systemctl cat, and systemd-analyze verify provide the information needed to diagnose many common failures.
The key is to fix the underlying cause before restarting the service or changing its recovery policy.
By understanding unit files, service dependencies, execution environments, and boot behavior, Linux administrators can restore failed services more reliably and prevent the same problems from recurring.
Introduction Border Gateway Protocol (BGP) is the routing protocol used to exchange network reachability information…
Introduction A Linux server can experience connection failures even when its network interface is working…
Introduction TCP retransmissions are an important indicator of network reliability and performance. When a Linux…
Open Shortest Path First (OSPF) is a link-state routing protocol widely used in enterprise networks…
Group Policy is one of the most important management features in Windows Server Active Directory…
Windows DNS servers play an essential role in Active Directory environments, allowing computers, servers, applications,…