move systemd ready notification to server.go

This commit is contained in:
bergquist 2017-12-01 14:02:05 +01:00
parent 94446fb85c
commit 7a497fd617
2 changed files with 28 additions and 36 deletions

View File

@ -3,7 +3,9 @@ package main
import ( import (
"context" "context"
"flag" "flag"
"fmt"
"io/ioutil" "io/ioutil"
"net"
"os" "os"
"path/filepath" "path/filepath"
"strconv" "strconv"
@ -29,7 +31,6 @@ import (
"github.com/grafana/grafana/pkg/social" "github.com/grafana/grafana/pkg/social"
"github.com/grafana/grafana/pkg/tracing" "github.com/grafana/grafana/pkg/tracing"
"github.com/grafana/grafana/pkg/util"
) )
func NewGrafanaServer() models.GrafanaServer { func NewGrafanaServer() models.GrafanaServer {
@ -97,7 +98,7 @@ func (g *GrafanaServerImpl) Start() {
return return
} }
util.SdNotify("READY=1") SendSystemdReady("READY=1")
g.startHttpServer() g.startHttpServer()
} }
@ -171,3 +172,28 @@ func (g *GrafanaServerImpl) writePIDFile() {
g.log.Info("Writing PID file", "path", *pidFile, "pid", pid) 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
}

View File

@ -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
}