refactor(daemon): share service description resolve
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
GATEWAY_WINDOWS_TASK_NAME,
|
||||
resolveGatewayLaunchAgentLabel,
|
||||
resolveGatewayProfileSuffix,
|
||||
resolveGatewayServiceDescription,
|
||||
resolveGatewaySystemdServiceName,
|
||||
resolveGatewayWindowsTaskName,
|
||||
} from "./constants.js";
|
||||
@@ -196,3 +197,23 @@ describe("formatGatewayServiceDescription", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveGatewayServiceDescription", () => {
|
||||
it("prefers explicit description override", () => {
|
||||
expect(
|
||||
resolveGatewayServiceDescription({
|
||||
env: { OPENCLAW_PROFILE: "work", OPENCLAW_SERVICE_VERSION: "1.0.0" },
|
||||
description: "Custom",
|
||||
}),
|
||||
).toBe("Custom");
|
||||
});
|
||||
|
||||
it("resolves version from explicit environment map", () => {
|
||||
expect(
|
||||
resolveGatewayServiceDescription({
|
||||
env: { OPENCLAW_PROFILE: "work", OPENCLAW_SERVICE_VERSION: "local" },
|
||||
environment: { OPENCLAW_SERVICE_VERSION: "remote" },
|
||||
}),
|
||||
).toBe("OpenClaw Gateway (profile: work, vremote)");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -75,6 +75,20 @@ export function formatGatewayServiceDescription(params?: {
|
||||
return `OpenClaw Gateway (${parts.join(", ")})`;
|
||||
}
|
||||
|
||||
export function resolveGatewayServiceDescription(params: {
|
||||
env: Record<string, string | undefined>;
|
||||
environment?: Record<string, string | undefined>;
|
||||
description?: string;
|
||||
}): string {
|
||||
return (
|
||||
params.description ??
|
||||
formatGatewayServiceDescription({
|
||||
profile: params.env.OPENCLAW_PROFILE,
|
||||
version: params.environment?.OPENCLAW_SERVICE_VERSION ?? params.env.OPENCLAW_SERVICE_VERSION,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function resolveNodeLaunchAgentLabel(): string {
|
||||
return NODE_LAUNCH_AGENT_LABEL;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import type { GatewayServiceRuntime } from "./service-runtime.js";
|
||||
import {
|
||||
formatGatewayServiceDescription,
|
||||
GATEWAY_LAUNCH_AGENT_LABEL,
|
||||
resolveGatewayServiceDescription,
|
||||
resolveGatewayLaunchAgentLabel,
|
||||
resolveLegacyGatewayLaunchAgentLabels,
|
||||
} from "./constants.js";
|
||||
@@ -384,12 +384,7 @@ export async function installLaunchAgent({
|
||||
const plistPath = resolveLaunchAgentPlistPathForLabel(env, label);
|
||||
await fs.mkdir(path.dirname(plistPath), { recursive: true });
|
||||
|
||||
const serviceDescription =
|
||||
description ??
|
||||
formatGatewayServiceDescription({
|
||||
profile: env.OPENCLAW_PROFILE,
|
||||
version: environment?.OPENCLAW_SERVICE_VERSION ?? env.OPENCLAW_SERVICE_VERSION,
|
||||
});
|
||||
const serviceDescription = resolveGatewayServiceDescription({ env, environment, description });
|
||||
const plist = buildLaunchAgentPlist({
|
||||
label,
|
||||
comment: serviceDescription,
|
||||
|
||||
@@ -2,7 +2,7 @@ import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import type { GatewayServiceRuntime } from "./service-runtime.js";
|
||||
import { splitArgsPreservingQuotes } from "./arg-split.js";
|
||||
import { formatGatewayServiceDescription, resolveGatewayWindowsTaskName } from "./constants.js";
|
||||
import { resolveGatewayServiceDescription, resolveGatewayWindowsTaskName } from "./constants.js";
|
||||
import { formatLine } from "./output.js";
|
||||
import { resolveGatewayStateDir } from "./paths.js";
|
||||
import { parseKeyValueOutput } from "./runtime-parse.js";
|
||||
@@ -190,12 +190,7 @@ export async function installScheduledTask({
|
||||
await assertSchtasksAvailable();
|
||||
const scriptPath = resolveTaskScriptPath(env);
|
||||
await fs.mkdir(path.dirname(scriptPath), { recursive: true });
|
||||
const taskDescription =
|
||||
description ??
|
||||
formatGatewayServiceDescription({
|
||||
profile: env.OPENCLAW_PROFILE,
|
||||
version: environment?.OPENCLAW_SERVICE_VERSION ?? env.OPENCLAW_SERVICE_VERSION,
|
||||
});
|
||||
const taskDescription = resolveGatewayServiceDescription({ env, environment, description });
|
||||
const script = buildTaskScript({
|
||||
description: taskDescription,
|
||||
programArguments,
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { GatewayServiceRuntime } from "./service-runtime.js";
|
||||
import {
|
||||
formatGatewayServiceDescription,
|
||||
LEGACY_GATEWAY_SYSTEMD_SERVICE_NAMES,
|
||||
resolveGatewayServiceDescription,
|
||||
resolveGatewaySystemdServiceName,
|
||||
} from "./constants.js";
|
||||
import { execFileUtf8 } from "./exec-file.js";
|
||||
@@ -200,12 +201,7 @@ export async function installSystemdService({
|
||||
|
||||
const unitPath = resolveSystemdUnitPath(env);
|
||||
await fs.mkdir(path.dirname(unitPath), { recursive: true });
|
||||
const serviceDescription =
|
||||
description ??
|
||||
formatGatewayServiceDescription({
|
||||
profile: env.OPENCLAW_PROFILE,
|
||||
version: environment?.OPENCLAW_SERVICE_VERSION ?? env.OPENCLAW_SERVICE_VERSION,
|
||||
});
|
||||
const serviceDescription = resolveGatewayServiceDescription({ env, environment, description });
|
||||
const unit = buildSystemdUnit({
|
||||
description: serviceDescription,
|
||||
programArguments,
|
||||
|
||||
Reference in New Issue
Block a user