diff --git a/pkg/cmd/grafana-server/server.go b/pkg/cmd/grafana-server/server.go index 476eb2f433f..4d95e77ad29 100644 --- a/pkg/cmd/grafana-server/server.go +++ b/pkg/cmd/grafana-server/server.go @@ -3,7 +3,9 @@ package main import ( "context" "flag" + "fmt" "io/ioutil" + "net" "os" "path/filepath" "strconv" @@ -29,7 +31,6 @@ import ( "github.com/grafana/grafana/pkg/social" "github.com/grafana/grafana/pkg/tracing" - "github.com/grafana/grafana/pkg/util" ) func NewGrafanaServer() models.GrafanaServer { @@ -97,7 +98,7 @@ func (g *GrafanaServerImpl) Start() { return } - util.SdNotify("READY=1") + SendSystemdReady("READY=1") g.startHttpServer() } @@ -171,3 +172,28 @@ func (g *GrafanaServerImpl) writePIDFile() { g.log.Info("Writing PID file", "path", *pidFile, "pid", pid) } + +func SendSystemdReady(state string) error { + notifySocket := os.Getenv("NOTIFY_SOCKET") + + if notifySocket == "" { + return fmt.Errorf("NOTIFY_SOCKET environment variable empty or unset.") + } + + socketAddr := &net.UnixAddr{ + Name: notifySocket, + Net: "unixgram", + } + + conn, err := net.DialUnix(socketAddr.Net, nil, socketAddr) + + if err != nil { + return err + } + + _, err = conn.Write([]byte(state)) + + conn.Close() + + return err +} diff --git a/pkg/util/sdnotify.go b/pkg/util/sdnotify.go deleted file mode 100644 index b5cd4a4a45d..00000000000 --- a/pkg/util/sdnotify.go +++ /dev/null @@ -1,34 +0,0 @@ -package util - -import ( - "errors" - "net" - "os" -) - -var NoNotifySocket = errors.New("NOTIFY_SOCKET environment variable empty or unset.") - -func SdNotify(state string) error { - notifySocket := os.Getenv("NOTIFY_SOCKET") - - if notifySocket == "" { - return NoNotifySocket - } - - socketAddr := &net.UnixAddr{ - Name: notifySocket, - Net: "unixgram", - } - - conn, err := net.DialUnix(socketAddr.Net, nil, socketAddr) - - if err != nil { - return err - } - - _, err = conn.Write([]byte(state)) - - conn.Close() - - return err -}