Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

fix(install): write the uid out — %U resolves to 0 for a User=<name> system unit

antinrml1526bad44816
diff --git a/CLAUDE.md b/CLAUDE.md
index b40d7e26..fcea8122 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -209,7 +209,7 @@ to `resources/` (rr) and drive any project from one manifest:
version control). The script refuses to start without a VNC password file. Two further
host-side facts that `scripts/install.sh` NOW CARRIES ITSELF, and that the feature dies
quietly without: (1) `loginctl enable-linger <user>`, or the unit stops at
- logout and never starts at boot; (2) `Environment=XDG_RUNTIME_DIR=/run/user/%U` in
+ logout and never starts at boot; (2) `Environment=XDG_RUNTIME_DIR=/run/user/<uid>` in
mso.service — a system unit running as `User=` gets NO user-bus address, so without it
every `systemctl --user` call fails with "Failed to connect to bus: No medium found".
`lib/camoufox/service.ts` reports that as an error rather than as "not installed", so the
diff --git a/docs/MANAGED-APPS.md b/docs/MANAGED-APPS.md
index 7140874b..41c60805 100644
--- a/docs/MANAGED-APPS.md
+++ b/docs/MANAGED-APPS.md
@@ -445,7 +445,8 @@ Handled in three places, deliberately overlapping so that no single one has to b
- `lib/managed-apps/runner.ts` → `resolveCommand()` falls back to `~/.local/bin` and
`~/.bun/bin` when PATH misses — the same lesson `hermes_cmd()` in
`scripts/managed-app-install` had already learned the hard way.
-- `scripts/install.sh` writes `Environment=XDG_RUNTIME_DIR=/run/user/%U` plus a PATH that
+- `scripts/install.sh` writes `Environment=XDG_RUNTIME_DIR=/run/user/<uid>` (the uid written out —
+ the `%U` specifier expands to 0 for a `User=<name>` system unit) plus a PATH that
includes those directories, and runs `loginctl enable-linger`. **Linger is not optional**:
without it `/run/user/<uid>` is destroyed at logout and the variable points at nothing.
diff --git a/lib/managed-apps/manager.ts b/lib/managed-apps/manager.ts
index b74c7e14..fef55a10 100644
--- a/lib/managed-apps/manager.ts
+++ b/lib/managed-apps/manager.ts
@@ -129,7 +129,7 @@ export async function getManagedApp(id: ManagedAppId): Promise<ManagedAppView> {
// been seen, and nothing about the bus can make that observation wrong.
diagnostic:
installation.type === "not-installed" && userBusUnavailable()
- ? "MSO cannot reach this user's systemd bus, so it cannot see user services — this app may in fact be installed. Run `loginctl enable-linger` for the user, and set XDG_RUNTIME_DIR=/run/user/%U in mso.service (a drop-in under /etc/systemd/system/mso.service.d/)."
+ ? "MSO cannot reach this user's systemd bus, so it cannot see user services — this app may in fact be installed. Run `loginctl enable-linger` for the user, and set XDG_RUNTIME_DIR=/run/user/<uid> in mso.service (a drop-in under /etc/systemd/system/mso.service.d/)."
: null,
};
}
diff --git a/lib/managed-apps/user-bus.ts b/lib/managed-apps/user-bus.ts
index 8ff4fc46..b0b2f47b 100644
--- a/lib/managed-apps/user-bus.ts
+++ b/lib/managed-apps/user-bus.ts
@@ -46,7 +46,7 @@ export function userBusEnv(): Record<string, string> | undefined {
// - Set and usable (a terminal, `machinectl shell`, an operator pointing at
// a non-default runtime dir on purpose): leave it completely alone.
// - Set but with nothing behind it: the unit hard-codes
- // `XDG_RUNTIME_DIR=/run/user/%U`, which is a static string evaluated when
+ // `XDG_RUNTIME_DIR=/run/user/<uid>`, which is a static string evaluated when
// the service starts. At boot mso.service can win the race against
// systemd-logind creating that directory. Trusting the variable's mere
// presence would disable this fallback exactly when it is needed.
diff --git a/scripts/install.sh b/scripts/install.sh
index 95e1b0e9..54e5e75c 100755
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -252,11 +252,17 @@ Environment=HOSTNAME=$BIND
# A system unit with User= inherits no login session, so it gets no user-bus
# address and every \`systemctl --user\` it runs answers "Failed to connect to bus:
# No medium found". That silently broke the managed-app installs (which create
-# systemd USER units) and made installed apps read as "not installed". %U is the
-# UID of User= above, so this stays correct if the account is renamed. Paired with
+# systemd USER units) and made installed apps read as "not installed". Paired with
# the \`loginctl enable-linger\` below, without which /run/user/<uid> is destroyed
# at logout.
-Environment=XDG_RUNTIME_DIR=/run/user/%U
+#
+# The UID IS WRITTEN OUT, NOT the %U specifier. Do not "tidy" this back to %U — it
+# was tried and it FAILS: with User=antinrml and UID=1000, systemd 255 expanded %U
+# to 0, so the unit got XDG_RUNTIME_DIR=/run/user/0 and every systemctl --user
+# answered "No such file or directory" — the original bug wearing a new message.
+# Specifiers are expanded while the unit is parsed, before the NAME in User= has
+# been resolved to a uid, so %U falls back to the manager's own uid (root).
+Environment=XDG_RUNTIME_DIR=/run/user/$(id -u)
# systemd would otherwise give this unit only
# /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin. Both managed-app CLIs install
# themselves into ~/.local/bin, so without this \`which hermes\` fails inside the
diff --git a/scripts/managed-app-install b/scripts/managed-app-install
index f1cf366b..ece51922 100755
--- a/scripts/managed-app-install
+++ b/scripts/managed-app-install
@@ -85,7 +85,7 @@ therefore no XDG_RUNTIME_DIR. Fix it once, on the host:
sudo loginctl enable-linger $(id -un)
sudo mkdir -p /etc/systemd/system/mso.service.d
- printf '[Service]\nEnvironment=XDG_RUNTIME_DIR=/run/user/%%U\n' \\
+ printf '[Service]\nEnvironment=XDG_RUNTIME_DIR=/run/user/%s\n' "$(id -u)" \\
| sudo tee /etc/systemd/system/mso.service.d/10-user-bus.conf
sudo systemctl daemon-reload && sudo systemctl restart mso