forked from KriganLabs/ZacrosBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (38 loc) · 972 Bytes
/
index.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
const { spawn } = require("child_process");
const path = require("path");
const fs = require("fs");
var isRunning = false;
function start(file) {
if (isRunning) return;
isRunning = true;
let pathFile = [path.join(__dirname, file), ...process.argv.slice(2)];
let run = spawn(process.argv[0], pathFile, {
stdio: ["inherit", "inherit", "inherit", "ipc"],
});
run.on("message", (data) => {
switch (data) {
case "reset":
run.kill();
isRunning = false;
start.apply(this, arguments);
break;
case "uptime":
run.send(process.uptime());
break;
case "close":
run.kill();
process.kill();
break;
}
});
run.on("exit", (code) => {
isRunning = false;
if (code == 1) return process.kill();
console.error("Exited with code:", code);
fs.watchFile(pathFile[0], () => {
fs.unwatchFile(pathFile[0]);
start(file);
});
});
}
start("main.js");