Interview Prep/Linux/systemd services and journald

`systemctl` commands hang or fail with `Failed to connect to bus: No such file or directory` inside a container or via `su`.

IntermediateTroubleshootingsystemd services and journald
Answer

Likely causes → No systemd running as PID 1 (most containers), or for --user, no XDG_RUNTIME_DIR/user bus because the session was started with su instead of a full login.

Diagnose →

ps -p 1 -o comm=
echo $XDG_RUNTIME_DIR $DBUS_SESSION_BUS_ADDRESS

Fix → In containers, run the process directly (no systemd). For user units, log in properly (machinectl shell user@ or SSH) or set XDG_RUNTIME_DIR=/run/user/$(id -u).

Prevent → Use machinectl shell or sudo -iu user with linger for user-unit management.

All Linux questions Roadmap: Linux

More on systemd services and journald