mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 10:27:28 +00:00
refactor(daemon): simplify gateway service backend delegates
This commit is contained in:
@@ -17,6 +17,14 @@ import {
|
||||
uninstallScheduledTask,
|
||||
} from "./schtasks.js";
|
||||
import type { GatewayServiceRuntime } from "./service-runtime.js";
|
||||
import type {
|
||||
GatewayServiceCommandConfig,
|
||||
GatewayServiceControlArgs,
|
||||
GatewayServiceEnv,
|
||||
GatewayServiceEnvArgs,
|
||||
GatewayServiceInstallArgs,
|
||||
GatewayServiceManageArgs,
|
||||
} from "./service-types.js";
|
||||
import {
|
||||
installSystemdService,
|
||||
isSystemdServiceEnabled,
|
||||
@@ -26,41 +34,34 @@ import {
|
||||
stopSystemdService,
|
||||
uninstallSystemdService,
|
||||
} from "./systemd.js";
|
||||
export type {
|
||||
GatewayServiceCommandConfig,
|
||||
GatewayServiceControlArgs,
|
||||
GatewayServiceEnv,
|
||||
GatewayServiceEnvArgs,
|
||||
GatewayServiceInstallArgs,
|
||||
GatewayServiceManageArgs,
|
||||
} from "./service-types.js";
|
||||
|
||||
export type GatewayServiceInstallArgs = {
|
||||
env: Record<string, string | undefined>;
|
||||
stdout: NodeJS.WritableStream;
|
||||
programArguments: string[];
|
||||
workingDirectory?: string;
|
||||
environment?: Record<string, string | undefined>;
|
||||
description?: string;
|
||||
};
|
||||
function ignoreInstallResult(
|
||||
install: (args: GatewayServiceInstallArgs) => Promise<unknown>,
|
||||
): (args: GatewayServiceInstallArgs) => Promise<void> {
|
||||
return async (args) => {
|
||||
await install(args);
|
||||
};
|
||||
}
|
||||
|
||||
export type GatewayService = {
|
||||
label: string;
|
||||
loadedText: string;
|
||||
notLoadedText: string;
|
||||
install: (args: GatewayServiceInstallArgs) => Promise<void>;
|
||||
uninstall: (args: {
|
||||
env: Record<string, string | undefined>;
|
||||
stdout: NodeJS.WritableStream;
|
||||
}) => Promise<void>;
|
||||
stop: (args: {
|
||||
env?: Record<string, string | undefined>;
|
||||
stdout: NodeJS.WritableStream;
|
||||
}) => Promise<void>;
|
||||
restart: (args: {
|
||||
env?: Record<string, string | undefined>;
|
||||
stdout: NodeJS.WritableStream;
|
||||
}) => Promise<void>;
|
||||
isLoaded: (args: { env?: Record<string, string | undefined> }) => Promise<boolean>;
|
||||
readCommand: (env: Record<string, string | undefined>) => Promise<{
|
||||
programArguments: string[];
|
||||
workingDirectory?: string;
|
||||
environment?: Record<string, string>;
|
||||
sourcePath?: string;
|
||||
} | null>;
|
||||
readRuntime: (env: Record<string, string | undefined>) => Promise<GatewayServiceRuntime>;
|
||||
uninstall: (args: GatewayServiceManageArgs) => Promise<void>;
|
||||
stop: (args: GatewayServiceControlArgs) => Promise<void>;
|
||||
restart: (args: GatewayServiceControlArgs) => Promise<void>;
|
||||
isLoaded: (args: GatewayServiceEnvArgs) => Promise<boolean>;
|
||||
readCommand: (env: GatewayServiceEnv) => Promise<GatewayServiceCommandConfig | null>;
|
||||
readRuntime: (env: GatewayServiceEnv) => Promise<GatewayServiceRuntime>;
|
||||
};
|
||||
|
||||
export function resolveGatewayService(): GatewayService {
|
||||
@@ -69,25 +70,11 @@ export function resolveGatewayService(): GatewayService {
|
||||
label: "LaunchAgent",
|
||||
loadedText: "loaded",
|
||||
notLoadedText: "not loaded",
|
||||
install: async (args) => {
|
||||
await installLaunchAgent(args);
|
||||
},
|
||||
uninstall: async (args) => {
|
||||
await uninstallLaunchAgent(args);
|
||||
},
|
||||
stop: async (args) => {
|
||||
await stopLaunchAgent({
|
||||
stdout: args.stdout,
|
||||
env: args.env,
|
||||
});
|
||||
},
|
||||
restart: async (args) => {
|
||||
await restartLaunchAgent({
|
||||
stdout: args.stdout,
|
||||
env: args.env,
|
||||
});
|
||||
},
|
||||
isLoaded: async (args) => isLaunchAgentLoaded(args),
|
||||
install: ignoreInstallResult(installLaunchAgent),
|
||||
uninstall: uninstallLaunchAgent,
|
||||
stop: stopLaunchAgent,
|
||||
restart: restartLaunchAgent,
|
||||
isLoaded: isLaunchAgentLoaded,
|
||||
readCommand: readLaunchAgentProgramArguments,
|
||||
readRuntime: readLaunchAgentRuntime,
|
||||
};
|
||||
@@ -98,27 +85,13 @@ export function resolveGatewayService(): GatewayService {
|
||||
label: "systemd",
|
||||
loadedText: "enabled",
|
||||
notLoadedText: "disabled",
|
||||
install: async (args) => {
|
||||
await installSystemdService(args);
|
||||
},
|
||||
uninstall: async (args) => {
|
||||
await uninstallSystemdService(args);
|
||||
},
|
||||
stop: async (args) => {
|
||||
await stopSystemdService({
|
||||
stdout: args.stdout,
|
||||
env: args.env,
|
||||
});
|
||||
},
|
||||
restart: async (args) => {
|
||||
await restartSystemdService({
|
||||
stdout: args.stdout,
|
||||
env: args.env,
|
||||
});
|
||||
},
|
||||
isLoaded: async (args) => isSystemdServiceEnabled(args),
|
||||
install: ignoreInstallResult(installSystemdService),
|
||||
uninstall: uninstallSystemdService,
|
||||
stop: stopSystemdService,
|
||||
restart: restartSystemdService,
|
||||
isLoaded: isSystemdServiceEnabled,
|
||||
readCommand: readSystemdServiceExecStart,
|
||||
readRuntime: async (env) => await readSystemdServiceRuntime(env),
|
||||
readRuntime: readSystemdServiceRuntime,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -127,27 +100,13 @@ export function resolveGatewayService(): GatewayService {
|
||||
label: "Scheduled Task",
|
||||
loadedText: "registered",
|
||||
notLoadedText: "missing",
|
||||
install: async (args) => {
|
||||
await installScheduledTask(args);
|
||||
},
|
||||
uninstall: async (args) => {
|
||||
await uninstallScheduledTask(args);
|
||||
},
|
||||
stop: async (args) => {
|
||||
await stopScheduledTask({
|
||||
stdout: args.stdout,
|
||||
env: args.env,
|
||||
});
|
||||
},
|
||||
restart: async (args) => {
|
||||
await restartScheduledTask({
|
||||
stdout: args.stdout,
|
||||
env: args.env,
|
||||
});
|
||||
},
|
||||
isLoaded: async (args) => isScheduledTaskInstalled(args),
|
||||
install: ignoreInstallResult(installScheduledTask),
|
||||
uninstall: uninstallScheduledTask,
|
||||
stop: stopScheduledTask,
|
||||
restart: restartScheduledTask,
|
||||
isLoaded: isScheduledTaskInstalled,
|
||||
readCommand: readScheduledTaskCommand,
|
||||
readRuntime: async (env) => await readScheduledTaskRuntime(env),
|
||||
readRuntime: readScheduledTaskRuntime,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user