From b38206438489c6fa3d8d6a382e8326aba39fad29 Mon Sep 17 00:00:00 2001 From: Kyle <3204236+DevKyleS@users.noreply.github.com> Date: Tue, 13 Sep 2022 21:52:32 -0600 Subject: [PATCH 1/5] Replace port env var in healthcheck.js --- extra/healthcheck.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/healthcheck.js b/extra/healthcheck.js index 7c3a7eb42..3a7661082 100644 --- a/extra/healthcheck.js +++ b/extra/healthcheck.js @@ -25,7 +25,7 @@ if (!hostname && !FBSD) { hostname = process.env.HOST; } -const port = parseInt(process.env.UPTIME_KUMA_PORT || process.env.PORT || 3001); +const port = parseInt(process.env.UPTIME_KUMA_SERVICE_PORT || process.env.PORT || 3001); let options = { host: hostname || "127.0.0.1", From b4f0f8bca5b62a9fe12d913504b842c3da81cf73 Mon Sep 17 00:00:00 2001 From: Kyle <3204236+DevKyleS@users.noreply.github.com> Date: Tue, 13 Sep 2022 22:18:00 -0600 Subject: [PATCH 2/5] Replace healthcheck hostname env variable name --- extra/healthcheck.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/healthcheck.js b/extra/healthcheck.js index 3a7661082..9e5e4e3d8 100644 --- a/extra/healthcheck.js +++ b/extra/healthcheck.js @@ -18,7 +18,7 @@ if (sslKey && sslCert) { // 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; +let hostname = process.env.UPTIME_KUMA_SERVICE_HOST; // Also read HOST if not *BSD, as HOST is a system environment variable in FreeBSD if (!hostname && !FBSD) { From db4b2cd984e9b7dd82e0af5995e7235eb2f67517 Mon Sep 17 00:00:00 2001 From: Kyle <3204236+DevKyleS@users.noreply.github.com> Date: Wed, 14 Sep 2022 14:25:56 -0600 Subject: [PATCH 3/5] Re-add support for UPTIME_KUMA_HOST and _PORT in healthcheck.js --- extra/healthcheck.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extra/healthcheck.js b/extra/healthcheck.js index 9e5e4e3d8..0c35fe2f5 100644 --- a/extra/healthcheck.js +++ b/extra/healthcheck.js @@ -18,17 +18,17 @@ if (sslKey && sslCert) { // 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_SERVICE_HOST; +let hostname = process.env.UPTIME_KUMA_SERVICE_HOST || process.env.UPTIME_KUMA_HOST || "127.0.0.1"; // Also read HOST if not *BSD, as HOST is a system environment variable in FreeBSD if (!hostname && !FBSD) { hostname = process.env.HOST; } -const port = parseInt(process.env.UPTIME_KUMA_SERVICE_PORT || process.env.PORT || 3001); +const port = parseInt(process.env.UPTIME_KUMA_SERVICE_PORT || process.env.UPTIME_KUMA_PORT || process.env.PORT || 3001); let options = { - host: hostname || "127.0.0.1", + host: hostname, port: port, timeout: 28 * 1000, }; From 7aa3f6c559f1624442e0f0239eca5c31bdf61ab0 Mon Sep 17 00:00:00 2001 From: Kyle <3204236+DevKyleS@users.noreply.github.com> Date: Wed, 14 Sep 2022 15:04:21 -0600 Subject: [PATCH 4/5] Corrected default hostname port for healthcheck --- extra/healthcheck.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/healthcheck.js b/extra/healthcheck.js index 0c35fe2f5..a169f1f43 100644 --- a/extra/healthcheck.js +++ b/extra/healthcheck.js @@ -18,7 +18,7 @@ if (sslKey && sslCert) { // 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_SERVICE_HOST || process.env.UPTIME_KUMA_HOST || "127.0.0.1"; +let hostname = process.env.UPTIME_KUMA_SERVICE_HOST || process.env.UPTIME_KUMA_HOST || "::"; // Also read HOST if not *BSD, as HOST is a system environment variable in FreeBSD if (!hostname && !FBSD) { From 4fb43034cda45230dd58bccbae50c8774d39b40d Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Mon, 30 Jan 2023 21:46:27 +0800 Subject: [PATCH 5/5] Handle k8s in healthcheck.go --- extra/healthcheck.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/extra/healthcheck.go b/extra/healthcheck.go index 302883d84..f79b3e65b 100644 --- a/extra/healthcheck.go +++ b/extra/healthcheck.go @@ -11,12 +11,17 @@ import ( "net/http" "os" "runtime" + "strings" "time" ) func main() { isFreeBSD := runtime.GOOS == "freebsd" + // Is K8S + uptime-kuma as the container name + // See #2083 + isK8s := strings.HasPrefix(os.Getenv("UPTIME_KUMA_PORT"), "tcp://") + // process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{ InsecureSkipVerify: true, @@ -44,7 +49,11 @@ func main() { hostname = "127.0.0.1" } - port := os.Getenv("UPTIME_KUMA_PORT") + port := "" + // UPTIME_KUMA_PORT is override by K8S unexpectedly, + if !isK8s { + port = os.Getenv("UPTIME_KUMA_PORT") + } if len(port) == 0 { port = os.Getenv("PORT") }