Merge pull request #10025 from jgrassler/systemd-sdnotify

Use systemd notification where applicable
This commit is contained in:
Carl Bergquist
2017-12-01 13:26:13 +01:00
committed by GitHub
3 changed files with 37 additions and 1 deletions

View File

@@ -29,6 +29,7 @@ import (
"github.com/grafana/grafana/pkg/social"
"github.com/grafana/grafana/pkg/tracing"
"github.com/grafana/grafana/pkg/util"
)
func NewGrafanaServer() models.GrafanaServer {
@@ -96,6 +97,7 @@ func (g *GrafanaServerImpl) Start() {
return
}
util.SdNotify("READY=1")
g.startHttpServer()
}

34
pkg/util/sdnotify.go Normal file
View File

@@ -0,0 +1,34 @@
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
}