Add logging to cleanup catch blocks, use pkill -f agent.py instead of killall python3

This commit is contained in:
2026-04-08 01:50:03 +00:00
parent e685a2a7ba
commit deca7228c7

View File

@@ -300,7 +300,7 @@ export async function stopAgent(name: string) {
try { try {
execFileSync( execFileSync(
"ssh", "ssh",
[...SSH_OPTS, `root@${info.ip}`, "killall python3 2>/dev/null; sleep 1"], [...SSH_OPTS, `root@${info.ip}`, "pkill -f 'agent.py' 2>/dev/null; sleep 1"],
{ stdio: "pipe", timeout: 5_000 } { stdio: "pipe", timeout: 5_000 }
); );
} catch { } catch {
@@ -358,18 +358,10 @@ export function listAgents(): AgentInfo[] {
} catch { } catch {
// Process is dead, clean up // Process is dead, clean up
log(`Agent "${name}" is dead, cleaning up...`); log(`Agent "${name}" is dead, cleaning up...`);
try { try { deleteTap(info.tapDevice); } catch (e) { log(` tap cleanup: ${e}`); }
deleteTap(info.tapDevice); try { releaseIp(info.octet); } catch (e) { log(` ip cleanup: ${e}`); }
} catch {} try { unlinkSync(info.rootfsPath); } catch (e) { log(` rootfs cleanup: ${e}`); }
try { try { unlinkSync(info.socketPath); } catch (e) { log(` socket cleanup: ${e}`); }
releaseIp(info.octet);
} catch {}
try {
unlinkSync(info.rootfsPath);
} catch {}
try {
unlinkSync(info.socketPath);
} catch {}
delete agents[name]; delete agents[name];
} }
} }
@@ -430,7 +422,7 @@ export async function reloadAgent(
// Signal agent to reload // Signal agent to reload
execFileSync( execFileSync(
"ssh", "ssh",
[...SSH_OPTS, sshTarget, "killall -HUP python3"], [...SSH_OPTS, sshTarget, "pkill -HUP -f 'agent.py'"],
{ stdio: "pipe", timeout: 10_000 } { stdio: "pipe", timeout: 10_000 }
); );
} catch (err) { } catch (err) {
@@ -460,11 +452,10 @@ export function reconcileAgents(): { adopted: string[]; cleaned: string[] } {
log(`Adopted running agent "${name}" (PID ${info.pid}, ${info.ip})`); log(`Adopted running agent "${name}" (PID ${info.pid}, ${info.ip})`);
} else { } else {
log(`Cleaning dead agent "${name}" (PID ${info.pid} gone)...`); log(`Cleaning dead agent "${name}" (PID ${info.pid} gone)...`);
// Clean up resources from dead agent try { deleteTap(info.tapDevice); } catch (e) { log(` tap: ${e}`); }
try { deleteTap(info.tapDevice); } catch {} try { releaseIp(info.octet); } catch (e) { log(` ip: ${e}`); }
try { releaseIp(info.octet); } catch {} try { unlinkSync(info.rootfsPath); } catch (e) { log(` rootfs: ${e}`); }
try { unlinkSync(info.rootfsPath); } catch {} try { unlinkSync(info.socketPath); } catch (e) { log(` socket: ${e}`); }
try { unlinkSync(info.socketPath); } catch {}
delete agents[name]; delete agents[name];
cleaned.push(name); cleaned.push(name);
} }