Files
clawdbot/src/infra/restart.ts
2026-01-01 16:54:46 +00:00

37 lines
1.2 KiB
TypeScript

import { spawnSync } from "node:child_process";
const DEFAULT_LAUNCHD_LABEL = "com.steipete.clawdis";
const DEFAULT_SYSTEMD_UNIT = "clawdis-gateway.service";
export function triggerClawdisRestart():
| "launchctl"
| "systemd"
| "supervisor" {
if (process.platform !== "darwin") {
if (process.platform === "linux") {
const unit = process.env.CLAWDIS_SYSTEMD_UNIT || DEFAULT_SYSTEMD_UNIT;
const userRestart = spawnSync("systemctl", ["--user", "restart", unit], {
stdio: "ignore",
});
if (!userRestart.error && userRestart.status === 0) {
return "systemd";
}
const systemRestart = spawnSync("systemctl", ["restart", unit], {
stdio: "ignore",
});
if (!systemRestart.error && systemRestart.status === 0) {
return "systemd";
}
return "systemd";
}
return "supervisor";
}
const label = process.env.CLAWDIS_LAUNCHD_LABEL || DEFAULT_LAUNCHD_LABEL;
const uid =
typeof process.getuid === "function" ? process.getuid() : undefined;
const target = uid !== undefined ? `gui/${uid}/${label}` : label;
spawnSync("launchctl", ["kickstart", "-k", target], { stdio: "ignore" });
return "launchctl";
}