mirror of https://github.com/Lissy93/dashy.git
♻️ Refactors Docker healthcheck script
This commit is contained in:
parent
fd29c1248e
commit
c717134b08
|
@ -13,7 +13,7 @@ const timeout = 2000;
|
||||||
|
|
||||||
const requestOptions = { host, port, timeout };
|
const requestOptions = { host, port, timeout };
|
||||||
|
|
||||||
const startTime = new Date();
|
const startTime = new Date(); // Initialize timestamp to calculate time taken
|
||||||
|
|
||||||
console.log(`[${startTime}] Running health check...`);
|
console.log(`[${startTime}] Running health check...`);
|
||||||
|
|
||||||
|
@ -23,14 +23,13 @@ const healthCheck = http.request(requestOptions, (response) => {
|
||||||
const status = response.statusCode;
|
const status = response.statusCode;
|
||||||
const color = status === 200 ? '\x1b[32m' : '\x1b[31m';
|
const color = status === 200 ? '\x1b[32m' : '\x1b[31m';
|
||||||
const message = `${color}Status: ${status}\nRequest took ${totalTime} seconds\n\x1b[0m---`;
|
const message = `${color}Status: ${status}\nRequest took ${totalTime} seconds\n\x1b[0m---`;
|
||||||
console.log(message);
|
console.log(message); // Print out healthcheck response
|
||||||
if (status == 200) { process.exit(0); }
|
process.exit(status === 200 ? 0 : 1); // Exit with 0 (success), if response is 200 okay
|
||||||
else { process.exit(1); }
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/* If the server is not running, then print the error code, and exit with 1 */
|
/* If the server is not running, then print the error code, and exit with 1 */
|
||||||
healthCheck.on('error', (err) => {
|
healthCheck.on('error', (err) => {
|
||||||
console.error(`\x1b[31mHealthceck Failed, Error: ${'\033[4m'}${err.code}\x1b[0m`);
|
console.error(`\x1b[31mHealthceck Failed, Error: ${'\x1b[33m'}${err.code}\x1b[0m`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue