19 lines
877 B
JavaScript
19 lines
877 B
JavaScript
import { spawn } from "node:child_process";
|
|
const children = [
|
|
spawn(process.execPath, ["--import", "./apps/server/node_modules/tsx/dist/loader.mjs", "apps/server/src/index.ts"], { stdio: "inherit" }),
|
|
spawn(process.execPath, ["sandbox/web.mjs"], { stdio: "inherit" }),
|
|
];
|
|
let stopping = false;
|
|
function stop(code) {
|
|
if (stopping) return;
|
|
stopping = true;
|
|
children.forEach(child => child.kill("SIGTERM"));
|
|
setTimeout(() => { children.forEach(child => child.kill("SIGKILL")); process.exit(code); }, 5000);
|
|
}
|
|
children.forEach(child => { child.on("error", () => stop(1)); child.on("exit", () => stop(stopping ? 0 : 1)); });
|
|
process.on("SIGTERM", () => stop(0));
|
|
process.on("SIGINT", () => stop(0));
|
|
const ttl = Number(process.env.SANDBOX_TTL_SECONDS ?? 3600);
|
|
if (!Number.isInteger(ttl) || ttl < 30 || ttl > 86400) stop(1);
|
|
else setTimeout(() => stop(0), ttl * 1000);
|