mirror of https://github.com/openclaw/openclaw.git
refactor: share daemon install cli setup
This commit is contained in:
parent
5197171d7a
commit
5b53481d1d
|
|
@ -84,8 +84,28 @@ vi.mock("../../commands/daemon-install-helpers.js", () => ({
|
||||||
|
|
||||||
vi.mock("./shared.js", () => ({
|
vi.mock("./shared.js", () => ({
|
||||||
parsePort: parsePortMock,
|
parsePort: parsePortMock,
|
||||||
|
createDaemonInstallActionContext: (jsonFlag: unknown) => {
|
||||||
|
const json = Boolean(jsonFlag);
|
||||||
|
return {
|
||||||
|
json,
|
||||||
|
stdout: process.stdout,
|
||||||
|
warnings: actionState.warnings,
|
||||||
|
emit: (payload: DaemonActionResponse) => {
|
||||||
|
actionState.emitted.push(payload);
|
||||||
|
},
|
||||||
|
fail: (message: string, hints?: string[]) => {
|
||||||
|
actionState.failed.push({ message, hints });
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
failIfNixDaemonInstallMode: (fail: (message: string, hints?: string[]) => void) => {
|
||||||
|
if (!resolveIsNixModeMock()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
fail("Nix mode detected; service install is disabled.");
|
||||||
|
return true;
|
||||||
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("../../commands/daemon-runtime.js", () => ({
|
vi.mock("../../commands/daemon-runtime.js", () => ({
|
||||||
DEFAULT_GATEWAY_DAEMON_RUNTIME: "node",
|
DEFAULT_GATEWAY_DAEMON_RUNTIME: "node",
|
||||||
isGatewayDaemonRuntime: isGatewayDaemonRuntimeMock,
|
isGatewayDaemonRuntime: isGatewayDaemonRuntimeMock,
|
||||||
|
|
@ -97,16 +117,6 @@ vi.mock("../../daemon/service.js", () => ({
|
||||||
|
|
||||||
vi.mock("./response.js", () => ({
|
vi.mock("./response.js", () => ({
|
||||||
buildDaemonServiceSnapshot: vi.fn(),
|
buildDaemonServiceSnapshot: vi.fn(),
|
||||||
createDaemonActionContext: vi.fn(() => ({
|
|
||||||
stdout: process.stdout,
|
|
||||||
warnings: actionState.warnings,
|
|
||||||
emit: (payload: DaemonActionResponse) => {
|
|
||||||
actionState.emitted.push(payload);
|
|
||||||
},
|
|
||||||
fail: (message: string, hints?: string[]) => {
|
|
||||||
actionState.failed.push({ message, hints });
|
|
||||||
},
|
|
||||||
})),
|
|
||||||
installDaemonServiceAndEmit: installDaemonServiceAndEmitMock,
|
installDaemonServiceAndEmit: installDaemonServiceAndEmitMock,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,25 +5,21 @@ import {
|
||||||
} from "../../commands/daemon-runtime.js";
|
} from "../../commands/daemon-runtime.js";
|
||||||
import { resolveGatewayInstallToken } from "../../commands/gateway-install-token.js";
|
import { resolveGatewayInstallToken } from "../../commands/gateway-install-token.js";
|
||||||
import { readBestEffortConfig, resolveGatewayPort } from "../../config/config.js";
|
import { readBestEffortConfig, resolveGatewayPort } from "../../config/config.js";
|
||||||
import { resolveIsNixMode } from "../../config/paths.js";
|
|
||||||
import { resolveGatewayService } from "../../daemon/service.js";
|
import { resolveGatewayService } from "../../daemon/service.js";
|
||||||
import { isNonFatalSystemdInstallProbeError } from "../../daemon/systemd.js";
|
import { isNonFatalSystemdInstallProbeError } from "../../daemon/systemd.js";
|
||||||
import { defaultRuntime } from "../../runtime.js";
|
import { defaultRuntime } from "../../runtime.js";
|
||||||
import { formatCliCommand } from "../command-format.js";
|
import { formatCliCommand } from "../command-format.js";
|
||||||
|
import { buildDaemonServiceSnapshot, installDaemonServiceAndEmit } from "./response.js";
|
||||||
import {
|
import {
|
||||||
buildDaemonServiceSnapshot,
|
createDaemonInstallActionContext,
|
||||||
createDaemonActionContext,
|
failIfNixDaemonInstallMode,
|
||||||
installDaemonServiceAndEmit,
|
parsePort,
|
||||||
} from "./response.js";
|
} from "./shared.js";
|
||||||
import { parsePort } from "./shared.js";
|
|
||||||
import type { DaemonInstallOptions } from "./types.js";
|
import type { DaemonInstallOptions } from "./types.js";
|
||||||
|
|
||||||
export async function runDaemonInstall(opts: DaemonInstallOptions) {
|
export async function runDaemonInstall(opts: DaemonInstallOptions) {
|
||||||
const json = Boolean(opts.json);
|
const { json, stdout, warnings, emit, fail } = createDaemonInstallActionContext(opts.json);
|
||||||
const { stdout, warnings, emit, fail } = createDaemonActionContext({ action: "install", json });
|
if (failIfNixDaemonInstallMode(fail)) {
|
||||||
|
|
||||||
if (resolveIsNixMode(process.env)) {
|
|
||||||
fail("Nix mode detected; service install is disabled.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { resolveIsNixMode } from "../../config/paths.js";
|
||||||
import {
|
import {
|
||||||
resolveGatewayLaunchAgentLabel,
|
resolveGatewayLaunchAgentLabel,
|
||||||
resolveGatewaySystemdServiceName,
|
resolveGatewaySystemdServiceName,
|
||||||
|
|
@ -12,10 +13,30 @@ import { getResolvedLoggerSettings } from "../../logging.js";
|
||||||
import { colorize, isRich, theme } from "../../terminal/theme.js";
|
import { colorize, isRich, theme } from "../../terminal/theme.js";
|
||||||
import { formatCliCommand } from "../command-format.js";
|
import { formatCliCommand } from "../command-format.js";
|
||||||
import { parsePort } from "../shared/parse-port.js";
|
import { parsePort } from "../shared/parse-port.js";
|
||||||
|
import { createDaemonActionContext } from "./response.js";
|
||||||
|
|
||||||
export { formatRuntimeStatus };
|
export { formatRuntimeStatus };
|
||||||
export { parsePort };
|
export { parsePort };
|
||||||
|
|
||||||
|
export function createDaemonInstallActionContext(jsonFlag: unknown) {
|
||||||
|
const json = Boolean(jsonFlag);
|
||||||
|
return {
|
||||||
|
json,
|
||||||
|
...createDaemonActionContext({ action: "install", json }),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function failIfNixDaemonInstallMode(
|
||||||
|
fail: (message: string, hints?: string[]) => void,
|
||||||
|
env: NodeJS.ProcessEnv = process.env,
|
||||||
|
): boolean {
|
||||||
|
if (!resolveIsNixMode(env)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
fail("Nix mode detected; service install is disabled.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
export function createCliStatusTextStyles() {
|
export function createCliStatusTextStyles() {
|
||||||
const rich = isRich();
|
const rich = isRich();
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ import {
|
||||||
DEFAULT_NODE_DAEMON_RUNTIME,
|
DEFAULT_NODE_DAEMON_RUNTIME,
|
||||||
isNodeDaemonRuntime,
|
isNodeDaemonRuntime,
|
||||||
} from "../../commands/node-daemon-runtime.js";
|
} from "../../commands/node-daemon-runtime.js";
|
||||||
import { resolveIsNixMode } from "../../config/paths.js";
|
|
||||||
import {
|
import {
|
||||||
resolveNodeLaunchAgentLabel,
|
resolveNodeLaunchAgentLabel,
|
||||||
resolveNodeSystemdServiceName,
|
resolveNodeSystemdServiceName,
|
||||||
|
|
@ -25,13 +24,11 @@ import {
|
||||||
runServiceStop,
|
runServiceStop,
|
||||||
runServiceUninstall,
|
runServiceUninstall,
|
||||||
} from "../daemon-cli/lifecycle-core.js";
|
} from "../daemon-cli/lifecycle-core.js";
|
||||||
import {
|
import { buildDaemonServiceSnapshot, installDaemonServiceAndEmit } from "../daemon-cli/response.js";
|
||||||
buildDaemonServiceSnapshot,
|
|
||||||
createDaemonActionContext,
|
|
||||||
installDaemonServiceAndEmit,
|
|
||||||
} from "../daemon-cli/response.js";
|
|
||||||
import {
|
import {
|
||||||
createCliStatusTextStyles,
|
createCliStatusTextStyles,
|
||||||
|
createDaemonInstallActionContext,
|
||||||
|
failIfNixDaemonInstallMode,
|
||||||
formatRuntimeStatus,
|
formatRuntimeStatus,
|
||||||
parsePort,
|
parsePort,
|
||||||
resolveRuntimeStatusColor,
|
resolveRuntimeStatusColor,
|
||||||
|
|
@ -89,11 +86,8 @@ function resolveNodeDefaults(
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function runNodeDaemonInstall(opts: NodeDaemonInstallOptions) {
|
export async function runNodeDaemonInstall(opts: NodeDaemonInstallOptions) {
|
||||||
const json = Boolean(opts.json);
|
const { json, stdout, warnings, emit, fail } = createDaemonInstallActionContext(opts.json);
|
||||||
const { stdout, warnings, emit, fail } = createDaemonActionContext({ action: "install", json });
|
if (failIfNixDaemonInstallMode(fail)) {
|
||||||
|
|
||||||
if (resolveIsNixMode(process.env)) {
|
|
||||||
fail("Nix mode detected; service install is disabled.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue