2021-09-10 08:17:20 -05:00
/ *
2023-02-13 22:31:19 -06: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 02:22:36 -06:00
* ⚠ ️ Deprecated : Changed to healthcheck . go , it will be deleted in the future .
2021-09-10 08:17:20 -05:00
* This script should be run after a period of time ( 180 s ) , because the server may need some time to prepare .
* /
2023-12-10 06:40:40 -06:00
const FBSD = /^freebsd/ . test ( process . platform ) ;
2021-11-01 12:13:05 -05:00
2021-09-07 03:06:28 -05:00
process . env . NODE _TLS _REJECT _UNAUTHORIZED = "0" ;
let client ;
2021-11-01 12:13:05 -05:00
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 ) {
2021-09-07 03:06:28 -05:00
client = require ( "https" ) ;
} else {
client = require ( "http" ) ;
}
2021-11-01 12:13:05 -05:00
// 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 (::)
2023-02-13 10:46:22 -06:00
let hostname = process . env . UPTIME _KUMA _HOST ;
2021-11-01 12:13:05 -05:00
2022-01-11 06:39:45 -06:00
// Also read HOST if not *BSD, as HOST is a system environment variable in FreeBSD
2022-01-11 11:44:01 -06:00
if ( ! hostname && ! FBSD ) {
2021-11-01 12:13:05 -05:00
hostname = process . env . HOST ;
}
2023-02-13 10:46:22 -06:00
const port = parseInt ( process . env . UPTIME _KUMA _PORT || process . env . PORT || 3001 ) ;
2021-11-01 12:13:05 -05:00
2021-08-09 00:49:37 -05:00
let options = {
2023-02-13 10:46:22 -06:00
host : hostname || "127.0.0.1" ,
2021-11-01 12:13:05 -05:00
port : port ,
2021-09-08 22:41:28 -05:00
timeout : 28 * 1000 ,
2021-07-17 09:37:35 -05:00
} ;
2021-09-07 03:06:28 -05:00
let request = client . request ( options , ( res ) => {
console . log ( ` Health Check OK [Res Code: ${ res . statusCode } ] ` ) ;
2021-11-02 09:03:02 -05:00
if ( res . statusCode === 302 ) {
2021-08-09 00:49:37 -05:00
process . exit ( 0 ) ;
} else {
process . exit ( 1 ) ;
}
2021-07-17 09:37:35 -05:00
} ) ;
2021-09-07 03:06:28 -05:00
2021-07-17 09:37:35 -05:00
request . on ( "error" , function ( err ) {
2021-09-07 03:06:28 -05:00
console . error ( "Health Check ERROR" ) ;
2021-08-09 00:49:37 -05:00
process . exit ( 1 ) ;
2021-07-17 09:37:35 -05:00
} ) ;
2021-09-07 03:06:28 -05:00
2021-07-17 09:37:35 -05:00
request . end ( ) ;