Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/conat/core/start-server.ts
1542 views
1
import { type Options } from "./server";
2
import { fork, type ChildProcess } from "node:child_process";
3
import { join } from "node:path";
4
5
const children: ChildProcess[] = [];
6
export function forkedConatServer(opts: Options) {
7
// this is fragile:
8
const child: ChildProcess = fork(
9
join(
10
__dirname,
11
"..",
12
"..",
13
"..",
14
"server",
15
"dist",
16
"conat",
17
"socketio",
18
"start-cluster-node.js",
19
),
20
);
21
children.push(child);
22
child.send(opts);
23
}
24
25
function close() {
26
children.map((child) => child.kill("SIGKILL"));
27
}
28
29
process.once("exit", () => {
30
close();
31
});
32
33
["SIGTERM", "SIGQUIT"].forEach((sig) => {
34
process.once(sig, () => {
35
children.map((child) => child.kill(sig as any));
36
});
37
});
38
39