fix(cutover): use direct detached spawn

This commit is contained in:
chick
2026-07-18 18:36:26 +08:00
parent 0b775b29bc
commit e390069edb
+9 -17
View File
@@ -1,4 +1,4 @@
import { execFile, execFileSync } from 'node:child_process';
import { execFile, spawn } from 'node:child_process';
import { constants } from 'node:fs';
import {
access,
@@ -159,22 +159,14 @@ export const nodeCutoverSystem: CutoverSystem = {
throw new Error(`PID ${pid} did not exit after SIGTERM`);
},
start(argv, environment) {
const output = execFileSync(
'/usr/bin/python3',
[
'-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,
stdio: ['ignore', 'pipe', 'ignore'],
},
);
const pid = Number(output.trim().split(/\s+/u)[0]);
if (!Number.isSafeInteger(pid) || pid <= 1) throw new Error('Failed to start command');
return pid;
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;
},
delay: (milliseconds) => new Promise((resolveWait) => setTimeout(resolveWait, milliseconds)),
};