mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
Daemon: scope relaxed systemd probes to install flows
This commit is contained in:
@@ -256,4 +256,27 @@ describe("runDaemonInstall", () => {
|
|||||||
expect(installDaemonServiceAndEmitMock).toHaveBeenCalledTimes(1);
|
expect(installDaemonServiceAndEmitMock).toHaveBeenCalledTimes(1);
|
||||||
expect(actionState.warnings.some((warning) => warning.includes("Auto-generated"))).toBe(true);
|
expect(actionState.warnings.some((warning) => warning.includes("Auto-generated"))).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("continues Linux install when service probe hits a non-fatal systemd bus failure", async () => {
|
||||||
|
service.isLoaded.mockRejectedValueOnce(
|
||||||
|
new Error("systemctl is-enabled unavailable: Failed to connect to bus"),
|
||||||
|
);
|
||||||
|
|
||||||
|
await runDaemonInstall({ json: true });
|
||||||
|
|
||||||
|
expect(actionState.failed).toEqual([]);
|
||||||
|
expect(installDaemonServiceAndEmitMock).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("fails install when service probe reports an unrelated error", async () => {
|
||||||
|
service.isLoaded.mockRejectedValueOnce(
|
||||||
|
new Error("systemctl is-enabled unavailable: read-only file system"),
|
||||||
|
);
|
||||||
|
|
||||||
|
await runDaemonInstall({ json: true });
|
||||||
|
|
||||||
|
expect(actionState.failed[0]?.message).toContain("Gateway service check failed");
|
||||||
|
expect(actionState.failed[0]?.message).toContain("read-only file system");
|
||||||
|
expect(installDaemonServiceAndEmitMock).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { resolveGatewayInstallToken } from "../../commands/gateway-install-token
|
|||||||
import { loadConfig, resolveGatewayPort } from "../../config/config.js";
|
import { loadConfig, resolveGatewayPort } from "../../config/config.js";
|
||||||
import { resolveIsNixMode } from "../../config/paths.js";
|
import { resolveIsNixMode } from "../../config/paths.js";
|
||||||
import { resolveGatewayService } from "../../daemon/service.js";
|
import { resolveGatewayService } from "../../daemon/service.js";
|
||||||
|
import { isNonFatalSystemdInstallProbeError } from "../../daemon/systemd.js";
|
||||||
import { defaultRuntime } from "../../runtime.js";
|
import { defaultRuntime } from "../../runtime.js";
|
||||||
import { formatCliCommand } from "../command-format.js";
|
import { formatCliCommand } from "../command-format.js";
|
||||||
import {
|
import {
|
||||||
@@ -48,8 +49,12 @@ export async function runDaemonInstall(opts: DaemonInstallOptions) {
|
|||||||
try {
|
try {
|
||||||
loaded = await service.isLoaded({ env: process.env });
|
loaded = await service.isLoaded({ env: process.env });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
fail(`Gateway service check failed: ${String(err)}`);
|
if (isNonFatalSystemdInstallProbeError(err)) {
|
||||||
return;
|
loaded = false;
|
||||||
|
} else {
|
||||||
|
fail(`Gateway service check failed: ${String(err)}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (loaded) {
|
if (loaded) {
|
||||||
if (!opts.force) {
|
if (!opts.force) {
|
||||||
|
|||||||
@@ -123,6 +123,21 @@ describe("maybeInstallDaemon", () => {
|
|||||||
expect(serviceInstall).toHaveBeenCalledTimes(1);
|
expect(serviceInstall).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("rethrows install probe failures that are not the known non-fatal Linux systemd cases", async () => {
|
||||||
|
serviceIsLoaded.mockRejectedValueOnce(
|
||||||
|
new Error("systemctl is-enabled unavailable: read-only file system"),
|
||||||
|
);
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
maybeInstallDaemon({
|
||||||
|
runtime: { log: vi.fn(), error: vi.fn(), exit: vi.fn() },
|
||||||
|
port: 18789,
|
||||||
|
}),
|
||||||
|
).rejects.toThrow("systemctl is-enabled unavailable: read-only file system");
|
||||||
|
|
||||||
|
expect(serviceInstall).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it("continues the WSL2 daemon install flow when service status probe reports systemd unavailability", async () => {
|
it("continues the WSL2 daemon install flow when service status probe reports systemd unavailability", async () => {
|
||||||
serviceIsLoaded.mockRejectedValueOnce(
|
serviceIsLoaded.mockRejectedValueOnce(
|
||||||
new Error("systemctl --user unavailable: Failed to connect to bus: No medium found"),
|
new Error("systemctl --user unavailable: Failed to connect to bus: No medium found"),
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { withProgress } from "../cli/progress.js";
|
import { withProgress } from "../cli/progress.js";
|
||||||
import { loadConfig } from "../config/config.js";
|
import { loadConfig } from "../config/config.js";
|
||||||
import { resolveGatewayService } from "../daemon/service.js";
|
import { resolveGatewayService } from "../daemon/service.js";
|
||||||
|
import { isNonFatalSystemdInstallProbeError } from "../daemon/systemd.js";
|
||||||
import type { RuntimeEnv } from "../runtime.js";
|
import type { RuntimeEnv } from "../runtime.js";
|
||||||
import { note } from "../terminal/note.js";
|
import { note } from "../terminal/note.js";
|
||||||
import { confirm, select } from "./configure.shared.js";
|
import { confirm, select } from "./configure.shared.js";
|
||||||
@@ -23,7 +24,10 @@ export async function maybeInstallDaemon(params: {
|
|||||||
let loaded = false;
|
let loaded = false;
|
||||||
try {
|
try {
|
||||||
loaded = await service.isLoaded({ env: process.env });
|
loaded = await service.isLoaded({ env: process.env });
|
||||||
} catch {
|
} catch (error) {
|
||||||
|
if (!isNonFatalSystemdInstallProbeError(error)) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
loaded = false;
|
loaded = false;
|
||||||
}
|
}
|
||||||
let shouldCheckLinger = false;
|
let shouldCheckLinger = false;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ vi.mock("node:child_process", () => ({
|
|||||||
import { splitArgsPreservingQuotes } from "./arg-split.js";
|
import { splitArgsPreservingQuotes } from "./arg-split.js";
|
||||||
import { parseSystemdExecStart } from "./systemd-unit.js";
|
import { parseSystemdExecStart } from "./systemd-unit.js";
|
||||||
import {
|
import {
|
||||||
|
isNonFatalSystemdInstallProbeError,
|
||||||
isSystemdUserServiceAvailable,
|
isSystemdUserServiceAvailable,
|
||||||
parseSystemdShow,
|
parseSystemdShow,
|
||||||
restartSystemdService,
|
restartSystemdService,
|
||||||
@@ -163,8 +164,11 @@ describe("isSystemdServiceEnabled", () => {
|
|||||||
cb(err, "", "");
|
cb(err, "", "");
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await isSystemdServiceEnabled({ env: { HOME: "/tmp/openclaw-test-home" } });
|
await expect(
|
||||||
expect(result).toBe(false);
|
isSystemdServiceEnabled({ env: { HOME: "/tmp/openclaw-test-home" } }),
|
||||||
|
).rejects.toThrow(
|
||||||
|
"systemctl is-enabled unavailable: Command failed: systemctl --user is-enabled openclaw-gateway.service",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns false when is-enabled cannot connect to the user bus without machine fallback", async () => {
|
it("returns false when is-enabled cannot connect to the user bus without machine fallback", async () => {
|
||||||
@@ -182,10 +186,11 @@ describe("isSystemdServiceEnabled", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await isSystemdServiceEnabled({
|
await expect(
|
||||||
env: { HOME: "/tmp/openclaw-test-home", USER: "", LOGNAME: "" },
|
isSystemdServiceEnabled({
|
||||||
});
|
env: { HOME: "/tmp/openclaw-test-home", USER: "", LOGNAME: "" },
|
||||||
expect(result).toBe(false);
|
}),
|
||||||
|
).rejects.toThrow("systemctl is-enabled unavailable: Failed to connect to bus");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns false when both direct and machine-scope is-enabled checks report bus unavailability", async () => {
|
it("returns false when both direct and machine-scope is-enabled checks report bus unavailability", async () => {
|
||||||
@@ -218,10 +223,11 @@ describe("isSystemdServiceEnabled", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await isSystemdServiceEnabled({
|
await expect(
|
||||||
env: { HOME: "/tmp/openclaw-test-home", USER: "debian" },
|
isSystemdServiceEnabled({
|
||||||
});
|
env: { HOME: "/tmp/openclaw-test-home", USER: "debian" },
|
||||||
expect(result).toBe(false);
|
}),
|
||||||
|
).rejects.toThrow("systemctl is-enabled unavailable: Failed to connect to user scope bus");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("throws when generic wrapper errors report infrastructure failures", async () => {
|
it("throws when generic wrapper errors report infrastructure failures", async () => {
|
||||||
@@ -281,6 +287,32 @@ describe("isSystemdServiceEnabled", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("isNonFatalSystemdInstallProbeError", () => {
|
||||||
|
it("matches wrapper-only WSL install probe failures", () => {
|
||||||
|
expect(
|
||||||
|
isNonFatalSystemdInstallProbeError(
|
||||||
|
new Error("Command failed: systemctl --user is-enabled openclaw-gateway.service"),
|
||||||
|
),
|
||||||
|
).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("matches bus-unavailable install probe failures", () => {
|
||||||
|
expect(
|
||||||
|
isNonFatalSystemdInstallProbeError(
|
||||||
|
new Error("systemctl is-enabled unavailable: Failed to connect to bus"),
|
||||||
|
),
|
||||||
|
).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not match real infrastructure failures", () => {
|
||||||
|
expect(
|
||||||
|
isNonFatalSystemdInstallProbeError(
|
||||||
|
new Error("systemctl is-enabled unavailable: read-only file system"),
|
||||||
|
),
|
||||||
|
).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("systemd runtime parsing", () => {
|
describe("systemd runtime parsing", () => {
|
||||||
it("parses active state details", () => {
|
it("parses active state details", () => {
|
||||||
const output = [
|
const output = [
|
||||||
|
|||||||
@@ -210,6 +210,15 @@ function isGenericSystemctlIsEnabledFailure(detail: string): boolean {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isNonFatalSystemdInstallProbeError(error: unknown): boolean {
|
||||||
|
const detail = error instanceof Error ? error.message : typeof error === "string" ? error : "";
|
||||||
|
if (!detail) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const normalized = detail.toLowerCase();
|
||||||
|
return isSystemctlBusUnavailable(normalized) || isGenericSystemctlIsEnabledFailure(normalized);
|
||||||
|
}
|
||||||
|
|
||||||
function resolveSystemctlDirectUserScopeArgs(): string[] {
|
function resolveSystemctlDirectUserScopeArgs(): string[] {
|
||||||
return ["--user"];
|
return ["--user"];
|
||||||
}
|
}
|
||||||
@@ -470,12 +479,7 @@ export async function isSystemdServiceEnabled(args: GatewayServiceEnvArgs): Prom
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const detail = readSystemctlDetail(res);
|
const detail = readSystemctlDetail(res);
|
||||||
if (
|
if (isSystemctlMissing(detail) || isSystemdUnitNotEnabled(detail)) {
|
||||||
isSystemctlMissing(detail) ||
|
|
||||||
isSystemdUnitNotEnabled(detail) ||
|
|
||||||
isSystemctlBusUnavailable(detail) ||
|
|
||||||
isGenericSystemctlIsEnabledFailure(detail)
|
|
||||||
) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
throw new Error(`systemctl is-enabled unavailable: ${detail || "unknown error"}`.trim());
|
throw new Error(`systemctl is-enabled unavailable: ${detail || "unknown error"}`.trim());
|
||||||
|
|||||||
Reference in New Issue
Block a user