forked from CraigChat/craig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcraig-runner.js
executable file
·38 lines (32 loc) · 935 Bytes
/
craig-runner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env node
const cp = require("child_process");
var craig = null;
function launch(activeRecordings) {
var me = craig = cp.fork("./craig.js", [], {
stdio: ["ignore", "inherit", "inherit", "ipc"]
});
me.on("message", (val) => {
if (typeof val !== "object")
return;
switch (val.t) {
case "gracefulRestart":
launch(val.activeRecordings);
break;
case "requestActiveRecordings":
me.send({t: "activeRecordings", "activeRecordings": activeRecordings});
break;
case "gracelessRestart":
process.exit(0);
break;
}
});
function relaunch() {
if (me === craig) {
craig = null;
setTimeout(() => { launch(); }, 10000);
}
}
me.on("error", relaunch);
me.on("exit", relaunch);
}
launch({});