mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 17:08:27 +00:00
refactor: dedupe daemon exec wrappers
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
import type { GatewayServiceRuntime } from "./service-runtime.js";
|
||||
import {
|
||||
formatGatewayServiceDescription,
|
||||
LEGACY_GATEWAY_SYSTEMD_SERVICE_NAMES,
|
||||
resolveGatewaySystemdServiceName,
|
||||
} from "./constants.js";
|
||||
import { execFileUtf8 } from "./exec-file.js";
|
||||
import { formatLine, toPosixPath } from "./output.js";
|
||||
import { resolveHomeDir } from "./paths.js";
|
||||
import { parseKeyValueOutput } from "./runtime-parse.js";
|
||||
@@ -22,8 +21,6 @@ import {
|
||||
parseSystemdExecStart,
|
||||
} from "./systemd-unit.js";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
|
||||
function resolveSystemdUnitPathForName(
|
||||
env: Record<string, string | undefined>,
|
||||
name: string,
|
||||
@@ -142,29 +139,7 @@ export function parseSystemdShow(output: string): SystemdServiceInfo {
|
||||
async function execSystemctl(
|
||||
args: string[],
|
||||
): Promise<{ stdout: string; stderr: string; code: number }> {
|
||||
try {
|
||||
const { stdout, stderr } = await execFileAsync("systemctl", args, {
|
||||
encoding: "utf8",
|
||||
});
|
||||
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,
|
||||
};
|
||||
}
|
||||
return await execFileUtf8("systemctl", args);
|
||||
}
|
||||
|
||||
export async function isSystemdUserServiceAvailable(): Promise<boolean> {
|
||||
|
||||
Reference in New Issue
Block a user