mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 08:14:18 -04:00
Small, trivial cleanup: got triggered because I saw a comment on how health plugins polls other plugins which isn't true. * Remove useless newHealth function * healthParse -> parse * Remove useless constants Net deletion of code. Signed-off-by: Miek Gieben <miek@miek.nl>
72 lines
1.2 KiB
Go
72 lines
1.2 KiB
Go
// Package health implements an HTTP handler that responds to health checks.
|
|
package health
|
|
|
|
import (
|
|
"io"
|
|
"net"
|
|
"net/http"
|
|
"time"
|
|
|
|
clog "github.com/coredns/coredns/plugin/pkg/log"
|
|
)
|
|
|
|
var log = clog.NewWithPlugin("health")
|
|
|
|
// Health implements healthchecks by exporting a HTTP endpoint.
|
|
type health struct {
|
|
Addr string
|
|
lameduck time.Duration
|
|
|
|
ln net.Listener
|
|
nlSetup bool
|
|
mux *http.ServeMux
|
|
|
|
stop chan bool
|
|
}
|
|
|
|
func (h *health) OnStartup() error {
|
|
if h.Addr == "" {
|
|
h.Addr = ":8080"
|
|
}
|
|
|
|
ln, err := net.Listen("tcp", h.Addr)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
h.ln = ln
|
|
h.mux = http.NewServeMux()
|
|
h.nlSetup = true
|
|
|
|
h.mux.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
|
|
// We're always healthy.
|
|
w.WriteHeader(http.StatusOK)
|
|
io.WriteString(w, "OK")
|
|
return
|
|
})
|
|
|
|
go func() { http.Serve(h.ln, h.mux) }()
|
|
go func() { h.overloaded() }()
|
|
|
|
return nil
|
|
}
|
|
|
|
func (h *health) OnRestart() error { return h.OnFinalShutdown() }
|
|
|
|
func (h *health) OnFinalShutdown() error {
|
|
if !h.nlSetup {
|
|
return nil
|
|
}
|
|
|
|
if h.lameduck > 0 {
|
|
log.Infof("Going into lameduck mode for %s", h.lameduck)
|
|
time.Sleep(h.lameduck)
|
|
}
|
|
|
|
h.ln.Close()
|
|
|
|
h.nlSetup = false
|
|
close(h.stop)
|
|
return nil
|
|
}
|