Available: permanent, freelance, remoteMorocco

ENFR
Contact me
Topics

NewsSystems

A systemd service will not start: a six-step method

State, exit code, journal, real definition, check: the order in which I read what systemd already knows, with exit codes 203, 217 and 200 explained.

El Mehdi Jouan

El Mehdi Jouan · Systems & support engineer

· 4 min read

A service that will not start is the most common call in Linux support. The temptation is to run systemctl restart three times and hope. I do the opposite: I first read what systemd already knows, in a fixed order. Most of the time, the cause is written in plain words by the second command.

Every command below was run on Ubuntu 26.04 (systemd 259) against a service I broke on purpose. They exist in the same form on RHEL, Oracle Linux, Debian and their derivatives. Replace myapp.service with the name of your unit.

1. The state, in one line then in detail

systemctl is-active myapp.service
systemctl status myapp.service --no-pager -l

is-active answers active, failed, inactive or activating. The last one often misleads: with Restart=on-failure, a service that crashes in a loop shows activating (auto-restart), not failed. It still does not work.

In status, two lines matter:

  • Loaded: gives the path of the unit file actually loaded. If it is not the one you just edited, you are fixing the wrong file.
  • Main PID: ... (code=exited, status=...) gives the exit code. It is the most valuable clue.

2. The exit code tells you which step failed

Codes from 200 upwards do not come from your program: systemd failed to launch it. The suffix names the step. The ones I meet most often:

CodeMeaningUsual cause
203/EXECthe binary could not be executedwrong path in ExecStart, missing x bit, wrong interpreter
217/USERthe user does not existUser= points to a missing account
200/CHDIRthe working directory is not reachableWorkingDirectory= missing or unreadable

I reproduced all three: an ExecStart pointing to a missing file gives status=203/EXEC, an unknown User= gives status=217/USER, a missing WorkingDirectory= gives status=200/CHDIR.

An ordinary code (1, 2, 127...) or a signal (status=9/KILL, status=11/SEGV) comes from the program itself: it started, then stopped. You then need its own messages.

3. The unit's journal, since this boot

journalctl -u myapp.service -b --no-pager -n 50 -o short-iso

-b limits to the current boot, -n 50 to the last 50 lines, -o short-iso gives unambiguous timestamps. This is where systemd writes the exact sentence. For my 203/EXEC, the journal said:

demo-app.service: Unable to locate executable '/opt/demo/run.sh': No such file or directory
demo-app.service: Failed at step EXEC spawning /opt/demo/run.sh: No such file or directory

To search for a sentence across the whole machine rather than one unit, -g filters by pattern:

journalctl -b -g 'Failed at step' --no-pager

4. The real definition of the unit

systemctl cat myapp.service

This prints the main file and every override file (.d/*.conf) in the order systemd applies them, each preceded by its path. This is often where you find a forgotten override.conf that changes ExecStart or User.

For one precise value, as systemd computed it after merging:

systemctl show myapp.service -p ExecMainStatus,Result,NRestarts,User,DropInPaths

NRestarts tells how many times systemd has already restarted the service. DropInPaths lists the overrides that were loaded.

5. Check the file before restarting

sudo systemd-analyze verify /etc/systemd/system/myapp.service

verify checks the syntax and that the executables exist, without starting anything. On my broken unit, it answered Command /opt/demo/run.sh is not executable: No such file or directory before the first attempt.

6. Fix, reload, reset

After you change a unit file, systemd rereads nothing until you ask it to:

sudo systemctl daemon-reload
sudo systemctl reset-failed myapp.service
sudo systemctl restart myapp.service
systemctl is-active myapp.service

reset-failed clears the failed state and the restart counter. Without it, a service that just hit its limit (5 starts in 10 seconds by default) can refuse to start again. I checked it: right after fixing the cause, systemctl start still answered Job for ... failed; eleven seconds later, it started. reset-failed saves the wait, and saves you from thinking the fix did not work.

To change a unit shipped by a package, I never edit the file in /usr/lib/systemd/system: the next update would overwrite it. I use an override:

sudo systemctl edit myapp.service

The editor creates /etc/systemd/system/myapp.service.d/override.conf and reloads systemd on exit. It needs a terminal: in my scripted tests I wrote that file by hand, followed by a daemon-reload, which amounts to the same thing. To replace ExecStart, you must first clear it with an empty ExecStart= line, then give the new value, otherwise systemd rejects the unit. I tried it: status then shows Loaded: bad-setting and the journal says Service has more than one ExecStart= setting, which is only allowed for Type=oneshot services. Refusing.

When none of this is enough

  • The service waits for a dependency that never comes: systemctl list-dependencies myapp.service shows the tree, and systemd-analyze critical-chain myapp.service shows what delayed it at boot.
  • The list of failed units on the machine: systemctl --failed.
  • The program runs by hand but not under systemd: compare the environment. systemd reads neither .bashrc nor /etc/profile. Variables must be declared with Environment= or EnvironmentFile=.

In short

systemctl status myapp.service --no-pager -l
journalctl -u myapp.service -b --no-pager -n 50 -o short-iso
systemctl cat myapp.service
sudo systemd-analyze verify /etc/systemd/system/myapp.service
sudo systemctl daemon-reload && sudo systemctl reset-failed myapp.service && sudo systemctl restart myapp.service

Five commands, always in this order. The state, the code, the journal, the definition, the check. Restart only once you understand.

  • linux
  • systemd
  • systemctl
  • journalctl
  • rhel