|
const { spawn, execSync, exec } = require("child_process"); |
|
function startBot(message) { |
|
(message) ? console.log(message) : ""; |
|
|
|
const child = spawn("node main.js", { |
|
cwd: __dirname, |
|
stdio: "inherit", |
|
shell: true |
|
}); |
|
|
|
child.on("close", (codeExit) => { |
|
if (codeExit != 0 || global.countRestart && global.countRestart < 5) { |
|
startBot("Restarting..."); |
|
global.countRestart += 1; |
|
return; |
|
} else return; |
|
}); |
|
|
|
child.on("error", function (error) { |
|
console.log("An error occurred: " + JSON.stringify(error)); |
|
}); |
|
}; |
|
startBot() |
|
console.log("start") |