Skip to content

Commit 0db2a0a

Browse files
committed
fix(status): probe system-level systemd unit when user-level unavailable
When the gateway runs under a system-level systemd unit (not user-level), systemctl --user is unavailable and the status check reports "systemd user services unavailable" as a false positive. Instead of relying on INVOCATION_ID detection, directly probe system-level systemctl when user-level fails. If the unit exists and responds at system level, return the actual status. Fixes #85094
1 parent 221f534 commit 0db2a0a

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

src/daemon/systemd.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,32 @@ export async function readSystemdServiceRuntime(
10801080
try {
10811081
await assertSystemdAvailable(env);
10821082
} catch (err) {
1083+
// When running under a system-level systemd unit (not user-level),
1084+
// systemctl --user is unavailable but the gateway may be healthy.
1085+
// Probe system-level systemctl directly to check the unit status.
1086+
// See: https://github.com/openclaw/openclaw/issues/85094
1087+
const serviceName = resolveSystemdServiceName(env);
1088+
const unitName = `${serviceName}.service`;
1089+
const systemRes = await execFileUtf8("systemctl", [
1090+
"show",
1091+
unitName,
1092+
"--no-page",
1093+
"--property",
1094+
"ActiveState,SubState,MainPID,ExecMainStatus,ExecMainCode",
1095+
]).catch(() => null);
1096+
if (systemRes && systemRes.exitCode === 0) {
1097+
const parsed = parseSystemdShow(systemRes.stdout || "");
1098+
const activeState = normalizeLowercaseStringOrEmpty(parsed.activeState);
1099+
const status = activeState === "active" ? "running" : activeState ? "stopped" : "unknown";
1100+
return {
1101+
status,
1102+
state: parsed.activeState,
1103+
subState: parsed.subState,
1104+
pid: parsed.mainPid,
1105+
lastExitStatus: parsed.execMainStatus,
1106+
lastExitReason: parsed.execMainCode,
1107+
};
1108+
}
10831109
return {
10841110
status: "unknown",
10851111
detail: formatErrorMessage(err),

0 commit comments

Comments
 (0)