diff --git a/serverutil/http.go b/serverutil/http.go index 7fbd69fe5693d7f33ca4a8c1faccd9ee073bc01c..32329492c8a490485b7094fd4e2d608246aa78d8 100644 --- a/serverutil/http.go +++ b/serverutil/http.go @@ -13,6 +13,7 @@ import ( "syscall" "time" + "github.com/coreos/go-systemd/daemon" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" ) @@ -82,7 +83,8 @@ func Serve(h http.Handler, config *ServerConfig, addr string) error { return err } - // Create the net.Listener, then notify systemd that we are ready to serve. + // Create the net.Listener first, so we can detect + // initialization-time errors safely. l, err := net.Listen("tcp", addr) if err != nil { return err @@ -113,6 +115,9 @@ func Serve(h http.Handler, config *ServerConfig, addr string) error { signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM) + // Notify systemd that we are ready to serve. + daemon.SdNotify(false, "READY=1") + err = srv.Serve(l) if err != http.ErrServerClosed { return err