> ## Content Index
> Fetch the complete content index at: https://blog.coopnet.us/llms.txt
> Use this file to discover other available public pages before exploring further.

# A systemd service that exits 0 in 18 ms, SELinux and two lost quotes
- URL: https://blog.coopnet.us/systemd-selinux-quotes-crash-loop/
- Published: 2026-11-23T13:13:44.000Z
- Updated: 2026-11-23T13:13:44.000Z
- Description: My Python service on an SELinux host crash-looped twice. systemd couldn't exec a sh wrapper under /home (203/EXEC), so I run it through bash -c. Later that line lost its quotes, and bash ran nothing and exited 0 in 18 ms. Quote the bash -c string and watch NRestarts after edits.
- Author: Renstur
- Tags: Automation & Linux, systemd, selinux, field-notes

A Python service on my CentOS Stream 10 box crash-looped, and systemd kept calling every exit a success. Active, restarted, active again. Forty restarts in a few minutes, each one a clean exit with nothing in the journal.

It was two separate traps on the same unit. Either one will crash-loop a service on its own, and the second one hides behind the fix for the first.

```tested-on
os: CentOS Stream 10
kernel: 6.12.0-266.el10
selinux: enforcing
hermes agent: 0.17.0, later 0.22.5

```

## The setup

The service is Hermes Agent, a Python app that runs under its own account, `svc-agent`, from a venv in that account's home directory. It has two system units, a gateway and a dashboard, both with `User=svc-agent`.

The app ships an installer for its unit file. It writes an `ExecStart` that points at a small `#!/bin/sh` launcher inside the home directory. On a stock Debian box that'd be fine. On this host it never started once.

## Trap 1: SELinux won't let systemd exec a script under /home

The first failure was at least loud about it:

```console
$ systemctl status agent-gateway.service
...
Failed at step EXEC spawning /home/svc-agent/.hermes/hermes-agent/.hermes/bin/hermes: Permission denied
Main process exited, code=exited, status=203/EXEC

```

Status 203 means systemd couldn't exec the program at all. The file was there and it was executable. The difference is that SELinux is enforcing, and everything under `/home/svc-agent` carries the `user_home_t` label.

The odd bit was that `ausearch` showed no AVC denial. I nearly crossed SELinux off the list because of that. Don't. No AVC in the log doesn't mean SELinux wasn't involved.

Rather than fight the policy, I tested what systemd would actually run with a throwaway unit as the same user:

```console
$ sudo systemd-run --uid=svc-agent --wait /home/svc-agent/.hermes/hermes-agent/.hermes/bin/hermes --version

```

I tried three targets:

- the `#!/bin/sh` wrapper failed with 203, Permission denied
- the real `python` binary in the venv worked
- `/bin/bash`, which is labelled `shell_exec_t`, worked, and bash could then start the Python module from the home directory

So the fix is a drop-in that execs bash, and bash execs the module:

```console
$ cat /etc/systemd/system/agent-gateway.service.d/override.conf
[Service]
ExecStart=
ExecStart=/bin/bash -c 'exec /home/svc-agent/.hermes/hermes-agent/venv/bin/python -m hermes_cli.main gateway run --replace'

```

The empty `ExecStart=` line clears the one from the base unit first. That drop-in is load-bearing. I deleted it once while tidying up and got 40 restarts in a few minutes.

## Trap 2: the quotes are load-bearing too

Later I rewrote that drop-in over SSH, from inside a single-quoted remote command. The outer quotes ate the inner ones without a word. The file ended up like this:

```console
$ cat /etc/systemd/system/agent-gateway.service.d/override.conf
[Service]
ExecStart=
ExecStart=/bin/bash -c exec /home/svc-agent/.hermes/hermes-agent/venv/bin/python -m hermes_cli.main gateway run --replace

```

Without the quotes, systemd splits the line into separate arguments. bash takes the single word `exec` as its command string, and the rest become `$0` and positional parameters it never uses. `exec` with no arguments does nothing, so bash exits 0 straight away.

That's what makes this one nasty. No syntax error and no stack trace, just a service that keeps finishing successfully:

```console
$ systemctl status agent-gateway.service
...
Main process exited, code=exited, status=0/SUCCESS
Duration: 18ms
Mem peak: 1.2M

```

Those two numbers gave it away. This app can't import its CLI in 18 ms, and a Python interpreter won't fit in 1.2M. That's bash exiting, not the app. If a service ran for a few milliseconds and exited 0 with an empty journal, I look at the quoting in `ExecStart` first now.

## Why I didn't notice straight away

`daemon-reload` hides it. The reload picks up the broken file, but the running process doesn't care and keeps going. Everything looks fine until the next restart, which might be days later during an update.

So I don't trust a reload anymore. After I touch a unit or a drop-in, I restart it and watch the restart counter for a minute:

```console
$ sudo systemctl restart agent-gateway.service
$ watch -n 5 systemctl show -p NRestarts agent-gateway.service
NRestarts=0

```

If that number moves in the first 60 seconds, something's wrong.

I also stopped writing unit files inside quoted SSH strings. Either edit the file on the host, or copy it over as a file and install it from there, so nothing has to survive a round of quoting:

```console
$ scp override.conf app-01.example.lab:/tmp/override.conf
$ ssh -t app-01.example.lab 'sudo install -m 0644 /tmp/override.conf /etc/systemd/system/agent-gateway.service.d/override.conf'

```

## It came back on the other unit

About a month later, an update rewrote the app's launcher in the service account's home directory to point at another `#!/bin/sh` script. The gateway was fine because of its drop-in. The dashboard unit didn't have one, and it started crash-looping with status 126.

Same trap, same fix. A second drop-in for the dashboard runs `bash -c 'exec .../venv/bin/python -m hermes_cli.main dashboard ...'`, with the quotes intact this time. Both drop-ins are now marked "do not clean up" in my notes.

## The side quest: no compiler

The reason I was touching the unit in the first place was that the app's update had failed:

```console
FileNotFoundError: [Errno 2] No such file or directory: 'make'

```

One of its dependencies, python-olm, didn't have a wheel for this platform, so pip compiles a bundled C library at install time. This host had no toolchain at all. It only worked before because the package was already in the venv and the build cache hid the problem.

Installing `make`, `gcc` and `gcc-c++` with dnf fixed it. I didn't take the green update as proof, though. I ran a cold-cache build in a scratch venv to be sure.

## What I saw and what I didn't check

Observed on this host, CentOS Stream 10 with SELinux enforcing, September and October 2026:

- the `#!/bin/sh` launcher under `/home` failed with 203/EXEC and no AVC in `ausearch`
- `/bin/bash` and the venv's `python` both ran from a `systemd-run` test unit
- the unquoted `bash -c` line exited 0 in 18 ms at 1.2M, over and over
- the dashboard unit later failed with status 126 before it got its own drop-in

Not checked: the exact SELinux rule that blocks the sh launcher while bash gets through, and whether a dontaudit rule is why no AVC showed up. I also didn't record the systemd version.

None of this is the same as the `systemctl --user` bus error I wrote up in [an earlier post](https://blog.coopnet.us/systemctl-user-failed-to-connect-to-bus/). That one fails loudly. This one exits 0, which is a much worse thing for a service to do.