mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-29 01:02:03 +03:00
refactor(daemon): share schtasks exec helper
This commit is contained in:
+1
-32
@@ -1,7 +1,5 @@
|
|||||||
import { execFile } from "node:child_process";
|
|
||||||
import fs from "node:fs/promises";
|
import fs from "node:fs/promises";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { promisify } from "node:util";
|
|
||||||
import {
|
import {
|
||||||
GATEWAY_SERVICE_KIND,
|
GATEWAY_SERVICE_KIND,
|
||||||
GATEWAY_SERVICE_MARKER,
|
GATEWAY_SERVICE_MARKER,
|
||||||
@@ -9,6 +7,7 @@ import {
|
|||||||
resolveGatewaySystemdServiceName,
|
resolveGatewaySystemdServiceName,
|
||||||
resolveGatewayWindowsTaskName,
|
resolveGatewayWindowsTaskName,
|
||||||
} from "./constants.js";
|
} from "./constants.js";
|
||||||
|
import { execSchtasks } from "./schtasks-exec.js";
|
||||||
|
|
||||||
export type ExtraGatewayService = {
|
export type ExtraGatewayService = {
|
||||||
platform: "darwin" | "linux" | "win32";
|
platform: "darwin" | "linux" | "win32";
|
||||||
@@ -24,7 +23,6 @@ export type FindExtraGatewayServicesOptions = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const EXTRA_MARKERS = ["openclaw", "clawdbot", "moltbot"] as const;
|
const EXTRA_MARKERS = ["openclaw", "clawdbot", "moltbot"] as const;
|
||||||
const execFileAsync = promisify(execFile);
|
|
||||||
|
|
||||||
export function renderGatewayServiceCleanupHints(
|
export function renderGatewayServiceCleanupHints(
|
||||||
env: Record<string, string | undefined> = process.env as Record<string, string | undefined>,
|
env: Record<string, string | undefined> = process.env as Record<string, string | undefined>,
|
||||||
@@ -296,35 +294,6 @@ function parseSchtasksList(output: string): ScheduledTaskInfo[] {
|
|||||||
return tasks;
|
return tasks;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function execSchtasks(
|
|
||||||
args: string[],
|
|
||||||
): Promise<{ stdout: string; stderr: string; code: number }> {
|
|
||||||
try {
|
|
||||||
const { stdout, stderr } = await execFileAsync("schtasks", args, {
|
|
||||||
encoding: "utf8",
|
|
||||||
windowsHide: true,
|
|
||||||
});
|
|
||||||
return {
|
|
||||||
stdout: String(stdout ?? ""),
|
|
||||||
stderr: String(stderr ?? ""),
|
|
||||||
code: 0,
|
|
||||||
};
|
|
||||||
} catch (error) {
|
|
||||||
const e = error as {
|
|
||||||
stdout?: unknown;
|
|
||||||
stderr?: unknown;
|
|
||||||
code?: unknown;
|
|
||||||
message?: unknown;
|
|
||||||
};
|
|
||||||
return {
|
|
||||||
stdout: typeof e.stdout === "string" ? e.stdout : "",
|
|
||||||
stderr:
|
|
||||||
typeof e.stderr === "string" ? e.stderr : typeof e.message === "string" ? e.message : "",
|
|
||||||
code: typeof e.code === "number" ? e.code : 1,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function findExtraGatewayServices(
|
export async function findExtraGatewayServices(
|
||||||
env: Record<string, string | undefined>,
|
env: Record<string, string | undefined>,
|
||||||
opts: FindExtraGatewayServicesOptions = {},
|
opts: FindExtraGatewayServicesOptions = {},
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import { execFile } from "node:child_process";
|
||||||
|
import { promisify } from "node:util";
|
||||||
|
|
||||||
|
const execFileAsync = promisify(execFile);
|
||||||
|
|
||||||
|
export async function execSchtasks(
|
||||||
|
args: string[],
|
||||||
|
): Promise<{ stdout: string; stderr: string; code: number }> {
|
||||||
|
try {
|
||||||
|
const { stdout, stderr } = await execFileAsync("schtasks", args, {
|
||||||
|
encoding: "utf8",
|
||||||
|
windowsHide: true,
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
stdout: String(stdout ?? ""),
|
||||||
|
stderr: String(stderr ?? ""),
|
||||||
|
code: 0,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
const e = error as {
|
||||||
|
stdout?: unknown;
|
||||||
|
stderr?: unknown;
|
||||||
|
code?: unknown;
|
||||||
|
message?: unknown;
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
stdout: typeof e.stdout === "string" ? e.stdout : "",
|
||||||
|
stderr:
|
||||||
|
typeof e.stderr === "string" ? e.stderr : typeof e.message === "string" ? e.message : "",
|
||||||
|
code: typeof e.code === "number" ? e.code : 1,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-33
@@ -1,14 +1,11 @@
|
|||||||
import { execFile } from "node:child_process";
|
|
||||||
import fs from "node:fs/promises";
|
import fs from "node:fs/promises";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { promisify } from "node:util";
|
|
||||||
import type { GatewayServiceRuntime } from "./service-runtime.js";
|
import type { GatewayServiceRuntime } from "./service-runtime.js";
|
||||||
import { colorize, isRich, theme } from "../terminal/theme.js";
|
import { colorize, isRich, theme } from "../terminal/theme.js";
|
||||||
import { formatGatewayServiceDescription, resolveGatewayWindowsTaskName } from "./constants.js";
|
import { formatGatewayServiceDescription, resolveGatewayWindowsTaskName } from "./constants.js";
|
||||||
import { resolveGatewayStateDir } from "./paths.js";
|
import { resolveGatewayStateDir } from "./paths.js";
|
||||||
import { parseKeyValueOutput } from "./runtime-parse.js";
|
import { parseKeyValueOutput } from "./runtime-parse.js";
|
||||||
|
import { execSchtasks } from "./schtasks-exec.js";
|
||||||
const execFileAsync = promisify(execFile);
|
|
||||||
|
|
||||||
const formatLine = (label: string, value: string) => {
|
const formatLine = (label: string, value: string) => {
|
||||||
const rich = isRich();
|
const rich = isRich();
|
||||||
@@ -197,35 +194,6 @@ function buildTaskScript({
|
|||||||
return `${lines.join("\r\n")}\r\n`;
|
return `${lines.join("\r\n")}\r\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function execSchtasks(
|
|
||||||
args: string[],
|
|
||||||
): Promise<{ stdout: string; stderr: string; code: number }> {
|
|
||||||
try {
|
|
||||||
const { stdout, stderr } = await execFileAsync("schtasks", args, {
|
|
||||||
encoding: "utf8",
|
|
||||||
windowsHide: true,
|
|
||||||
});
|
|
||||||
return {
|
|
||||||
stdout: String(stdout ?? ""),
|
|
||||||
stderr: String(stderr ?? ""),
|
|
||||||
code: 0,
|
|
||||||
};
|
|
||||||
} catch (error) {
|
|
||||||
const e = error as {
|
|
||||||
stdout?: unknown;
|
|
||||||
stderr?: unknown;
|
|
||||||
code?: unknown;
|
|
||||||
message?: unknown;
|
|
||||||
};
|
|
||||||
return {
|
|
||||||
stdout: typeof e.stdout === "string" ? e.stdout : "",
|
|
||||||
stderr:
|
|
||||||
typeof e.stderr === "string" ? e.stderr : typeof e.message === "string" ? e.message : "",
|
|
||||||
code: typeof e.code === "number" ? e.code : 1,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function assertSchtasksAvailable() {
|
async function assertSchtasksAvailable() {
|
||||||
const res = await execSchtasks(["/Query"]);
|
const res = await execSchtasks(["/Query"]);
|
||||||
if (res.code === 0) {
|
if (res.code === 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user