Skip to content
Snippets Groups Projects
Commit 1c931821 authored by ale's avatar ale
Browse files

Really notify systemd, don't just say we do

Doh, don't know how this was missed until now.
parent c1ef74c7
Branches
No related tags found
Loading
...@@ -13,6 +13,7 @@ import ( ...@@ -13,6 +13,7 @@ import (
"syscall" "syscall"
"time" "time"
"github.com/coreos/go-systemd/daemon"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
) )
...@@ -82,7 +83,8 @@ func Serve(h http.Handler, config *ServerConfig, addr string) error { ...@@ -82,7 +83,8 @@ func Serve(h http.Handler, config *ServerConfig, addr string) error {
return err 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) l, err := net.Listen("tcp", addr)
if err != nil { if err != nil {
return err return err
...@@ -113,6 +115,9 @@ func Serve(h http.Handler, config *ServerConfig, addr string) error { ...@@ -113,6 +115,9 @@ func Serve(h http.Handler, config *ServerConfig, addr string) error {
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM) signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
// Notify systemd that we are ready to serve.
daemon.SdNotify(false, "READY=1")
err = srv.Serve(l) err = srv.Serve(l)
if err != http.ErrServerClosed { if err != http.ErrServerClosed {
return err return err
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment