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(systemd): stop quoting WorkingDirectory, restore install exec bit

Abdurrahman Fakhrulb70ee506daf1
diff --git a/lib/host/self-update-timer.test.ts b/lib/host/self-update-timer.test.ts
index ecb81a55..73dc369e 100644
--- a/lib/host/self-update-timer.test.ts
+++ b/lib/host/self-update-timer.test.ts
@@ -24,16 +24,21 @@ describe("nightly update timer units", () => {
expect(files.timer).toContain("Persistent=true");
expect(files.timer).toContain("Unit=mso-auto-update.service");
expect(files.service).toContain("Type=oneshot");
- expect(files.service).toContain('WorkingDirectory="/srv/mso"');
+ // WorkingDirectory is a PATH directive: systemd does not strip quotes there,
+ // so a quoted value fails with "path is not absolute" and the unit never runs.
+ expect(files.service).toContain("WorkingDirectory=/srv/mso");
+ expect(files.service).not.toContain('WorkingDirectory="');
expect(files.service).toContain('/srv/mso/scripts/mso-auto-update');
// No unit argument: the channel comes from prefs at run time, not from a file a
// client could have influenced.
expect(files.service).not.toContain("--channel");
});
- it("quotes a checkout path with spaces instead of splitting it into two argv", () => {
+ it("escapes a checkout path with spaces instead of quoting it or splitting argv", () => {
const files = unitFiles("/srv/my mso", "/tmp/a b.log");
- expect(files.service).toContain('WorkingDirectory="/srv/my mso"');
+ // \x20 is systemd's own whitespace escape for path directives, where quotes
+ // would be taken literally and the path would be rejected as non-absolute.
+ expect(files.service).toContain("WorkingDirectory=/srv/my\\x20mso");
expect(files.service).toContain('MSO_UPDATE_LOG="/tmp/a b.log"');
});
diff --git a/lib/host/self-update-timer.ts b/lib/host/self-update-timer.ts
index 6bcf9c36..cc3a8da8 100644
--- a/lib/host/self-update-timer.ts
+++ b/lib/host/self-update-timer.ts
@@ -34,6 +34,8 @@ export const unitPaths = (): { service: string; timer: string } => {
/** systemd exec arguments are space-split with quote support; a checkout path with
* a space must survive as ONE argument, so quote and escape rather than join raw. */
const exec = (value: string): string => `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
+/** Path directives take NO quotes; systemd rejects `WorkingDirectory="/x"`. */
+const pathDirective = (value: string): string => value.replace(/ /g, "\\x20");
/** Pure: unit text for a given checkout. No request value reaches this string. */
export function unitFiles(root: string, logPath: string): { service: string; timer: string } {
@@ -42,7 +44,7 @@ Description=MSO unattended self-update (the pre-flight decides whether anything
[Service]
Type=oneshot
-WorkingDirectory=${exec(root)}
+WorkingDirectory=${pathDirective(root)}
Environment=MSO_UPDATE_LOG=${exec(logPath)}
# A build on a small VPS is minutes. The transient update unit already has its own
# 1h start timeout; this is the outer bound for pre-flight + that wait.
diff --git a/scripts/managed-app-install b/scripts/managed-app-install
old mode 100644
new mode 100755
diff --git a/scripts/orca/systemd-unit.mjs b/scripts/orca/systemd-unit.mjs
index bc214e16..e368cb31 100644
--- a/scripts/orca/systemd-unit.mjs
+++ b/scripts/orca/systemd-unit.mjs
@@ -17,10 +17,10 @@ import { dirname, isAbsolute } from 'node:path'
import { DEFAULT_PORT } from './constants.mjs'
import { SERVICE_NAME, UNIT_IDENTITY_MARKER } from './managed-paths.mjs'
import { assertConfiguredAdvertisedEndpoint, assertPersistentPort } from './supervision.mjs'
-import { renderUnitText, systemdQuote } from './unit-render.mjs'
+import { renderUnitText, systemdPath, systemdQuote } from './unit-render.mjs'
import { readOwnedUnitFile } from './unit-read.mjs'
-export { systemdQuote }
+export { systemdPath, systemdQuote }
const CONTROL = /[\0\r\n]/
diff --git a/scripts/orca/systemd-unit.test.mjs b/scripts/orca/systemd-unit.test.mjs
index 51aefc7d..eea762fe 100644
--- a/scripts/orca/systemd-unit.test.mjs
+++ b/scripts/orca/systemd-unit.test.mjs
@@ -7,6 +7,7 @@ import {
inspectExistingUnit,
isManagedOrcaUnit,
renderOrcaServiceUnit,
+ systemdPath,
systemdQuote
} from './systemd-unit.mjs'
@@ -47,6 +48,22 @@ describe('Orca user unit rendering', () => {
assert.ok(unit.includes('$$HOME'))
})
+ it('renders WorkingDirectory as an unquoted path directive', () => {
+ // Regression: systemd does not strip quotes for path directives. A quoted
+ // WorkingDirectory fails unit load with "path is not absolute", so the
+ // managed runtime could never start (observed on the VPS install).
+ const unit = renderOrcaServiceUnit(BASE)
+ assert.ok(unit.includes('WorkingDirectory=/home/operator/.local/share/mso/orca'))
+ assert.ok(!unit.includes('WorkingDirectory="'))
+ })
+
+ it('escapes spaces in a path directive instead of quoting it', () => {
+ assert.equal(systemdPath('/srv/my mso'), '/srv/my\\x20mso')
+ assert.equal(systemdPath('/srv/100%'), '/srv/100%%')
+ assert.throws(() => systemdPath('relative'), /absolute/)
+ assert.throws(() => systemdPath(''), /non-empty/)
+ })
+
it('quotes a single argument as one systemd token', () => {
assert.equal(systemdQuote('plain'), '"plain"')
assert.equal(systemdQuote('a b'), '"a b"')
diff --git a/scripts/orca/unit-render.mjs b/scripts/orca/unit-render.mjs
index d48d3a14..07b6971d 100644
--- a/scripts/orca/unit-render.mjs
+++ b/scripts/orca/unit-render.mjs
@@ -22,6 +22,21 @@ export function systemdQuote(value) {
return `"${escaped}"`
}
+/**
+ * Render an absolute path for a systemd path directive (`WorkingDirectory=`).
+ * Quotes are WRONG here: systemd does not strip them for these directives, so
+ * `WorkingDirectory="/home/x"` fails with `path is not absolute` and the unit
+ * never starts. Only the specifier escape and whitespace escaping apply.
+ * @param {string} value
+ */
+export function systemdPath(value) {
+ if (typeof value !== 'string' || value.length === 0 || CONTROL.test(value)) {
+ throw new Error('unit path must be a non-empty string without control characters')
+ }
+ if (!value.startsWith('/')) throw new Error(`unit path must be absolute, got: ${value}`)
+ return value.replace(/%/g, '%%').replace(/ /g, '\\x20')
+}
+
/**
* @typedef {object} UnitRenderInput
* @property {string} marker
@@ -62,7 +77,7 @@ StartLimitBurst=3
[Service]
Type=simple
-WorkingDirectory=${systemdQuote(managedRoot)}
+WorkingDirectory=${systemdPath(managedRoot)}
ExecStart=${argv.map(systemdQuote).join(' ')}
Environment="NODE_ENV=production"
Restart=on-failure