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