health_check.go 884 B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright 2021 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package cli // import "miniflux.app/cli"
  5. import (
  6. "net/http"
  7. "time"
  8. "miniflux.app/config"
  9. "miniflux.app/logger"
  10. )
  11. func doHealthCheck(healthCheckEndpoint string) {
  12. if healthCheckEndpoint == "auto" {
  13. healthCheckEndpoint = "http://" + config.Opts.ListenAddr() + config.Opts.BasePath() + "/healthcheck"
  14. }
  15. logger.Debug(`Executing health check on %s`, healthCheckEndpoint)
  16. client := &http.Client{Timeout: 3 * time.Second}
  17. resp, err := client.Get(healthCheckEndpoint)
  18. if err != nil {
  19. logger.Fatal(`Health check failure: %v`, err)
  20. }
  21. defer resp.Body.Close()
  22. if resp.StatusCode != 200 {
  23. logger.Fatal(`Health check failed with status code %d`, resp.StatusCode)
  24. }
  25. logger.Debug(`Health check is OK`)
  26. }