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(hosted): restore updates and Hermes runtime

Rahman4fd8bfd3995e
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 799e1f35..1abfcb54 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -12,6 +12,7 @@ this is the *what*, and it is what Settings → About shows as “What's new”.
**Fixed**
+- `hosted` restore updates and Hermes runtime
- `update` recover no-systemd container installs
- `installer` build node-pty reliably on Codespaces
- `managed-apps` support Hermes without systemd
diff --git a/frontend/slices/managed-apps/feature-app.tsx b/frontend/slices/managed-apps/feature-app.tsx
index a5689fcb..5ba15017 100644
--- a/frontend/slices/managed-apps/feature-app.tsx
+++ b/frontend/slices/managed-apps/feature-app.tsx
@@ -51,7 +51,9 @@ export function ManagedFeatureApp({ feature, publicDashboardUrl }: AppProps & {
it is a deployment that serves no dashboards, and only this file knows that. */}
{!uiAvailable ? (
<p className="shrink-0 border-b border-border px-3 py-1.5 text-[11px] leading-snug text-muted-foreground">
- No browser UI is exposed by this deployment, so the CLI below is the view. A managed app can work without a domain; split-origin dashboard hosts are optional.
+ {feature.applicationId === "hermes"
+ ? "Hermes is running as its agent/CLI runtime. The optional browser dashboard is not exposed on this host; use the interactive Hermes terminal below."
+ : "No browser UI is exposed by this deployment, so the CLI below is the view. A managed app can work without a domain; split-origin dashboard hosts are optional."}
</p>
) : null}
{view === "cli" || !uiAvailable ? (
diff --git a/frontend/slices/managed-apps/feature-cli.test.ts b/frontend/slices/managed-apps/feature-cli.test.ts
index 09ab421d..f9fb8ba2 100644
--- a/frontend/slices/managed-apps/feature-cli.test.ts
+++ b/frontend/slices/managed-apps/feature-cli.test.ts
@@ -7,7 +7,7 @@ describe("managed app CLI launch commands", () => {
});
it("keeps the upstream read-only status command for CLI-managed apps", () => {
- expect(cliCommand(dashboardFeature("hermes", "Hermes"))).toBe("hermes status");
+ expect(cliCommand(dashboardFeature("hermes", "Hermes"))).toBe("hermes");
expect(cliCommand(dashboardFeature("openclaw", "OpenClaw"))).toBe("openclaw status");
});
});
diff --git a/frontend/slices/managed-apps/feature-cli.ts b/frontend/slices/managed-apps/feature-cli.ts
index 155bb61d..5ce5f6bb 100644
--- a/frontend/slices/managed-apps/feature-cli.ts
+++ b/frontend/slices/managed-apps/feature-cli.ts
@@ -11,12 +11,13 @@ export function dashboardFeature(id: ManagedAppId, title: string): ManagedAppFea
return { id: `${id}:overview`, applicationId: id, title, route: "/", source: "nav-bundle", available: true };
}
-/** Safe read-only command shown when switching a managed-app window to CLI.
- * Hermes/OpenClaw expose `status`. 9Router does NOT: its upstream CLI starts the
- * server when invoked, while MSO manages the Docker runtime, so auto-running it
- * would race the container for port 20128. Docker logs are the useful read-only
- * server CLI surface and leave the terminal interactive afterwards. */
+/** Default terminal command for a managed app.
+ * Hermes is an agent/CLI first, so open its interactive runtime directly rather
+ * than reducing it to a dashboard/status card. OpenClaw's status command is the
+ * safe read-only default. 9Router has no equivalent status CLI because invoking
+ * its upstream launcher starts another server, so MSO shows container logs. */
export function cliCommand(feature: ManagedAppFeature): string {
+ if (feature.applicationId === "hermes") return "hermes";
if (feature.applicationId === "9router") return "docker logs --tail 80 9router";
return `${feature.applicationId} status`;
}
diff --git a/lib/host/self-update-offline.ts b/lib/host/self-update-offline.ts
new file mode 100644
index 00000000..c8b3d882
--- /dev/null
+++ b/lib/host/self-update-offline.ts
@@ -0,0 +1,40 @@
+import "server-only";
+import { promises as fs } from "node:fs";
+import os from "node:os";
+import path from "node:path";
+
+/**
+ * systemd-less hosts still need the updater to outlive the web process it
+ * replaces. `setsid -f` creates a detached process group; the wrapper redirects
+ * its stdio immediately, then runs the same guarded `mso update` path used from a
+ * terminal. The API still exposes only one boolean: normal update vs rebuild.
+ */
+export function offlineUpdateArgs(root: string, rebuildOnly = false): string[] {
+ return [
+ "-f",
+ "/bin/bash",
+ path.join(root, "scripts", "mso-offline-update-job"),
+ ...(rebuildOnly ? ["--rebuild-only"] : []),
+ ];
+}
+
+const offlineUpdatePidPath = (): string => path.join(os.homedir(), ".mso", "self-update.pid");
+
+/** True only for the detached updater process that owns the pid marker. */
+export async function offlineUpdateRunning(): Promise<boolean> {
+ const pidFile = offlineUpdatePidPath();
+ const raw = await fs.readFile(/* turbopackIgnore: true */ pidFile, "utf8").catch(() => "");
+ const pid = Number(raw.trim());
+ if (!Number.isSafeInteger(pid) || pid <= 1) return false;
+ try {
+ process.kill(pid, 0);
+ // Avoid treating a stale pid file as live after PID reuse. This branch is
+ // Linux-only because setsid fallback is Linux-only, so /proc is authoritative.
+ const cmdline = await fs.readFile(/* turbopackIgnore: true */ `/proc/${pid}/cmdline`, "utf8");
+ if (cmdline.includes("mso-offline-update-job")) return true;
+ } catch {
+ // Exited (or inaccessible) means stale; clean the marker below.
+ }
+ await fs.unlink(/* turbopackIgnore: true */ pidFile).catch(() => undefined);
+ return false;
+}
diff --git a/lib/host/self-update-status.test.ts b/lib/host/self-update-status.test.ts
index 0e8d9ede..1fe33514 100644
--- a/lib/host/self-update-status.test.ts
+++ b/lib/host/self-update-status.test.ts
@@ -7,7 +7,8 @@ vi.mock("node:child_process", () => ({
execFile: vi.fn((command: string, args: string[], _options: unknown, done: (error: { code: number } | null, stdout: string, stderr: string) => void) => {
let output = "", code = 0;
const key = args.join(" ");
- if (command !== "git") code = 1; // This real deployment has no systemd manager.
+ if (command === "setsid" && args[0] === "--version") { output = "setsid from util-linux"; code = 0; }
+ else if (command !== "git") code = 1; // This deployment has no systemd manager, but does have detached handoff.
else if (key === "rev-parse --is-inside-work-tree") { output = "true"; code = fixture.noGit ? 1 : 0; }
else if (key === "branch --show-current") output = fixture.branch;
else if (key === "rev-parse --short HEAD") output = "16860d9";
@@ -23,13 +24,12 @@ vi.mock("node:child_process", () => ({
const { getUpdateStatus, blockingReason } = await import("./self-update");
beforeEach(() => { fixture.branch = "main"; fixture.fetchFails = false; fixture.noGit = false; fixture.behind = 13; });
-describe("version discovery independent of restart support", () => {
- it("reports incoming commits on a host without systemd rather than a false current status", async () => {
+describe("version discovery independent of restart mechanism", () => {
+ it("offers the same update on a systemd-less host when detached handoff is available", async () => {
const result = await getUpdateStatus(true);
- expect(result).toMatchObject({ current: "16860d9", latest: "7cffd11", behind: 13, remoteChecked: true, supported: false });
- expect(result.reason).toContain("mso update");
+ expect(result).toMatchObject({ current: "16860d9", latest: "7cffd11", behind: 13, remoteChecked: true, supported: true, reason: null });
expect(result.commits).toHaveLength(1);
- expect(blockingReason(result, false)).toBe(result.reason);
+ expect(blockingReason(result, false)).toBeNull();
});
it("still reports available versions on detached HEAD but refuses mutation", async () => {
fixture.branch = "";
@@ -40,7 +40,7 @@ describe("version discovery independent of restart support", () => {
it("does not claim a failed fetch was verified", async () => {
fixture.fetchFails = true;
fixture.behind = 0;
- expect(await getUpdateStatus(true)).toMatchObject({ behind: 0, remoteChecked: false, supported: false });
+ expect(await getUpdateStatus(true)).toMatchObject({ behind: 0, remoteChecked: false, supported: true });
});
it("does not claim a cached-only poll checked the remote", async () => {
expect(await getUpdateStatus(false)).toMatchObject({ behind: 13, remoteChecked: false });
diff --git a/lib/host/self-update.test.ts b/lib/host/self-update.test.ts
index a8d64b7e..29159726 100644
--- a/lib/host/self-update.test.ts
+++ b/lib/host/self-update.test.ts
@@ -8,6 +8,7 @@ import { describe, expect, it, vi } from "vitest";
vi.mock("server-only", () => ({}));
const { parseCommits, blockingReason, updateBranchReason, updateUnitArgs } = await import("./self-update");
+const { offlineUpdateArgs } = await import("./self-update-offline");
const status = (over: Partial<Parameters<typeof blockingReason>[0]> = {}) => ({
supported: true,
@@ -67,6 +68,18 @@ describe("updateUnitArgs", () => {
});
});
+describe("offlineUpdateArgs", () => {
+ it("hands systemd-less updates to a detached fixed wrapper with only the rebuild boolean optional", () => {
+ expect(offlineUpdateArgs("/srv/mso")).toEqual([
+ "-f",
+ "/bin/bash",
+ "/srv/mso/scripts/mso-offline-update-job",
+ ]);
+ expect(offlineUpdateArgs("/srv/mso", true).at(-1)).toBe("--rebuild-only");
+ expect(offlineUpdateArgs("/srv/mso", true).join(" ")).not.toContain("sudo");
+ });
+});
+
describe("updateBranchReason", () => {
it("keeps Settings updates on main", () => {
expect(updateBranchReason("main\n")).toBeNull();
diff --git a/lib/host/self-update.ts b/lib/host/self-update.ts
index 2e416183..fe643ecb 100644
--- a/lib/host/self-update.ts
+++ b/lib/host/self-update.ts
@@ -5,6 +5,7 @@ import { promises as fs } from "node:fs";
import os from "node:os";
import path from "node:path";
import { HostError } from "./host-error";
+import { offlineUpdateArgs, offlineUpdateRunning } from "./self-update-offline";
// SERVER-ONLY. "Is there a newer MSO, and pull it in" — the deploy that CLAUDE.md
// describes (`git pull` → build → restart), driven from Settings instead of from a
@@ -36,7 +37,7 @@ export interface UpdateCommit {
}
export interface UpdateStatus {
- /** False when this deployment cannot self-update (not a checkout, no systemd). */
+ /** False when this deployment cannot self-update (for example, not a checkout or no safe handoff runtime). */
supported: boolean;
/** Why not, when `supported` is false — shown to the operator verbatim. */
reason: string | null;
@@ -164,7 +165,8 @@ async function isRunning(): Promise<boolean> {
run("systemctl", ["--user", "is-active", `${UNIT}.service`], 10_000),
run("systemctl", ["is-active", `${UNIT}.service`], 10_000),
]);
- return userUnit.code === 0 || legacySystemUnit.code === 0;
+ if (userUnit.code === 0 || legacySystemUnit.code === 0) return true;
+ return offlineUpdateRunning();
}
async function readLog(): Promise<string> {
@@ -185,6 +187,13 @@ async function automaticUpdateReason(): Promise<string | null> {
// is both non-interactive and non-root.
const userManager = await run("systemctl", ["--user", "show-environment"], 10_000);
if (userManager.code !== 0) {
+ // A container/hosted runtime can legitimately have no systemd at all (PID 1
+ // may be tini). The CLI already has a safe offline update path that quiesces
+ // only MSO-owned runtimes under the checkout exclusion lock. `setsid -f` is
+ // the missing handoff boundary: it lets that path survive the Next process it
+ // intentionally stops and replaces. No sudo and no arbitrary client argv.
+ const setsid = process.platform === "linux" ? await run("setsid", ["--version"], 5_000) : { code: 1 };
+ if (setsid.code === 0) return null;
return "Automatic restart is unavailable on this host. Run mso update from a terminal; version checks still work.";
}
@@ -217,19 +226,9 @@ export async function getUpdateStatus(fetchRemote = true): Promise<UpdateStatus>
// the biggest thing in the response.
const log = await readLog();
const base: UpdateStatus = {
- supported: false,
- reason: null,
- current: "unknown",
- currentSubject: "",
- buildSha,
- pendingBuild: false,
- ahead: 0,
- behind: 0,
- commits: [],
- dirty: false,
- running: false,
- remoteChecked: false,
- log,
+ supported: false, reason: null, current: "unknown", currentSubject: "", buildSha,
+ pendingBuild: false, ahead: 0, behind: 0, commits: [], dirty: false,
+ running: false, remoteChecked: false, log,
};
const inside = await git(["rev-parse", "--is-inside-work-tree"]);
@@ -294,17 +293,23 @@ export async function startUpdate(rebuildOnly = false): Promise<UpdateStatus> {
const blocked = blockingReason(status, rebuildOnly);
if (blocked) throw new HostError(blocked);
- const script = path.join(repoRoot(), "scripts", "mso-service-update");
- if (!(await fs.stat(script).catch(() => null))) throw new HostError(`missing ${script}`);
-
- const started = await run(
- "systemd-run",
- updateUnitArgs(repoRoot(), updateLogPath(), rebuildOnly),
- 30_000,
- );
+ const userManager = await run("systemctl", ["--user", "show-environment"], 10_000);
+ let started: Ran;
+ if (userManager.code === 0) {
+ const script = path.join(repoRoot(), "scripts", "mso-service-update");
+ if (!(await fs.stat(script).catch(() => null))) throw new HostError(`missing ${script}`);
+ started = await run("systemd-run", updateUnitArgs(repoRoot(), updateLogPath(), rebuildOnly), 30_000);
+ } else {
+ const script = path.join(repoRoot(), "scripts", "mso-offline-update-job");
+ if (!(await fs.stat(script).catch(() => null))) throw new HostError(`missing ${script}`);
+ // The wrapper writes its PID before doing any mutation and redirects stdout/
+ // stderr to the same log the panel already polls. setsid receives only a
+ // compile-time script path and the one allowed boolean flag.
+ started = await run("setsid", offlineUpdateArgs(repoRoot(), rebuildOnly), 30_000);
+ }
if (started.code !== 0) {
throw new HostError(
- `could not start the updater: ${(started.stderr || started.stdout).trim().slice(0, 300) || `exit ${started.code}`}. Re-run scripts/install.sh once if the user systemd manager is unavailable`,
+ `could not start the updater: ${(started.stderr || started.stdout).trim().slice(0, 300) || `exit ${started.code}`}`,
);
}
return { ...status, running: true };
diff --git a/lib/security/managed-app-supply-chain.test.ts b/lib/security/managed-app-supply-chain.test.ts
index 997d6306..9f8a16e0 100644
--- a/lib/security/managed-app-supply-chain.test.ts
+++ b/lib/security/managed-app-supply-chain.test.ts
@@ -31,11 +31,16 @@ describe("managed-app immutable artifact contract", () => {
expect(executable).not.toMatch(/curl[^\n]+\|\s*(?:ba)?sh/);
});
- it("pins the Hermes Docker fallback and never uses a mutable image tag", () => {
+ it("pins the Hermes Docker fallback, preserves VPS workspace access, and bounds VFS storage", () => {
const script = source(INSTALL);
- expect(script).toContain('"$HERMES_IMAGE_REF" gateway run');
+ expect(script).toContain('"$HERMES_RUNTIME_IMAGE" gateway run');
expect(script).toContain("HERMES_DASHBOARD_HOST=127.0.0.1");
expect(script).toContain("--restart unless-stopped");
+ expect(script).toContain('-v "$HOME:$HOME"');
+ expect(script).toContain('config set terminal.cwd "$HOME"');
+ expect(script).toContain("io.mso.source-image=$HERMES_IMAGE_REF");
+ expect(script).toContain("flattening Hermes for Docker VFS storage");
+ expect(script).toContain('exec "${runner[@]}" "${args[@]}" hermes /opt/hermes/hermes "$@"');
expect(script).not.toContain("nousresearch/hermes-agent:latest");
});
diff --git a/scripts/managed-app-install b/scripts/managed-app-install
index 4ad49db3..e518a1f4 100755
--- a/scripts/managed-app-install
+++ b/scripts/managed-app-install
@@ -171,42 +171,139 @@ persist_hermes_provider_key() {
mv "$tmp" "$env_file"
}
+hermes_flat_image_ref() {
+ printf 'mso/hermes-agent:%s-vfs-flat' "${HERMES_INSTALLER_TAG#v}"
+}
+
+prepare_hermes_runtime_image() {
+ HERMES_RUNTIME_IMAGE="$HERMES_IMAGE_REF"
+
+ local driver flat source_label tmp
+ driver="$("${DOCKER[@]}" info --format '{{.Driver}}' 2>/dev/null || true)"
+ flat="$(hermes_flat_image_ref)"
+ if [ "$driver" = "vfs" ]; then
+ # Reuse an already-derived image BEFORE pulling upstream again. On VFS, merely
+ # pulling the multi-layer source can consume tens of GB because each layer is
+ # a full snapshot. The source label binds this local representation to the
+ # exact reviewed digest in managed-app-artifacts.env.
+ source_label="$("${DOCKER[@]}" image inspect --format '{{index .Config.Labels "io.mso.source-image"}}' "$flat" 2>/dev/null || true)"
+ if [ "$source_label" = "$HERMES_IMAGE_REF" ]; then
+ HERMES_RUNTIME_IMAGE="$flat"
+ log "reusing flattened Hermes image for Docker VFS storage"
+ return 0
+ fi
+ fi
+
+ log "pulling pinned Hermes image ($HERMES_INSTALLER_TAG)"
+ "${DOCKER[@]}" pull "$HERMES_IMAGE_REF"
+ [ "$driver" = "vfs" ] || return 0
+
+ # Docker's VFS driver deep-copies every cumulative image layer. The upstream
+ # Hermes image has many layers, so its ~2.7 GB logical rootfs can consume tens
+ # of GB physically. Flatten ONLY the already-reviewed pinned source image into
+ # one local layer; the source digest remains recorded as a label and is checked
+ # before reuse. This is a storage representation change, not a different build.
+ source_label="$("${DOCKER[@]}" image inspect --format '{{index .Config.Labels "io.mso.source-image"}}' "$flat" 2>/dev/null || true)"
+ if [ "$source_label" != "$HERMES_IMAGE_REF" ]; then
+ tmp="mso-hermes-flatten-$$"
+ "${DOCKER[@]}" rm -f "$tmp" >/dev/null 2>&1 || true
+ "${DOCKER[@]}" create --name "$tmp" "$HERMES_IMAGE_REF" >/dev/null
+ log "flattening Hermes for Docker VFS storage"
+ if ! "${DOCKER[@]}" export "$tmp" | "${DOCKER[@]}" import \
+ --change 'ENV PATH=/opt/hermes/bin:/opt/hermes/.venv/bin:/opt/data/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' \
+ --change 'ENV PYTHONUNBUFFERED=1' \
+ --change 'ENV PYTHONDONTWRITEBYTECODE=1' \
+ --change 'ENV PLAYWRIGHT_BROWSERS_PATH=/opt/hermes/.playwright' \
+ --change 'ENV npm_config_install_links=false' \
+ --change 'ENV HERMES_WEB_DIST=/opt/hermes/hermes_cli/web_dist' \
+ --change 'ENV HERMES_TUI_DIR=/opt/hermes/ui-tui' \
+ --change 'ENV HERMES_HOME=/opt/data' \
+ --change 'ENV HERMES_WRITE_SAFE_ROOT=/opt/data' \
+ --change 'ENV HERMES_DISABLE_LAZY_INSTALLS=1' \
+ --change 'ENV HERMES_LAZY_INSTALL_TARGET=/opt/data/lazy-packages' \
+ --change 'WORKDIR /opt/hermes' \
+ --change 'VOLUME ["/opt/data"]' \
+ --change 'ENTRYPOINT ["/opt/hermes/docker/entrypoint-dispatch.sh"]' \
+ --change "LABEL org.opencontainers.image.revision=$HERMES_INSTALLER_COMMIT" \
+ --change "LABEL io.mso.source-image=$HERMES_IMAGE_REF" \
+ - "$flat" >/dev/null; then
+ "${DOCKER[@]}" rm -f "$tmp" >/dev/null 2>&1 || true
+ return 1
+ fi
+ "${DOCKER[@]}" rm -f "$tmp" >/dev/null 2>&1 || true
+ fi
+ HERMES_RUNTIME_IMAGE="$flat"
+}
+
+install_hermes_cli_wrapper() {
+ local wrapper="$HOME/.local/bin/hermes"
+ mkdir -p "$(dirname "$wrapper")"
+ cat >"$wrapper" <<'WRAPPER'
+#!/usr/bin/env bash
+set -euo pipefail
+cwd="$PWD"
+case "$cwd" in
+ "$HOME"|"$HOME"/*) ;;
+ *) cwd="$HOME" ;;
+esac
+runner=(docker)
+if ! docker version --format '{{.Server.Version}}' >/dev/null 2>&1; then runner=(sudo -n docker); fi
+args=(exec --user "$(id -u):$(id -g)" -w "$cwd")
+if [ -t 0 ] && [ -t 1 ]; then args+=(-it); else args+=(-i); fi
+exec "${runner[@]}" "${args[@]}" hermes /opt/hermes/hermes "$@"
+WRAPPER
+ chmod 755 "$wrapper"
+}
+
install_hermes_docker() {
docker_cli || { echo "Docker is unavailable to $(id -un)" >&2; return 1; }
mkdir -p "$HOME/.hermes"
+ persist_hermes_provider_key
+ prepare_hermes_runtime_image
+
+ log "configuring Hermes in the persistent data volume"
+ "${DOCKER[@]}" run --rm --network host \
+ -v "$HOME/.hermes:/opt/data" \
+ -v "$HOME:$HOME" \
+ -e "HERMES_UID=$(id -u)" -e "HERMES_GID=$(id -g)" \
+ "$HERMES_RUNTIME_IMAGE" setup --non-interactive
+ "${DOCKER[@]}" run --rm \
+ -v "$HOME/.hermes:/opt/data" -v "$HOME:$HOME" \
+ -e "HERMES_UID=$(id -u)" -e "HERMES_GID=$(id -g)" \
+ "$HERMES_RUNTIME_IMAGE" config set terminal.cwd "$HOME" >/dev/null
+ install_hermes_cli_wrapper
if "${DOCKER[@]}" container inspect hermes >/dev/null 2>&1; then
- local configured_image
+ local source_label configured_image
configured_image="$("${DOCKER[@]}" inspect --format '{{.Config.Image}}' hermes 2>/dev/null || true)"
- if [ "$configured_image" != "$HERMES_IMAGE_REF" ]; then
- echo "a container named 'hermes' already exists with a different image; refusing to replace it" >&2
+ source_label="$("${DOCKER[@]}" inspect --format '{{index .Config.Labels "io.mso.source-image"}}' hermes 2>/dev/null || true)"
+ if [ "$configured_image" != "$HERMES_IMAGE_REF" ] && [ "$configured_image" != "$HERMES_RUNTIME_IMAGE" ] && [ "$source_label" != "$HERMES_IMAGE_REF" ]; then
+ echo "a container named 'hermes' already exists with an unrelated image; refusing to replace it" >&2
return 1
fi
- log "Hermes container already exists; starting the reviewed image"
- "${DOCKER[@]}" start hermes >/dev/null
- else
- log "pulling pinned Hermes image ($HERMES_INSTALLER_TAG)"
- "${DOCKER[@]}" pull "$HERMES_IMAGE_REF"
-
- persist_hermes_provider_key
-
- log "configuring Hermes in the persistent data volume"
- "${DOCKER[@]}" run --rm --network host \
- -v "$HOME/.hermes:/opt/data" \
- -e "HERMES_UID=$(id -u)" -e "HERMES_GID=$(id -g)" \
- "$HERMES_IMAGE_REF" setup --non-interactive
-
- log "starting Hermes gateway + dashboard on loopback"
- "${DOCKER[@]}" run -d \
- --name hermes \
- --restart unless-stopped \
- --network host \
- -v "$HOME/.hermes:/opt/data" \
- -e "HERMES_UID=$(id -u)" \
- -e "HERMES_GID=$(id -g)" \
- -e HERMES_DASHBOARD=1 \
- -e HERMES_DASHBOARD_HOST=127.0.0.1 \
- "$HERMES_IMAGE_REF" gateway run >/dev/null
+ log "reconciling existing Hermes container"
+ "${DOCKER[@]}" rm -f hermes >/dev/null
+ fi
+
+ log "starting Hermes gateway + dashboard on loopback"
+ "${DOCKER[@]}" run -d \
+ --name hermes \
+ --restart unless-stopped \
+ --network host \
+ --label "io.mso.source-image=$HERMES_IMAGE_REF" \
+ -v "$HOME/.hermes:/opt/data" \
+ -v "$HOME:$HOME" \
+ -e "HERMES_UID=$(id -u)" \
+ -e "HERMES_GID=$(id -g)" \
+ -e HERMES_DASHBOARD=1 \
+ -e HERMES_DASHBOARD_HOST=127.0.0.1 \
+ "$HERMES_RUNTIME_IMAGE" gateway run >/dev/null
+
+ # The flattened VFS image supersedes the multi-layer source locally. Removing
+ # the reviewed source image after the container is on the derived image frees
+ # the duplicated VFS layer trees; a future update pulls the pinned source again.
+ if [ "$HERMES_RUNTIME_IMAGE" != "$HERMES_IMAGE_REF" ]; then
+ "${DOCKER[@]}" image rm "$HERMES_IMAGE_REF" >/dev/null 2>&1 || true
fi
local i running
diff --git a/scripts/mso-offline-update-job b/scripts/mso-offline-update-job
new file mode 100755
index 00000000..5306a2c5
--- /dev/null
+++ b/scripts/mso-offline-update-job
@@ -0,0 +1,29 @@
+#!/usr/bin/env bash
+# Detached update owner for hosts with no systemd user manager (containers, hosted
+# workspaces, etc.). The web API launches this through `setsid -f`; this process
+# must therefore own its PID marker and log before it asks mso-update to quiesce
+# the currently serving Next runtime.
+set -euo pipefail
+umask 077
+
+ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
+LOG="${MSO_UPDATE_LOG:-$HOME/.mso/self-update.log}"
+PID_FILE="${MSO_UPDATE_PID_FILE:-$HOME/.mso/self-update.pid}"
+mkdir -p "$(dirname "$LOG")" "$(dirname "$PID_FILE")"
+printf '%s\n' "$$" >"$PID_FILE"
+cleanup() { rm -f "$PID_FILE"; }
+trap cleanup EXIT HUP INT TERM
+
+# Close the pipe inherited from Node/setsid immediately. This is what lets the
+# API request return while the detached process continues through a rebuild.
+: >"$LOG"
+exec >>"$LOG" 2>&1
+printf '[%s] == detached offline update\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
+
+case "${1:-}" in
+ "") /bin/bash "$ROOT/scripts/mso-update" ;;
+ --rebuild-only) /bin/bash "$ROOT/scripts/mso-update" --rebuild ;;
+ *) echo "usage: mso-offline-update-job [--rebuild-only]" >&2; exit 2 ;;
+esac
+
+printf 'UPDATE OK\n'