mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
refactor(cli): dedupe daemon install finalize
This commit is contained in:
@@ -16,7 +16,11 @@ import { resolveGatewayService } from "../../daemon/service.js";
|
||||
import { resolveGatewayAuth } from "../../gateway/auth.js";
|
||||
import { defaultRuntime } from "../../runtime.js";
|
||||
import { formatCliCommand } from "../command-format.js";
|
||||
import { buildDaemonServiceSnapshot, createDaemonActionContext } from "./response.js";
|
||||
import {
|
||||
buildDaemonServiceSnapshot,
|
||||
createDaemonActionContext,
|
||||
installDaemonServiceAndEmit,
|
||||
} from "./response.js";
|
||||
import { parsePort } from "./shared.js";
|
||||
|
||||
export async function runDaemonInstall(opts: DaemonInstallOptions) {
|
||||
@@ -154,29 +158,20 @@ export async function runDaemonInstall(opts: DaemonInstallOptions) {
|
||||
config: cfg,
|
||||
});
|
||||
|
||||
try {
|
||||
await service.install({
|
||||
env: process.env,
|
||||
stdout,
|
||||
programArguments,
|
||||
workingDirectory,
|
||||
environment,
|
||||
});
|
||||
} catch (err) {
|
||||
fail(`Gateway install failed: ${String(err)}`);
|
||||
return;
|
||||
}
|
||||
|
||||
let installed = true;
|
||||
try {
|
||||
installed = await service.isLoaded({ env: process.env });
|
||||
} catch {
|
||||
installed = true;
|
||||
}
|
||||
emit({
|
||||
ok: true,
|
||||
result: "installed",
|
||||
service: buildDaemonServiceSnapshot(service, installed),
|
||||
warnings: warnings.length ? warnings : undefined,
|
||||
await installDaemonServiceAndEmit({
|
||||
serviceNoun: "Gateway",
|
||||
service,
|
||||
warnings,
|
||||
emit,
|
||||
fail,
|
||||
install: async () => {
|
||||
await service.install({
|
||||
env: process.env,
|
||||
stdout,
|
||||
programArguments,
|
||||
workingDirectory,
|
||||
environment,
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -79,3 +79,32 @@ export function createDaemonActionContext(params: { action: DaemonAction; json:
|
||||
|
||||
return { stdout, warnings, emit, fail };
|
||||
}
|
||||
|
||||
export async function installDaemonServiceAndEmit(params: {
|
||||
serviceNoun: string;
|
||||
service: GatewayService;
|
||||
warnings: string[];
|
||||
emit: (payload: Omit<DaemonActionResponse, "action">) => void;
|
||||
fail: (message: string, hints?: string[]) => void;
|
||||
install: () => Promise<void>;
|
||||
}) {
|
||||
try {
|
||||
await params.install();
|
||||
} catch (err) {
|
||||
params.fail(`${params.serviceNoun} install failed: ${String(err)}`);
|
||||
return;
|
||||
}
|
||||
|
||||
let installed = true;
|
||||
try {
|
||||
installed = await params.service.isLoaded({ env: process.env });
|
||||
} catch {
|
||||
installed = true;
|
||||
}
|
||||
params.emit({
|
||||
ok: true,
|
||||
result: "installed",
|
||||
service: buildDaemonServiceSnapshot(params.service, installed),
|
||||
warnings: params.warnings.length ? params.warnings : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -22,7 +22,11 @@ import {
|
||||
runServiceStop,
|
||||
runServiceUninstall,
|
||||
} from "../daemon-cli/lifecycle-core.js";
|
||||
import { buildDaemonServiceSnapshot, createDaemonActionContext } from "../daemon-cli/response.js";
|
||||
import {
|
||||
buildDaemonServiceSnapshot,
|
||||
createDaemonActionContext,
|
||||
installDaemonServiceAndEmit,
|
||||
} from "../daemon-cli/response.js";
|
||||
import { formatRuntimeStatus, parsePort } from "../daemon-cli/shared.js";
|
||||
|
||||
type NodeDaemonInstallOptions = {
|
||||
@@ -160,31 +164,22 @@ export async function runNodeDaemonInstall(opts: NodeDaemonInstallOptions) {
|
||||
},
|
||||
});
|
||||
|
||||
try {
|
||||
await service.install({
|
||||
env: process.env,
|
||||
stdout,
|
||||
programArguments,
|
||||
workingDirectory,
|
||||
environment,
|
||||
description,
|
||||
});
|
||||
} catch (err) {
|
||||
fail(`Node install failed: ${String(err)}`);
|
||||
return;
|
||||
}
|
||||
|
||||
let installed = true;
|
||||
try {
|
||||
installed = await service.isLoaded({ env: process.env });
|
||||
} catch {
|
||||
installed = true;
|
||||
}
|
||||
emit({
|
||||
ok: true,
|
||||
result: "installed",
|
||||
service: buildDaemonServiceSnapshot(service, installed),
|
||||
warnings: warnings.length ? warnings : undefined,
|
||||
await installDaemonServiceAndEmit({
|
||||
serviceNoun: "Node",
|
||||
service,
|
||||
warnings,
|
||||
emit,
|
||||
fail,
|
||||
install: async () => {
|
||||
await service.install({
|
||||
env: process.env,
|
||||
stdout,
|
||||
programArguments,
|
||||
workingDirectory,
|
||||
environment,
|
||||
description,
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user