2026-02-21 18:02:05 +01:00
|
|
|
|
import type { Writable } from "node:stream";
|
2026-03-05 18:17:58 +08:00
|
|
|
|
import { readBestEffortConfig, readConfigFileSnapshot } from "../../config/config.js";
|
|
|
|
|
|
import { formatConfigIssueLines } from "../../config/issue-format.js";
|
2026-02-14 14:00:34 +00:00
|
|
|
|
import { resolveIsNixMode } from "../../config/paths.js";
|
2026-02-16 14:03:28 +01:00
|
|
|
|
import { checkTokenDrift } from "../../daemon/service-audit.js";
|
2026-02-18 01:34:35 +00:00
|
|
|
|
import type { GatewayService } from "../../daemon/service.js";
|
2026-02-14 14:00:34 +00:00
|
|
|
|
import { renderSystemdUnavailableHints } from "../../daemon/systemd-hints.js";
|
|
|
|
|
|
import { isSystemdUserServiceAvailable } from "../../daemon/systemd.js";
|
2026-03-07 17:59:30 -08:00
|
|
|
|
import { isGatewaySecretRefUnavailableError } from "../../gateway/credentials.js";
|
2026-02-14 14:00:34 +00:00
|
|
|
|
import { isWSL } from "../../infra/wsl.js";
|
|
|
|
|
|
import { defaultRuntime } from "../../runtime.js";
|
2026-03-08 00:27:41 +00:00
|
|
|
|
import { resolveGatewayTokenForDriftCheck } from "./gateway-token-drift.js";
|
2026-02-14 14:00:34 +00:00
|
|
|
|
import {
|
|
|
|
|
|
buildDaemonServiceSnapshot,
|
|
|
|
|
|
createNullWriter,
|
|
|
|
|
|
type DaemonAction,
|
2026-02-19 14:03:47 +00:00
|
|
|
|
type DaemonActionResponse,
|
2026-02-14 14:00:34 +00:00
|
|
|
|
emitDaemonActionJson,
|
|
|
|
|
|
} from "./response.js";
|
|
|
|
|
|
|
|
|
|
|
|
type DaemonLifecycleOptions = {
|
|
|
|
|
|
json?: boolean;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-02-21 18:02:05 +01:00
|
|
|
|
type RestartPostCheckContext = {
|
|
|
|
|
|
json: boolean;
|
|
|
|
|
|
stdout: Writable;
|
|
|
|
|
|
warnings: string[];
|
|
|
|
|
|
fail: (message: string, hints?: string[]) => void;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-03-07 21:20:29 -05:00
|
|
|
|
type NotLoadedActionResult = {
|
|
|
|
|
|
result: "stopped" | "restarted";
|
|
|
|
|
|
message?: string;
|
|
|
|
|
|
warnings?: string[];
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
type NotLoadedActionContext = {
|
|
|
|
|
|
json: boolean;
|
|
|
|
|
|
stdout: Writable;
|
|
|
|
|
|
fail: (message: string, hints?: string[]) => void;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-02-14 14:00:34 +00:00
|
|
|
|
async function maybeAugmentSystemdHints(hints: string[]): Promise<string[]> {
|
|
|
|
|
|
if (process.platform !== "linux") {
|
|
|
|
|
|
return hints;
|
|
|
|
|
|
}
|
|
|
|
|
|
const systemdAvailable = await isSystemdUserServiceAvailable().catch(() => false);
|
|
|
|
|
|
if (systemdAvailable) {
|
|
|
|
|
|
return hints;
|
|
|
|
|
|
}
|
|
|
|
|
|
return [...hints, ...renderSystemdUnavailableHints({ wsl: await isWSL() })];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function createActionIO(params: { action: DaemonAction; json: boolean }) {
|
|
|
|
|
|
const stdout = params.json ? createNullWriter() : process.stdout;
|
2026-02-19 14:03:47 +00:00
|
|
|
|
const emit = (payload: Omit<DaemonActionResponse, "action">) => {
|
2026-02-14 14:00:34 +00:00
|
|
|
|
if (!params.json) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
emitDaemonActionJson({ action: params.action, ...payload });
|
|
|
|
|
|
};
|
|
|
|
|
|
const fail = (message: string, hints?: string[]) => {
|
|
|
|
|
|
if (params.json) {
|
|
|
|
|
|
emit({ ok: false, error: message, hints });
|
|
|
|
|
|
} else {
|
|
|
|
|
|
defaultRuntime.error(message);
|
|
|
|
|
|
}
|
|
|
|
|
|
defaultRuntime.exit(1);
|
|
|
|
|
|
};
|
|
|
|
|
|
return { stdout, emit, fail };
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-15 12:57:47 +00:00
|
|
|
|
async function handleServiceNotLoaded(params: {
|
|
|
|
|
|
serviceNoun: string;
|
|
|
|
|
|
service: GatewayService;
|
|
|
|
|
|
loaded: boolean;
|
|
|
|
|
|
renderStartHints: () => string[];
|
|
|
|
|
|
json: boolean;
|
|
|
|
|
|
emit: ReturnType<typeof createActionIO>["emit"];
|
|
|
|
|
|
}) {
|
|
|
|
|
|
const hints = await maybeAugmentSystemdHints(params.renderStartHints());
|
|
|
|
|
|
params.emit({
|
|
|
|
|
|
ok: true,
|
|
|
|
|
|
result: "not-loaded",
|
|
|
|
|
|
message: `${params.serviceNoun} service ${params.service.notLoadedText}.`,
|
|
|
|
|
|
hints,
|
|
|
|
|
|
service: buildDaemonServiceSnapshot(params.service, params.loaded),
|
|
|
|
|
|
});
|
|
|
|
|
|
if (!params.json) {
|
|
|
|
|
|
defaultRuntime.log(`${params.serviceNoun} service ${params.service.notLoadedText}.`);
|
|
|
|
|
|
for (const hint of hints) {
|
|
|
|
|
|
defaultRuntime.log(`Start with: ${hint}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-18 22:40:09 +00:00
|
|
|
|
async function resolveServiceLoadedOrFail(params: {
|
|
|
|
|
|
serviceNoun: string;
|
|
|
|
|
|
service: GatewayService;
|
|
|
|
|
|
fail: ReturnType<typeof createActionIO>["fail"];
|
|
|
|
|
|
}): Promise<boolean | null> {
|
|
|
|
|
|
try {
|
|
|
|
|
|
return await params.service.isLoaded({ env: process.env });
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
params.fail(`${params.serviceNoun} service check failed: ${String(err)}`);
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-05 18:17:58 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* Best-effort config validation. Returns a string describing the issues if
|
|
|
|
|
|
* config exists and is invalid, or null if config is valid/missing/unreadable.
|
2026-03-08 00:02:49 +08:00
|
|
|
|
*
|
|
|
|
|
|
* Note: This reads the config file snapshot in the current CLI environment.
|
|
|
|
|
|
* Configs using env vars only available in the service context (launchd/systemd)
|
|
|
|
|
|
* may produce false positives, but the check is intentionally best-effort —
|
|
|
|
|
|
* a false positive here is safer than a crash on startup. (#35862)
|
2026-03-05 18:17:58 +08:00
|
|
|
|
*/
|
|
|
|
|
|
async function getConfigValidationError(): Promise<string | null> {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const snapshot = await readConfigFileSnapshot();
|
|
|
|
|
|
if (!snapshot.exists || snapshot.valid) {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
return snapshot.issues.length > 0
|
|
|
|
|
|
? formatConfigIssueLines(snapshot.issues, "", { normalizeRoot: true }).join("\n")
|
|
|
|
|
|
: "Unknown validation issue.";
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-14 14:00:34 +00:00
|
|
|
|
export async function runServiceUninstall(params: {
|
|
|
|
|
|
serviceNoun: string;
|
|
|
|
|
|
service: GatewayService;
|
|
|
|
|
|
opts?: DaemonLifecycleOptions;
|
|
|
|
|
|
stopBeforeUninstall: boolean;
|
|
|
|
|
|
assertNotLoadedAfterUninstall: boolean;
|
|
|
|
|
|
}) {
|
|
|
|
|
|
const json = Boolean(params.opts?.json);
|
|
|
|
|
|
const { stdout, emit, fail } = createActionIO({ action: "uninstall", json });
|
|
|
|
|
|
|
|
|
|
|
|
if (resolveIsNixMode(process.env)) {
|
|
|
|
|
|
fail("Nix mode detected; service uninstall is disabled.");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let loaded = false;
|
|
|
|
|
|
try {
|
|
|
|
|
|
loaded = await params.service.isLoaded({ env: process.env });
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
loaded = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (loaded && params.stopBeforeUninstall) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
await params.service.stop({ env: process.env, stdout });
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
// Best-effort stop; final loaded check gates success when enabled.
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
|
|
|
await params.service.uninstall({ env: process.env, stdout });
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
fail(`${params.serviceNoun} uninstall failed: ${String(err)}`);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
loaded = false;
|
|
|
|
|
|
try {
|
|
|
|
|
|
loaded = await params.service.isLoaded({ env: process.env });
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
loaded = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (loaded && params.assertNotLoadedAfterUninstall) {
|
|
|
|
|
|
fail(`${params.serviceNoun} service still loaded after uninstall.`);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
emit({
|
|
|
|
|
|
ok: true,
|
|
|
|
|
|
result: "uninstalled",
|
|
|
|
|
|
service: buildDaemonServiceSnapshot(params.service, loaded),
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export async function runServiceStart(params: {
|
|
|
|
|
|
serviceNoun: string;
|
|
|
|
|
|
service: GatewayService;
|
|
|
|
|
|
renderStartHints: () => string[];
|
|
|
|
|
|
opts?: DaemonLifecycleOptions;
|
|
|
|
|
|
}) {
|
|
|
|
|
|
const json = Boolean(params.opts?.json);
|
|
|
|
|
|
const { stdout, emit, fail } = createActionIO({ action: "start", json });
|
|
|
|
|
|
|
2026-02-18 22:40:09 +00:00
|
|
|
|
const loaded = await resolveServiceLoadedOrFail({
|
|
|
|
|
|
serviceNoun: params.serviceNoun,
|
|
|
|
|
|
service: params.service,
|
|
|
|
|
|
fail,
|
|
|
|
|
|
});
|
|
|
|
|
|
if (loaded === null) {
|
2026-02-14 14:00:34 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!loaded) {
|
2026-02-15 12:57:47 +00:00
|
|
|
|
await handleServiceNotLoaded({
|
|
|
|
|
|
serviceNoun: params.serviceNoun,
|
|
|
|
|
|
service: params.service,
|
|
|
|
|
|
loaded,
|
|
|
|
|
|
renderStartHints: params.renderStartHints,
|
|
|
|
|
|
json,
|
|
|
|
|
|
emit,
|
2026-02-14 14:00:34 +00:00
|
|
|
|
});
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2026-03-05 18:17:58 +08:00
|
|
|
|
// Pre-flight config validation (#35862)
|
|
|
|
|
|
{
|
|
|
|
|
|
const configError = await getConfigValidationError();
|
|
|
|
|
|
if (configError) {
|
|
|
|
|
|
fail(
|
|
|
|
|
|
`${params.serviceNoun} aborted: config is invalid.\n${configError}\nFix the config and retry, or run "openclaw doctor" to repair.`,
|
|
|
|
|
|
);
|
2026-03-08 00:02:49 +08:00
|
|
|
|
return;
|
2026-03-05 18:17:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-14 14:00:34 +00:00
|
|
|
|
try {
|
|
|
|
|
|
await params.service.restart({ env: process.env, stdout });
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
const hints = params.renderStartHints();
|
|
|
|
|
|
fail(`${params.serviceNoun} start failed: ${String(err)}`, hints);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let started = true;
|
|
|
|
|
|
try {
|
|
|
|
|
|
started = await params.service.isLoaded({ env: process.env });
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
started = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
emit({
|
|
|
|
|
|
ok: true,
|
|
|
|
|
|
result: "started",
|
|
|
|
|
|
service: buildDaemonServiceSnapshot(params.service, started),
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export async function runServiceStop(params: {
|
|
|
|
|
|
serviceNoun: string;
|
|
|
|
|
|
service: GatewayService;
|
|
|
|
|
|
opts?: DaemonLifecycleOptions;
|
2026-03-07 21:20:29 -05:00
|
|
|
|
onNotLoaded?: (ctx: NotLoadedActionContext) => Promise<NotLoadedActionResult | null>;
|
2026-02-14 14:00:34 +00:00
|
|
|
|
}) {
|
|
|
|
|
|
const json = Boolean(params.opts?.json);
|
|
|
|
|
|
const { stdout, emit, fail } = createActionIO({ action: "stop", json });
|
|
|
|
|
|
|
2026-02-18 22:40:09 +00:00
|
|
|
|
const loaded = await resolveServiceLoadedOrFail({
|
|
|
|
|
|
serviceNoun: params.serviceNoun,
|
|
|
|
|
|
service: params.service,
|
|
|
|
|
|
fail,
|
|
|
|
|
|
});
|
|
|
|
|
|
if (loaded === null) {
|
2026-02-14 14:00:34 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!loaded) {
|
2026-03-07 21:20:29 -05:00
|
|
|
|
try {
|
|
|
|
|
|
const handled = await params.onNotLoaded?.({ json, stdout, fail });
|
|
|
|
|
|
if (handled) {
|
|
|
|
|
|
emit({
|
|
|
|
|
|
ok: true,
|
|
|
|
|
|
result: handled.result,
|
|
|
|
|
|
message: handled.message,
|
|
|
|
|
|
warnings: handled.warnings,
|
|
|
|
|
|
service: buildDaemonServiceSnapshot(params.service, false),
|
|
|
|
|
|
});
|
|
|
|
|
|
if (!json && handled.message) {
|
|
|
|
|
|
defaultRuntime.log(handled.message);
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
fail(`${params.serviceNoun} stop failed: ${String(err)}`);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2026-02-14 14:00:34 +00:00
|
|
|
|
emit({
|
|
|
|
|
|
ok: true,
|
|
|
|
|
|
result: "not-loaded",
|
|
|
|
|
|
message: `${params.serviceNoun} service ${params.service.notLoadedText}.`,
|
|
|
|
|
|
service: buildDaemonServiceSnapshot(params.service, loaded),
|
|
|
|
|
|
});
|
|
|
|
|
|
if (!json) {
|
|
|
|
|
|
defaultRuntime.log(`${params.serviceNoun} service ${params.service.notLoadedText}.`);
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
|
|
|
await params.service.stop({ env: process.env, stdout });
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
fail(`${params.serviceNoun} stop failed: ${String(err)}`);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let stopped = false;
|
|
|
|
|
|
try {
|
|
|
|
|
|
stopped = await params.service.isLoaded({ env: process.env });
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
stopped = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
emit({
|
|
|
|
|
|
ok: true,
|
|
|
|
|
|
result: "stopped",
|
|
|
|
|
|
service: buildDaemonServiceSnapshot(params.service, stopped),
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export async function runServiceRestart(params: {
|
|
|
|
|
|
serviceNoun: string;
|
|
|
|
|
|
service: GatewayService;
|
|
|
|
|
|
renderStartHints: () => string[];
|
|
|
|
|
|
opts?: DaemonLifecycleOptions;
|
2026-02-17 08:44:07 -05:00
|
|
|
|
checkTokenDrift?: boolean;
|
2026-02-21 18:02:05 +01:00
|
|
|
|
postRestartCheck?: (ctx: RestartPostCheckContext) => Promise<void>;
|
2026-03-07 21:20:29 -05:00
|
|
|
|
onNotLoaded?: (ctx: NotLoadedActionContext) => Promise<NotLoadedActionResult | null>;
|
2026-02-14 14:00:34 +00:00
|
|
|
|
}): Promise<boolean> {
|
|
|
|
|
|
const json = Boolean(params.opts?.json);
|
|
|
|
|
|
const { stdout, emit, fail } = createActionIO({ action: "restart", json });
|
2026-03-07 21:20:29 -05:00
|
|
|
|
const warnings: string[] = [];
|
|
|
|
|
|
let handledNotLoaded: NotLoadedActionResult | null = null;
|
2026-02-14 14:00:34 +00:00
|
|
|
|
|
2026-02-18 22:40:09 +00:00
|
|
|
|
const loaded = await resolveServiceLoadedOrFail({
|
|
|
|
|
|
serviceNoun: params.serviceNoun,
|
|
|
|
|
|
service: params.service,
|
|
|
|
|
|
fail,
|
|
|
|
|
|
});
|
|
|
|
|
|
if (loaded === null) {
|
2026-02-14 14:00:34 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!loaded) {
|
2026-03-07 21:20:29 -05:00
|
|
|
|
try {
|
|
|
|
|
|
handledNotLoaded = (await params.onNotLoaded?.({ json, stdout, fail })) ?? null;
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
fail(`${params.serviceNoun} restart failed: ${String(err)}`);
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!handledNotLoaded) {
|
|
|
|
|
|
await handleServiceNotLoaded({
|
|
|
|
|
|
serviceNoun: params.serviceNoun,
|
|
|
|
|
|
service: params.service,
|
|
|
|
|
|
loaded,
|
|
|
|
|
|
renderStartHints: params.renderStartHints,
|
|
|
|
|
|
json,
|
|
|
|
|
|
emit,
|
|
|
|
|
|
});
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (handledNotLoaded.warnings?.length) {
|
|
|
|
|
|
warnings.push(...handledNotLoaded.warnings);
|
|
|
|
|
|
}
|
2026-02-14 14:00:34 +00:00
|
|
|
|
}
|
2026-02-16 14:03:28 +01:00
|
|
|
|
|
2026-03-07 21:20:29 -05:00
|
|
|
|
if (loaded && params.checkTokenDrift) {
|
2026-02-17 08:44:07 -05:00
|
|
|
|
// Check for token drift before restart (service token vs config token)
|
|
|
|
|
|
try {
|
|
|
|
|
|
const command = await params.service.readCommand(process.env);
|
|
|
|
|
|
const serviceToken = command?.environment?.OPENCLAW_GATEWAY_TOKEN;
|
2026-03-07 20:48:13 -05:00
|
|
|
|
const cfg = await readBestEffortConfig();
|
2026-03-08 00:27:41 +00:00
|
|
|
|
const configToken = resolveGatewayTokenForDriftCheck({ cfg, env: process.env });
|
2026-02-17 08:44:07 -05:00
|
|
|
|
const driftIssue = checkTokenDrift({ serviceToken, configToken });
|
|
|
|
|
|
if (driftIssue) {
|
|
|
|
|
|
const warning = driftIssue.detail
|
|
|
|
|
|
? `${driftIssue.message} ${driftIssue.detail}`
|
|
|
|
|
|
: driftIssue.message;
|
|
|
|
|
|
warnings.push(warning);
|
|
|
|
|
|
if (!json) {
|
|
|
|
|
|
defaultRuntime.log(`\n⚠️ ${driftIssue.message}`);
|
|
|
|
|
|
if (driftIssue.detail) {
|
|
|
|
|
|
defaultRuntime.log(` ${driftIssue.detail}\n`);
|
|
|
|
|
|
}
|
2026-02-16 14:48:00 +01:00
|
|
|
|
}
|
2026-02-16 14:03:28 +01:00
|
|
|
|
}
|
2026-03-05 12:53:56 -06:00
|
|
|
|
} catch (err) {
|
|
|
|
|
|
if (isGatewaySecretRefUnavailableError(err, "gateway.auth.token")) {
|
|
|
|
|
|
const warning =
|
|
|
|
|
|
"Unable to verify gateway token drift: gateway.auth.token SecretRef is configured but unavailable in this command path.";
|
|
|
|
|
|
warnings.push(warning);
|
|
|
|
|
|
if (!json) {
|
|
|
|
|
|
defaultRuntime.log(`\n⚠️ ${warning}\n`);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-02-16 14:03:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-05 18:17:58 +08:00
|
|
|
|
// Pre-flight config validation (#35862)
|
|
|
|
|
|
{
|
|
|
|
|
|
const configError = await getConfigValidationError();
|
|
|
|
|
|
if (configError) {
|
|
|
|
|
|
fail(
|
|
|
|
|
|
`${params.serviceNoun} aborted: config is invalid.\n${configError}\nFix the config and retry, or run "openclaw doctor" to repair.`,
|
|
|
|
|
|
);
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-14 14:00:34 +00:00
|
|
|
|
try {
|
2026-03-07 21:20:29 -05:00
|
|
|
|
if (loaded) {
|
|
|
|
|
|
await params.service.restart({ env: process.env, stdout });
|
|
|
|
|
|
}
|
2026-02-21 18:02:05 +01:00
|
|
|
|
if (params.postRestartCheck) {
|
|
|
|
|
|
await params.postRestartCheck({ json, stdout, warnings, fail });
|
|
|
|
|
|
}
|
2026-03-07 21:20:29 -05:00
|
|
|
|
let restarted = loaded;
|
|
|
|
|
|
if (loaded) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
restarted = await params.service.isLoaded({ env: process.env });
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
restarted = true;
|
|
|
|
|
|
}
|
2026-02-14 14:00:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
emit({
|
|
|
|
|
|
ok: true,
|
|
|
|
|
|
result: "restarted",
|
2026-03-07 21:20:29 -05:00
|
|
|
|
message: handledNotLoaded?.message,
|
2026-02-14 14:00:34 +00:00
|
|
|
|
service: buildDaemonServiceSnapshot(params.service, restarted),
|
2026-02-16 14:48:00 +01:00
|
|
|
|
warnings: warnings.length ? warnings : undefined,
|
2026-02-14 14:00:34 +00:00
|
|
|
|
});
|
2026-03-07 21:20:29 -05:00
|
|
|
|
if (!json && handledNotLoaded?.message) {
|
|
|
|
|
|
defaultRuntime.log(handledNotLoaded.message);
|
|
|
|
|
|
}
|
2026-02-14 14:00:34 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
const hints = params.renderStartHints();
|
|
|
|
|
|
fail(`${params.serviceNoun} restart failed: ${String(err)}`, hints);
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|