fix(cutover): track direct detached listener pid
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { spawn, execFile } from 'node:child_process';
|
||||
import { execFile, execFileSync } from 'node:child_process';
|
||||
import { constants } from 'node:fs';
|
||||
import {
|
||||
access,
|
||||
@@ -159,14 +159,22 @@ export const nodeCutoverSystem: CutoverSystem = {
|
||||
throw new Error(`PID ${pid} did not exit after SIGTERM`);
|
||||
},
|
||||
start(argv, environment) {
|
||||
const child = spawn(argv[0], argv.slice(1), {
|
||||
detached: true,
|
||||
stdio: 'ignore',
|
||||
env: environment ?? process.env,
|
||||
});
|
||||
child.unref();
|
||||
if (!child.pid) throw new Error('Failed to start command');
|
||||
return child.pid;
|
||||
const output = execFileSync(
|
||||
'/usr/bin/python3',
|
||||
[
|
||||
'-c',
|
||||
'import os,sys; pid=os.fork(); print(pid, flush=True); pid and sys.exit(0); os.setsid(); os.execve(sys.argv[1], sys.argv[1:], dict(os.environ))',
|
||||
...argv,
|
||||
],
|
||||
{
|
||||
encoding: 'utf8',
|
||||
env: environment ?? process.env,
|
||||
stdio: ['ignore', 'pipe', 'ignore'],
|
||||
},
|
||||
);
|
||||
const pid = Number(output.trim());
|
||||
if (!Number.isSafeInteger(pid) || pid <= 1) throw new Error('Failed to start command');
|
||||
return pid;
|
||||
},
|
||||
delay: (milliseconds) => new Promise((resolveWait) => setTimeout(resolveWait, milliseconds)),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user