mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 03:11:25 +00:00
CLI: fix gateway restart health ownership for child listener pids (#24696)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: d6d4b43f7e
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
committed by
GitHub
parent
78e7f41d28
commit
5de1f540e7
@@ -75,6 +75,16 @@ async function resolveUnixUser(pid: number): Promise<string | undefined> {
|
||||
return line || undefined;
|
||||
}
|
||||
|
||||
async function resolveUnixParentPid(pid: number): Promise<number | undefined> {
|
||||
const res = await runCommandSafe(["ps", "-p", String(pid), "-o", "ppid="]);
|
||||
if (res.code !== 0) {
|
||||
return undefined;
|
||||
}
|
||||
const line = res.stdout.trim();
|
||||
const parentPid = Number.parseInt(line, 10);
|
||||
return Number.isFinite(parentPid) && parentPid > 0 ? parentPid : undefined;
|
||||
}
|
||||
|
||||
async function readUnixListeners(
|
||||
port: number,
|
||||
): Promise<{ listeners: PortListener[]; detail?: string; errors: string[] }> {
|
||||
@@ -88,9 +98,10 @@ async function readUnixListeners(
|
||||
if (!listener.pid) {
|
||||
return;
|
||||
}
|
||||
const [commandLine, user] = await Promise.all([
|
||||
const [commandLine, user, parentPid] = await Promise.all([
|
||||
resolveUnixCommandLine(listener.pid),
|
||||
resolveUnixUser(listener.pid),
|
||||
resolveUnixParentPid(listener.pid),
|
||||
]);
|
||||
if (commandLine) {
|
||||
listener.commandLine = commandLine;
|
||||
@@ -98,6 +109,9 @@ async function readUnixListeners(
|
||||
if (user) {
|
||||
listener.user = user;
|
||||
}
|
||||
if (parentPid !== undefined) {
|
||||
listener.ppid = parentPid;
|
||||
}
|
||||
}),
|
||||
);
|
||||
return { listeners, detail: res.stdout.trim() || undefined, errors };
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
export type PortListener = {
|
||||
pid?: number;
|
||||
ppid?: number;
|
||||
command?: string;
|
||||
commandLine?: string;
|
||||
user?: string;
|
||||
|
||||
Reference in New Issue
Block a user