Services & systemd

Managed state or runtime directories cannot be prepared

StateDirectory or RuntimeDirectory fails before ExecStart. Check path collisions, ownership and capacity while preserving existing application state.

On this page
  1. Symptoms & scope
  2. Possible causes
  3. Diagnose safely
  4. Evidence-guided next steps
  5. References & review
  6. Related problems

Symptoms & scope

  • Startup exits with STATE_DIRECTORY or RUNTIME_DIRECTORY.
  • The expected directory path collides with a file or unsuitable link.

Relevant environment

systemd units using StateDirectory or RuntimeDirectory, including DynamicUser storage layout.

Recognizable messages (synthetic examples)
systemd[1]: example.service: Main process exited, code=exited, status=238/STATE_DIRECTORY

Inspect the named directory and preceding filesystem error.

systemd[1]: example.service: Main process exited, code=exited, status=233/RUNTIME_DIRECTORY

Check /run context and capacity before assuming persistent corruption.

Possible causes

These are possible explanations, not a confirmed diagnosis. Several independent faults can coexist.

  • A path collision, ownership setup error or read-only backing filesystem can block preparation.
  • Storage or inode exhaustion can prevent directory creation; /run may be full independently of /var/lib.

Diagnose safely

Run one command at a time in the relevant session. Read the explanation first. Uppercase placeholders need your own values; tools and privileges vary by distribution. These commands are displayed here and never executed by the website.

Check 1

Replace the unit; inspect settings before assuming path ownership.

systemctl show example.service -p StateDirectory -p RuntimeDirectory -p User -p DynamicUser

Interpret the result: StateDirectory is persistent state; RuntimeDirectory is runtime data. DynamicUser can use private storage and compatibility symlinks.

Check 2

Replace the path with the failing managed path from the journal; metadata only.

namei -l /var/lib/example

Interpret the result: A regular file at a required directory differs from a legitimate DynamicUser symlink. Inspect targets before moving anything.

Check 3

Reads typical state and runtime filesystem capacity; adjust for alternate roots.

df -h /var/lib /run

Interpret the result: A full /run tmpfs can block runtime setup while persistent storage has room. If allocation fails despite room, check inode availability as well.

Evidence-guided next steps

Resolve a verified path collision

If a stray file occupies the required directory, stop the service and archive it before provisioning the intended directory through the configured manager mechanism. Preserve existing state and documented private-directory layout.

Precautions: Do not delete service data or recursively change ownership without identifying contents and DynamicUser behavior.

Recovery / rollback: Stop the service, restore the archived path and previous unit, and reconnect the original state before startup.

Did this solution help you?

Share this solution#

Correct the specific storage constraint

If capacity or a read-only mount caused failure, restore writable capacity on that filesystem or move state using the application's supported procedure. Reduce the identified runtime-data consumer if /run is exhausted.

Precautions: State migration can require shutdown and backups. RuntimeDirectory contents usually disappear when stopping unless preservation is configured.

Recovery / rollback: Restore old directory settings and backed-up data with the application stopped; do not merge divergent live datasets.

Did this solution help you?

Share this solution#

References & review

This guide was prepared from primary project or distribution sources and reviewed on the date shown. This is an editorial source check, not evidence that a fix was reproduced on your hardware. Diagnostic log examples are synthetic fixtures. Version-dependent details must be checked against your installed release.