mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge pull request #10025 from jgrassler/systemd-sdnotify
Use systemd notification where applicable
This commit is contained in:
@@ -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
34
pkg/util/sdnotify.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user