-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.js
42 lines (32 loc) · 987 Bytes
/
run.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
39
40
41
42
const { spawn } = require("child_process");
const path = require("path");
function run(count) {
if(count > 4) {
console.log("Tried too many times and it's always being blocked.");
return;
}
console.log("node path: ", process.execPath);
const exec = spawn(process.execPath, [path.join(__dirname, "app.js")], {
env: {
NODE_ENV: "production",
PATH: process.env.PATH,
},
});
exec.stdout.on("data", (data) => {
console.log(`stdout: ${data}`);
});
exec.stderr.on("data", (data) => {
console.error(`stderr: ${data}`);
});
exec.on("close", (code) => {
console.log(`child process exited with code ${code}`);
if (code != 0) {
console.log("Going to restart after 30 minutes.");
setTimeout(() => {
console.log("Restarting...");
run(count + 1);
}, 1800000 * count);
}
});
}
run(1);