2023-06-19 17:42:47 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2021-02-20 15:42:15 -05:00
|
|
|
|
2023-08-10 22:46:45 -04:00
|
|
|
package cli // import "miniflux.app/v2/internal/cli"
|
2021-02-20 15:42:15 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
2023-08-10 22:46:45 -04:00
|
|
|
"miniflux.app/v2/internal/config"
|
|
|
|
"miniflux.app/v2/internal/logger"
|
2021-02-20 15:42:15 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func doHealthCheck(healthCheckEndpoint string) {
|
|
|
|
if healthCheckEndpoint == "auto" {
|
|
|
|
healthCheckEndpoint = "http://" + config.Opts.ListenAddr() + config.Opts.BasePath() + "/healthcheck"
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.Debug(`Executing health check on %s`, healthCheckEndpoint)
|
|
|
|
|
|
|
|
client := &http.Client{Timeout: 3 * time.Second}
|
|
|
|
resp, err := client.Get(healthCheckEndpoint)
|
|
|
|
if err != nil {
|
|
|
|
logger.Fatal(`Health check failure: %v`, err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
if resp.StatusCode != 200 {
|
|
|
|
logger.Fatal(`Health check failed with status code %d`, resp.StatusCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.Debug(`Health check is OK`)
|
|
|
|
}
|