-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (32 loc) · 1014 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
40
41
const rq = require('request-promise-native');
const {
exec
} = require('child_process');
const config = require('./config.json');
// CSMM might need longer than the configured check interval to reboot.
var restarting = false;
main();
async function main() {
let interval = setInterval(async () => {
try {
let response = await rq(config.url);
// Check if the response includes a certain string, if it doesn't we are likely on a error page (cloudflare for example)
if (!response.includes(config.stringToCheck)) {
restart();
}
} catch (error) {
// If request fails, it means the site is down -> restart.
restart();
}
}, config.interval)
}
async function restart() {
if (!restarting) {
restarting = true;
exec(config.restartCommand, () => {
setTimeout(() => {
restarting = false;
}, config.restartCooldown)
})
}
}