2023-06-19 23:42:47 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2021-02-20 21:42:15 +01:00
|
|
|
|
2023-08-11 04:46:45 +02:00
|
|
|
package cli // import "miniflux.app/v2/internal/cli"
|
2021-02-20 21:42:15 +01:00
|
|
|
|
|
|
|
import (
|
2023-09-25 01:32:09 +02:00
|
|
|
"fmt"
|
|
|
|
"log/slog"
|
2021-02-20 21:42:15 +01:00
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
2023-08-11 04:46:45 +02:00
|
|
|
"miniflux.app/v2/internal/config"
|
2021-02-20 21:42:15 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func doHealthCheck(healthCheckEndpoint string) {
|
|
|
|
if healthCheckEndpoint == "auto" {
|
|
|
|
healthCheckEndpoint = "http://" + config.Opts.ListenAddr() + config.Opts.BasePath() + "/healthcheck"
|
|
|
|
}
|
|
|
|
|
2023-09-25 01:32:09 +02:00
|
|
|
slog.Debug("Executing health check request", slog.String("endpoint", healthCheckEndpoint))
|
2021-02-20 21:42:15 +01:00
|
|
|
|
|
|
|
client := &http.Client{Timeout: 3 * time.Second}
|
|
|
|
resp, err := client.Get(healthCheckEndpoint)
|
|
|
|
if err != nil {
|
2023-09-25 01:32:09 +02:00
|
|
|
printErrorAndExit(fmt.Errorf(`health check failure: %v`, err))
|
2021-02-20 21:42:15 +01:00
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
if resp.StatusCode != 200 {
|
2023-09-25 01:32:09 +02:00
|
|
|
printErrorAndExit(fmt.Errorf(`health check failed with status code %d`, resp.StatusCode))
|
2021-02-20 21:42:15 +01:00
|
|
|
}
|
|
|
|
|
2023-09-25 01:32:09 +02:00
|
|
|
slog.Debug(`Health check is passing`)
|
2021-02-20 21:42:15 +01:00
|
|
|
}
|