Update MineGeo domain and harden process supervision
All checks were successful
Deploy MineGeo to Dokploy / deploy (push) Successful in 5m57s
All checks were successful
Deploy MineGeo to Dokploy / deploy (push) Successful in 5m57s
This commit is contained in:
@@ -13,12 +13,19 @@ function run(args) {
|
||||
windowsHide: true,
|
||||
});
|
||||
children.push(c);
|
||||
c.on("exit", (code) => {
|
||||
c.on("error", (error) => {
|
||||
if (!stopping) {
|
||||
console.error(`Unable to start MineGeo process: ${error.message}`);
|
||||
stop(1);
|
||||
}
|
||||
});
|
||||
c.on("exit", (code, signal) => {
|
||||
if (!stopping) {
|
||||
const reason = code === null ? `signal ${signal ?? "unknown"}` : `code ${code}`;
|
||||
console.error(
|
||||
`MineGeo process exited (${code}). Shutting down companion process.`,
|
||||
`MineGeo process exited (${reason}). Shutting down companion process.`,
|
||||
);
|
||||
stop(code ?? 1);
|
||||
stop(code === 0 ? 1 : (code ?? 1));
|
||||
}
|
||||
});
|
||||
return c;
|
||||
@@ -26,8 +33,30 @@ function run(args) {
|
||||
function stop(code = 0) {
|
||||
if (stopping) return;
|
||||
stopping = true;
|
||||
for (const c of children) c.kill("SIGTERM");
|
||||
setTimeout(() => process.exit(code), 500).unref();
|
||||
const running = (child) => child.exitCode === null && child.signalCode === null;
|
||||
for (const c of children) {
|
||||
if (running(c)) c.kill("SIGTERM");
|
||||
}
|
||||
|
||||
const forceStop = setTimeout(() => {
|
||||
for (const c of children) {
|
||||
if (running(c)) c.kill("SIGKILL");
|
||||
}
|
||||
process.exit(code);
|
||||
}, 8_000);
|
||||
|
||||
Promise.all(
|
||||
children.map(
|
||||
(c) =>
|
||||
new Promise((resolve) => {
|
||||
if (!running(c)) resolve();
|
||||
else c.once("close", resolve);
|
||||
}),
|
||||
),
|
||||
).then(() => {
|
||||
clearTimeout(forceStop);
|
||||
process.exitCode = code;
|
||||
});
|
||||
}
|
||||
process.on("SIGINT", () => stop());
|
||||
process.on("SIGTERM", () => stop());
|
||||
|
||||
Reference in New Issue
Block a user