Every so often a command fails in a way that teaches you nothing, and you lose twenty minutes to a problem that has a one-line answer. This is one of those. I hit it again last week while bouncing a gateway service on the VPS, and since it keeps coming back — same mistake, different month — it belongs in my self-hosting security notes as a permanent entry rather than a thing I relearn.
The short version: running systemctl --user restart <service> as root fails with No medium found. It is not a disk problem. It is not a permissions problem on the unit file. It is not a corrupted systemd install. It is the fact that root’s shell has no XDG_RUNTIME_DIR pointing at root’s own user manager — and until you set XDG_RUNTIME_DIR=/run/user/0, the client has no idea where to deliver the request.
The restart that refused to restart
The scenario is always the same shape. Something is stuck. A gateway process is not picking up a config change, or it has wedged itself and I want a clean bounce rather than a kill. I am already logged in as root, because on this box almost everything I do is root-level: editing unit files, reading journals, poking at nginx, restarting docker. So the muscle memory takes over and I type the user-level restart, because the service in question is a user service, not a system one.
systemctl --user restart openclaw-gateway
And back comes:
Failed to restart openclaw-gateway.service: No medium found
That is the whole error. No unit name resolution failure, no “connection refused to bus”, no hint about runtime directories or user managers. Just No medium found, which reads like the machine is telling me it cannot find a floppy disk. The first time I saw it I assumed something had gone wrong with the filesystem — I checked mounts, I checked free space, I looked at whether the unit file had somehow been deleted. All fine. The service was running. The unit file was right there. Only the restart was impossible.
Why root is the wrong shell for a –user unit
Here is the mental model that makes the error stop being mysterious. A user service does not live in the system manager. It lives in a separate, per-user instance of systemd, and that instance is scoped to a runtime directory (XDG_RUNTIME_DIR) keyed by the user’s UID. When you are a normal logged-in user, the session sets XDG_RUNTIME_DIR for you (via pam_systemd(8)) and everything just works — --user resolves to that directory, finds the user manager, and the request lands.
Root’s shell is a different story. Root has a user manager too, and root’s runtime directory exists, but the environment variable that points at it is not guaranteed to be set in the contexts where I actually run commands — a root shell that came in over SSH, a script, a cron job, a subshell. When XDG_RUNTIME_DIR is unset, the systemctl --user client has nothing to resolve against. It does not fall back to a sensible default. It does not print “I could not find a user manager for UID 0”. It produces the least informative message in the entire systemd vocabulary.
The detail that makes this sticky is that it is not specific to one unit. It applies to any systemd user service on the box. I have hit it on openclaw-gateway and on hermes-gateway, and the only reason the list is that short is that those are the two user services I bounce most often. Every other user unit would behave exactly the same way. That is what makes it worth writing down: there is no per-service fix to remember, there is one environment fix that covers all of them.
The fix is one variable, and the placement matters
The fix is to tell the client where root’s runtime directory is before it runs:
export XDG_RUNTIME_DIR=/run/user/0
systemctl --user restart openclaw-gateway
That is it. The service restarts, the config reloads, and the whole detour collapses into two lines. The same two lines work for hermes-gateway, and for any other user unit I add later.
You can also do it as a one-shot without polluting the shell, which is what I use when the command is going into a script or a note rather than an interactive session:
XDG_RUNTIME_DIR=/run/user/0 systemctl --user restart hermes-gateway
Both forms are the same fix. The difference is scope. The export version changes the shell you are standing in, so every subsequent --user command in that session works — convenient if you are about to do status, journal, and restart in sequence. The inline version touches only that one invocation, which is what you want inside a script where an inherited environment variable could surprise you later, or in documentation where a reader might copy the block into a context you did not anticipate.
My rule of thumb: interactive shell, use export once at the top of the session and stop thinking about it. Anything that becomes a file — script, cron entry, playbook, runbook — use the inline form so the dependency is visible on the line where it matters instead of hiding somewhere above it.
Why the error message is the real problem
I can live with a missing environment variable. What cost me time is that “No medium found” actively points away from the cause. It sounds like storage. It sounds like hardware. In a late-night debugging session, the wrong error message is more expensive than no error message, because it sends you down a path and gives you false confirmation when you find nothing wrong there.
My internal checklist now fires before I start reading the message literally: if a --user command fails as root and the failure makes no obvious sense, suspect the runtime directory first. That check is instant — it is not a debugging session, it is a reflex. The reflex is the actual deliverable here, more than the fix itself.
What I ruled out first
It is worth being honest about the order I checked things in, because the ordering was wrong and that is where the time went.
First I suspected the unit file. That is the most common cause of a restart failing for me: a typo in a config I just edited, a referenced path that no longer exists, a service that refuses to start because something it depends on moved. But the request never reached the point where the unit file mattered. A syntax error in a unit would have produced something about the unit. This produced something about a medium.
Second I suspected storage, because the message said so. That is the trap in its purest form: I let the wording of an error dictate the first hypothesis. Free space, mount state, whether something had gone read-only underneath me. All of it clean. Of course it was — the box was serving traffic the whole time, and a real storage failure does not confine itself politely to one restart command.
Third, and only third, I asked the question I should have asked first: what is different about the context rather than the command? Not what am I trying to restart, but where am I standing when I ask for it. That reframing is what produced the answer in under a minute. The command was correct, the unit was correct, the service was fine. The shell was the broken part.
The tempting wrapper, and why I skipped it
Once you know the fix, the obvious next move is to make it disappear — a shell function, an alias, a small wrapper script that sets the variable and forwards the arguments. I considered it and decided against it for this box, for one reason: the wrapper would have to live somewhere that every relevant context sources, and the contexts that break are precisely the ones that do not source anything. A shell alias helps the interactive case, which is already the case where I remember the fix. It does nothing for the script, the cron entry, or the nested subshell, which are the cases where forgetting costs the most.
So instead of hiding the variable, I made it visible in the places where it is load-bearing. Any file that contains a --user command now shows XDG_RUNTIME_DIR=/run/user/0 on the same line. It is slightly more verbose, and it means that anyone reading that line — including future me at an inconvenient hour — sees the dependency without needing to know the story behind it. Explicit beats clever when the whole failure mode is “I forgot”.
Why root is not a special case, it is just the loudest one
I frame this as a root problem because root is where I trip over it, but the mechanism is not about root at all. It is about a user manager being addressed through an environment variable that a shell may or may not have. Root is simply the account I run most of my commands as, and the account whose shell is least likely to have been set up by a login session that hands out a runtime directory.
That reframing matters if I ever add another user service under a different account. The fix does not travel as “use /run/user/0”, because the trailing number is the UID, not a constant. The fix travels as “point the client at that account’s runtime directory before invoking --user“. The specific path in my notes is correct for the commands I actually run, and it is the form I keep, but the principle behind it is what stops the next instance of this from being a mystery.
Where it bites again
The places I have trained myself to expect it are the ones where the environment is not a fresh interactive login:
- A root shell over SSH. No session setup, no runtime directory exported, and the mistake is invisible until the command fails.
- Any script that shells out to systemctl. The script inherits whatever environment it was launched with, which may be nothing at all.
- Scheduled work. A cron job has an environment that is barely there by design. A
--userrestart inside one is a coin flip unless the variable is set explicitly on the line. - Nested shells and one-liners. A
bash -cor a subshell that does not carry the export forward.
The unifying property is that none of these are interactive sessions, and none of them will set the variable for you. If a --user command lives anywhere other than a properly set up login shell, it needs the variable set on the same line or exported immediately before.
The sequence I actually run now
When a user service needs a bounce, I do not start with the restart. I start by making the environment unambiguous, then I look before I act:
- Set
XDG_RUNTIME_DIR=/run/user/0for the shell, or inline it on the command. - Confirm the unit is what I think it is — the point is to avoid restarting the wrong gateway at the wrong moment.
- Restart the specific unit by name:
systemctl --user restart openclaw-gateway. - Verify the service actually came back, rather than trusting the absence of an error.
Step four is the one I used to skip. A restart command that returns cleanly only tells you the request was delivered. On a gateway, “delivered” and “healthy” are different states, and the gap between them is where a bad config turns into a silent outage.
What I would do differently
Two things, both about not re-learning this.
The first is documentation placement. My notes about this box live in a file I actually read before touching services, and this gotcha now sits at the top of the service-management section rather than buried next to whichever service revealed it. The lesson is generic — user units, root shell, runtime directory — so filing it under “openclaw” would have hidden it from future me working on hermes. Filing it under the general category is what makes it reusable.
The second is that I stopped treating --user as a cosmetic variant of the plain command. For a long time I read systemctl restart X and systemctl --user restart X as the same operation aimed at slightly different scopes. They are not. One talks to a global manager that is always there; the other talks to a per-user manager that has to be located through the environment, and that location step is exactly where this fails. Once I internalised that --user implies “there is an address to resolve, and I own the job of making sure it resolves”, the class of errors stopped being surprising.
The two-line takeaway
If a user unit will not restart from root and the message is nonsense, it is almost certainly XDG_RUNTIME_DIR. Set it to /run/user/0 and run the same command again:
export XDG_RUNTIME_DIR=/run/user/0
systemctl --user restart openclaw-gateway
The same pair works for hermes-gateway and for anything else running as a user service on this box. It is a small, mechanical fix for a problem that feels much larger than it is — and the only genuinely hard part, the part that costs the time, is remembering that “No medium found” has nothing to do with a medium at all.
What the man pages say (and what they don’t)
The mechanics are all documented, just split across pages that never once use the phrase “No medium found.” systemd.exec(5) defines XDG_RUNTIME_DIR and states that --user units live inside it; pam_systemd(8) is the component that actually creates the directory and exports the variable at login — which is exactly why a real login shell never hits this and an SSH root shell does. The --user flag itself is covered in systemctl(1), and the directory’s role in the wider scheme lives in the XDG Base Directory Specification.
What none of those pages tell you is the failure signature. Nothing in systemd’s documentation maps the string “No medium found” to “the client could not resolve a user manager.” The message is what the ENOMEDIUM error from sd-bus looks like when there is no bus address to connect to at all — the “medium” is the bus socket, not a disk — and that connection is only discoverable by reading the source or by hitting it at 11pm on your own box. That is the gap this post exists to fill: the docs give you the variable, but not the reflex to reach for it when the error text is actively misleading.
Related
- The Miner in ps Wasn’t Ollama, It Was a Container
- SSH Brute-Force to Crypto Miner: Hardening a VPS the Hard Way
- Fixing ECONNRESET on a Self-Hosted HTTP Bridge
- Docker’s FORWARD DROP Ate My Container-to-Host Traffic
- Docker Compose .env Changes Need Container Recreation
Guides & explainers
Filed under: Ops & Automation, Automation, Docker, Self-Hosting, SSH, VPS