Skip to content

Commit

Permalink
Merge pull request #2083 from DevKyleS/patch-1
Browse files Browse the repository at this point in the history
Bugfix: Fix healthcheck port value in healthcheck.js for Kubernetes support
  • Loading branch information
louislam authored Jan 30, 2023
2 parents 664da4a + 4fb4303 commit ce82ad1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 10 additions & 1 deletion extra/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
}
Expand Down
6 changes: 3 additions & 3 deletions extra/healthcheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,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_HOST;
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) {
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.UPTIME_KUMA_PORT || process.env.PORT || 3001);

let options = {
host: hostname || "127.0.0.1",
host: hostname,
port: port,
timeout: 28 * 1000,
};
Expand Down

0 comments on commit ce82ad1

Please sign in to comment.