forked from xbrowsersync/api-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
healthcheck.js
44 lines (39 loc) · 860 Bytes
/
healthcheck.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
42
43
44
const http = require('http');
const response = http.request(
{
host: '0.0.0.0',
method: 'GET',
path: '/info',
port: 8080,
timeout: 2000,
},
(res) => {
let body = '';
res.setEncoding('utf8');
res.on('data', (chunk) => {
body += chunk;
});
res.on('end', () => {
if (res.statusCode === 200) {
const payload = JSON.parse(body);
switch (payload.status) {
case 1:
case 3:
console.log('HEALTHCHECK: online');
process.exit(0);
case 2:
default:
console.log('HEALTHCHECK: offline');
}
} else {
console.log('HEALTHCHECK: offline');
}
process.exit(1);
});
}
);
response.on('error', function (err) {
console.log('HEALTHCHECK: offline');
process.exit(1);
});
response.end();