You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
1.6 KiB
91 lines
1.6 KiB
/*
|
|
* If changed, have to run `npm run build-docker-builder-go`.
|
|
* This script should be run after a period of time (180s), because the server may need some time to prepare.
|
|
*/
|
|
package main
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"io/ioutil"
|
|
"log"
|
|
"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,
|
|
}
|
|
|
|
client := http.Client{
|
|
Timeout: 28 * time.Second,
|
|
}
|
|
|
|
sslKey := os.Getenv("UPTIME_KUMA_SSL_KEY")
|
|
if sslKey == "" {
|
|
sslKey = os.Getenv("SSL_KEY")
|
|
}
|
|
|
|
sslCert := os.Getenv("UPTIME_KUMA_SSL_CERT")
|
|
if sslCert == "" {
|
|
sslCert = os.Getenv("SSL_CERT")
|
|
}
|
|
|
|
hostname := os.Getenv("UPTIME_KUMA_HOST")
|
|
if hostname == "" && !isFreeBSD {
|
|
hostname = os.Getenv("HOST")
|
|
}
|
|
if hostname == "" {
|
|
hostname = "127.0.0.1"
|
|
}
|
|
|
|
port := ""
|
|
// UPTIME_KUMA_PORT is override by K8S unexpectedly,
|
|
if !isK8s {
|
|
port = os.Getenv("UPTIME_KUMA_PORT")
|
|
}
|
|
if port == "" {
|
|
port = os.Getenv("PORT")
|
|
}
|
|
if port == "" {
|
|
port = "3001"
|
|
}
|
|
|
|
protocol := ""
|
|
if sslKey != "" && sslCert != "" {
|
|
protocol = "https"
|
|
} else {
|
|
protocol = "http"
|
|
}
|
|
|
|
url := protocol + "://" + hostname + ":" + port
|
|
|
|
log.Println("Checking " + url)
|
|
resp, err := client.Get(url)
|
|
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
_, err = ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
log.Printf("Health Check OK [Res Code: %d]\n", resp.StatusCode)
|
|
|
|
}
|