mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 07:37:29 +00:00
fix(daemon): handle systemctl is-enabled exit code 4 (not-found) on Ubuntu (#33633)
This commit is contained in:
committed by
Shakker
parent
3fa43ec221
commit
d1ad9e2753
@@ -90,6 +90,21 @@ describe("isSystemdServiceEnabled", () => {
|
||||
"systemctl is-enabled unavailable: Failed to connect to bus",
|
||||
);
|
||||
});
|
||||
|
||||
it("returns false when systemctl is-enabled exits with code 4 (not-found)", async () => {
|
||||
const { isSystemdServiceEnabled } = await import("./systemd.js");
|
||||
execFileMock.mockImplementationOnce((_cmd, _args, _opts, cb) => {
|
||||
// On Ubuntu 24.04, `systemctl --user is-enabled <unit>` exits with
|
||||
// code 4 and prints "not-found" to stdout when the unit doesn't exist.
|
||||
const err = new Error(
|
||||
"Command failed: systemctl --user is-enabled openclaw-gateway.service",
|
||||
) as Error & { code?: number };
|
||||
err.code = 4;
|
||||
cb(err, "not-found\n", "");
|
||||
});
|
||||
const result = await isSystemdServiceEnabled({ env: {} });
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("systemd runtime parsing", () => {
|
||||
|
||||
@@ -143,7 +143,10 @@ async function execSystemctl(
|
||||
}
|
||||
|
||||
function readSystemctlDetail(result: { stdout: string; stderr: string }): string {
|
||||
return (result.stderr || result.stdout || "").trim();
|
||||
// Concatenate both streams so pattern matchers (isSystemdUnitNotEnabled,
|
||||
// isSystemctlMissing) can see the unit status from stdout even when
|
||||
// execFileUtf8 populates stderr with the Node error message fallback.
|
||||
return `${result.stderr} ${result.stdout}`.trim();
|
||||
}
|
||||
|
||||
function isSystemctlMissing(detail: string): boolean {
|
||||
|
||||
Reference in New Issue
Block a user