forked from leinstay/discobot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrestart.js
More file actions
26 lines (22 loc) · 732 Bytes
/
Copy pathrestart.js
File metadata and controls
26 lines (22 loc) · 732 Bytes
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
const { exec } = require('child_process');
const CronJob = require('cron').CronJob;
const restartCommand = "pm2 restart DiscoBot";
const listCommand = "pm2 list";
console.log("Starting bot restart process.");
const restartApp = function () {
exec(restartCommand, (err, stdout, stderr) => {
if (!err && !stderr) {
console.log(new Date(), `App restarted.`);
listApps();
} else if (err || stderr) {
console.log(new Date(), `Error in executing ${restartCommand}`, err || stderr);
}
});
}
function listApps() {
exec(listCommand, (err, stdout, stderr) => {
console.log(`pm2 list`);
console.log(`${stdout}`);
});
}
new CronJob('0 0 */3 * * *', restartApp(), null, true, 'Europe/Moscow');