uptime-kuma/extra/healthcheck.js

56 lines
1.8 KiB
JavaScript
Raw Normal View History

2021-09-10 06:17:20 -07:00
/*
2023-02-13 20:31:19 -08:00
* Due to the weird issue in Portainer that the healthcheck script is still pointing to this script for unknown reason.
* IT CANNOT BE DROPPED, even though it looks like it is not used.
* See more: https://github.com/louislam/uptime-kuma/issues/2774#issuecomment-1429092359
*
2022-12-07 00:22:36 -08:00
* Deprecated: Changed to healthcheck.go, it will be deleted in the future.
2021-09-10 06:17:20 -07:00
* This script should be run after a period of time (180s), because the server may need some time to prepare.
*/
2022-01-11 09:44:01 -08:00
const { FBSD } = require("../server/util-server");
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
let client;
const sslKey = process.env.UPTIME_KUMA_SSL_KEY || process.env.SSL_KEY || undefined;
const sslCert = process.env.UPTIME_KUMA_SSL_CERT || process.env.SSL_CERT || undefined;
if (sslKey && sslCert) {
client = require("https");
} else {
client = require("http");
}
// If host is omitted, the server will accept connections on the unspecified IPv6 address (::) when IPv6 is available and the unspecified IPv4 address (0.0.0.0) otherwise.
// Dual-stack support for (::)
let hostname = process.env.UPTIME_KUMA_HOST;
2022-01-11 04:39:45 -08:00
// Also read HOST if not *BSD, as HOST is a system environment variable in FreeBSD
2022-01-11 09:44:01 -08:00
if (!hostname && !FBSD) {
hostname = process.env.HOST;
}
const port = parseInt(process.env.UPTIME_KUMA_PORT || process.env.PORT || 3001);
2021-08-08 22:49:37 -07:00
let options = {
host: hostname || "127.0.0.1",
port: port,
timeout: 28 * 1000,
};
let request = client.request(options, (res) => {
console.log(`Health Check OK [Res Code: ${res.statusCode}]`);
2021-11-02 07:03:02 -07:00
if (res.statusCode === 302) {
2021-08-08 22:49:37 -07:00
process.exit(0);
} else {
process.exit(1);
}
});
request.on("error", function (err) {
console.error("Health Check ERROR");
2021-08-08 22:49:37 -07:00
process.exit(1);
});
request.end();