-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.js
More file actions
43 lines (36 loc) · 1.11 KB
/
Copy pathindex.js
File metadata and controls
43 lines (36 loc) · 1.11 KB
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
43
const { spawn } = require("child_process");
const path = require("path");
const { logger } = require("./system/logger");
const SCRIPT_FILE = "main.js";
const SCRIPT_PATH = path.join(__dirname, SCRIPT_FILE);
const restartEnabled = process.env.PID !== "0";
// ok sir
let mainProcess;
function start() {
mainProcess = spawn("node", ["--no-deprecation", "--no-warnings", SCRIPT_PATH], {
cwd: __dirname,
stdio: "inherit",
shell: true,
});
mainProcess.on("error", (err) => {
logger.error("Error occurred while starting the process:", err);
});
mainProcess.on("close", (exitCode) => {
console.log(`Process exited with code [${exitCode}]`);
if (restartEnabled) {
logger.success("Restarting process...");
restartProcess();
} else {
console.log("Shutdown initiated...");
process.exit(exitCode);
}
});
}
function restartProcess() {
if (mainProcess && mainProcess.pid) {
mainProcess.kill("SIGKILL");
logger.success("Main process killed. Restarting...");
}
start();
}
start();