mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 07:21:23 +00:00
refactor: centralize daemon path resolution
This commit is contained in:
@@ -16,6 +16,7 @@ import {
|
||||
} from "./launchd-plist.js";
|
||||
import { parseKeyValueOutput } from "./runtime-parse.js";
|
||||
import type { GatewayServiceRuntime } from "./service-runtime.js";
|
||||
import { resolveGatewayStateDir, resolveHomeDir } from "./paths.js";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
|
||||
@@ -29,11 +30,6 @@ function resolveLaunchAgentLabel(args?: { env?: Record<string, string | undefine
|
||||
if (envLabel) return envLabel;
|
||||
return resolveGatewayLaunchAgentLabel(args?.env?.CLAWDBOT_PROFILE);
|
||||
}
|
||||
function resolveHomeDir(env: Record<string, string | undefined>): string {
|
||||
const home = env.HOME?.trim() || env.USERPROFILE?.trim();
|
||||
if (!home) throw new Error("Missing HOME");
|
||||
return home;
|
||||
}
|
||||
|
||||
function resolveLaunchAgentPlistPathForLabel(
|
||||
env: Record<string, string | undefined>,
|
||||
@@ -53,12 +49,7 @@ export function resolveGatewayLogPaths(env: Record<string, string | undefined>):
|
||||
stdoutPath: string;
|
||||
stderrPath: string;
|
||||
} {
|
||||
const home = resolveHomeDir(env);
|
||||
const stateOverride = env.CLAWDBOT_STATE_DIR?.trim();
|
||||
const profile = env.CLAWDBOT_PROFILE?.trim();
|
||||
const suffix = profile && profile.toLowerCase() !== "default" ? `-${profile}` : "";
|
||||
const defaultStateDir = path.join(home, `.clawdbot${suffix}`);
|
||||
const stateDir = stateOverride ? resolveUserPathWithHome(stateOverride, home) : defaultStateDir;
|
||||
const stateDir = resolveGatewayStateDir(env);
|
||||
const logDir = path.join(stateDir, "logs");
|
||||
return {
|
||||
logDir,
|
||||
@@ -67,16 +58,6 @@ export function resolveGatewayLogPaths(env: Record<string, string | undefined>):
|
||||
};
|
||||
}
|
||||
|
||||
function resolveUserPathWithHome(input: string, home: string): string {
|
||||
const trimmed = input.trim();
|
||||
if (!trimmed) return trimmed;
|
||||
if (trimmed.startsWith("~")) {
|
||||
const expanded = trimmed.replace(/^~(?=$|[\\/])/, home);
|
||||
return path.resolve(expanded);
|
||||
}
|
||||
return path.resolve(trimmed);
|
||||
}
|
||||
|
||||
export async function readLaunchAgentProgramArguments(
|
||||
env: Record<string, string | undefined>,
|
||||
): Promise<{
|
||||
|
||||
Reference in New Issue
Block a user