mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 12:51:24 +00:00
refactor(daemon): share runtime status formatter
This commit is contained in:
@@ -4,10 +4,13 @@ import {
|
|||||||
resolveGatewayWindowsTaskName,
|
resolveGatewayWindowsTaskName,
|
||||||
} from "../../daemon/constants.js";
|
} from "../../daemon/constants.js";
|
||||||
import { resolveGatewayLogPaths } from "../../daemon/launchd.js";
|
import { resolveGatewayLogPaths } from "../../daemon/launchd.js";
|
||||||
|
import { formatRuntimeStatus } from "../../daemon/runtime-format.js";
|
||||||
import { pickPrimaryLanIPv4 } from "../../gateway/net.js";
|
import { pickPrimaryLanIPv4 } from "../../gateway/net.js";
|
||||||
import { getResolvedLoggerSettings } from "../../logging.js";
|
import { getResolvedLoggerSettings } from "../../logging.js";
|
||||||
import { formatCliCommand } from "../command-format.js";
|
import { formatCliCommand } from "../command-format.js";
|
||||||
|
|
||||||
|
export { formatRuntimeStatus };
|
||||||
|
|
||||||
export function parsePort(raw: unknown): number | null {
|
export function parsePort(raw: unknown): number | null {
|
||||||
if (raw === undefined || raw === null) {
|
if (raw === undefined || raw === null) {
|
||||||
return null;
|
return null;
|
||||||
@@ -106,53 +109,6 @@ export function normalizeListenerAddress(raw: string): string {
|
|||||||
return value.trim();
|
return value.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatRuntimeStatus(
|
|
||||||
runtime:
|
|
||||||
| {
|
|
||||||
status?: string;
|
|
||||||
state?: string;
|
|
||||||
subState?: string;
|
|
||||||
pid?: number;
|
|
||||||
lastExitStatus?: number;
|
|
||||||
lastExitReason?: string;
|
|
||||||
lastRunResult?: string;
|
|
||||||
lastRunTime?: string;
|
|
||||||
detail?: string;
|
|
||||||
}
|
|
||||||
| undefined,
|
|
||||||
) {
|
|
||||||
if (!runtime) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const status = runtime.status ?? "unknown";
|
|
||||||
const details: string[] = [];
|
|
||||||
if (runtime.pid) {
|
|
||||||
details.push(`pid ${runtime.pid}`);
|
|
||||||
}
|
|
||||||
if (runtime.state && runtime.state.toLowerCase() !== status) {
|
|
||||||
details.push(`state ${runtime.state}`);
|
|
||||||
}
|
|
||||||
if (runtime.subState) {
|
|
||||||
details.push(`sub ${runtime.subState}`);
|
|
||||||
}
|
|
||||||
if (runtime.lastExitStatus !== undefined) {
|
|
||||||
details.push(`last exit ${runtime.lastExitStatus}`);
|
|
||||||
}
|
|
||||||
if (runtime.lastExitReason) {
|
|
||||||
details.push(`reason ${runtime.lastExitReason}`);
|
|
||||||
}
|
|
||||||
if (runtime.lastRunResult) {
|
|
||||||
details.push(`last run ${runtime.lastRunResult}`);
|
|
||||||
}
|
|
||||||
if (runtime.lastRunTime) {
|
|
||||||
details.push(`last run time ${runtime.lastRunTime}`);
|
|
||||||
}
|
|
||||||
if (runtime.detail) {
|
|
||||||
details.push(runtime.detail);
|
|
||||||
}
|
|
||||||
return details.length > 0 ? `${status} (${details.join(", ")})` : status;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function renderRuntimeHints(
|
export function renderRuntimeHints(
|
||||||
runtime: { missingUnit?: boolean; status?: string } | undefined,
|
runtime: { missingUnit?: boolean; status?: string } | undefined,
|
||||||
env: NodeJS.ProcessEnv = process.env,
|
env: NodeJS.ProcessEnv = process.env,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
resolveGatewayWindowsTaskName,
|
resolveGatewayWindowsTaskName,
|
||||||
} from "../daemon/constants.js";
|
} from "../daemon/constants.js";
|
||||||
import { resolveGatewayLogPaths } from "../daemon/launchd.js";
|
import { resolveGatewayLogPaths } from "../daemon/launchd.js";
|
||||||
|
import { formatRuntimeStatus } from "../daemon/runtime-format.js";
|
||||||
import {
|
import {
|
||||||
isSystemdUnavailableDetail,
|
isSystemdUnavailableDetail,
|
||||||
renderSystemdUnavailableHints,
|
renderSystemdUnavailableHints,
|
||||||
@@ -21,36 +22,7 @@ type RuntimeHintOptions = {
|
|||||||
export function formatGatewayRuntimeSummary(
|
export function formatGatewayRuntimeSummary(
|
||||||
runtime: GatewayServiceRuntime | undefined,
|
runtime: GatewayServiceRuntime | undefined,
|
||||||
): string | null {
|
): string | null {
|
||||||
if (!runtime) {
|
return formatRuntimeStatus(runtime);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const status = runtime.status ?? "unknown";
|
|
||||||
const details: string[] = [];
|
|
||||||
if (runtime.pid) {
|
|
||||||
details.push(`pid ${runtime.pid}`);
|
|
||||||
}
|
|
||||||
if (runtime.state && runtime.state.toLowerCase() !== status) {
|
|
||||||
details.push(`state ${runtime.state}`);
|
|
||||||
}
|
|
||||||
if (runtime.subState) {
|
|
||||||
details.push(`sub ${runtime.subState}`);
|
|
||||||
}
|
|
||||||
if (runtime.lastExitStatus !== undefined) {
|
|
||||||
details.push(`last exit ${runtime.lastExitStatus}`);
|
|
||||||
}
|
|
||||||
if (runtime.lastExitReason) {
|
|
||||||
details.push(`reason ${runtime.lastExitReason}`);
|
|
||||||
}
|
|
||||||
if (runtime.lastRunResult) {
|
|
||||||
details.push(`last run ${runtime.lastRunResult}`);
|
|
||||||
}
|
|
||||||
if (runtime.lastRunTime) {
|
|
||||||
details.push(`last run time ${runtime.lastRunTime}`);
|
|
||||||
}
|
|
||||||
if (runtime.detail) {
|
|
||||||
details.push(runtime.detail);
|
|
||||||
}
|
|
||||||
return details.length > 0 ? `${status} (${details.join(", ")})` : status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildGatewayRuntimeHints(
|
export function buildGatewayRuntimeHints(
|
||||||
|
|||||||
44
src/daemon/runtime-format.ts
Normal file
44
src/daemon/runtime-format.ts
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
export type ServiceRuntimeLike = {
|
||||||
|
status?: string;
|
||||||
|
state?: string;
|
||||||
|
subState?: string;
|
||||||
|
pid?: number;
|
||||||
|
lastExitStatus?: number;
|
||||||
|
lastExitReason?: string;
|
||||||
|
lastRunResult?: string;
|
||||||
|
lastRunTime?: string;
|
||||||
|
detail?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function formatRuntimeStatus(runtime: ServiceRuntimeLike | undefined): string | null {
|
||||||
|
if (!runtime) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const status = runtime.status ?? "unknown";
|
||||||
|
const details: string[] = [];
|
||||||
|
if (runtime.pid) {
|
||||||
|
details.push(`pid ${runtime.pid}`);
|
||||||
|
}
|
||||||
|
if (runtime.state && runtime.state.toLowerCase() !== status) {
|
||||||
|
details.push(`state ${runtime.state}`);
|
||||||
|
}
|
||||||
|
if (runtime.subState) {
|
||||||
|
details.push(`sub ${runtime.subState}`);
|
||||||
|
}
|
||||||
|
if (runtime.lastExitStatus !== undefined) {
|
||||||
|
details.push(`last exit ${runtime.lastExitStatus}`);
|
||||||
|
}
|
||||||
|
if (runtime.lastExitReason) {
|
||||||
|
details.push(`reason ${runtime.lastExitReason}`);
|
||||||
|
}
|
||||||
|
if (runtime.lastRunResult) {
|
||||||
|
details.push(`last run ${runtime.lastRunResult}`);
|
||||||
|
}
|
||||||
|
if (runtime.lastRunTime) {
|
||||||
|
details.push(`last run time ${runtime.lastRunTime}`);
|
||||||
|
}
|
||||||
|
if (runtime.detail) {
|
||||||
|
details.push(runtime.detail);
|
||||||
|
}
|
||||||
|
return details.length > 0 ? `${status} (${details.join(", ")})` : status;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user