Commit 820abef8 by Carl Bergquist Committed by GitHub

Merge pull request #10025 from jgrassler/systemd-sdnotify

Use systemd notification where applicable
parents 142c3a6b d28ca541
...@@ -9,7 +9,7 @@ After=postgresql.service mariadb.service mysql.service ...@@ -9,7 +9,7 @@ After=postgresql.service mariadb.service mysql.service
EnvironmentFile=/etc/sysconfig/grafana-server EnvironmentFile=/etc/sysconfig/grafana-server
User=grafana User=grafana
Group=grafana Group=grafana
Type=simple Type=notify
Restart=on-failure Restart=on-failure
WorkingDirectory=/usr/share/grafana WorkingDirectory=/usr/share/grafana
RuntimeDirectory=grafana RuntimeDirectory=grafana
......
...@@ -29,6 +29,7 @@ import ( ...@@ -29,6 +29,7 @@ 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 {
...@@ -96,6 +97,7 @@ func (g *GrafanaServerImpl) Start() { ...@@ -96,6 +97,7 @@ func (g *GrafanaServerImpl) Start() {
return return
} }
util.SdNotify("READY=1")
g.startHttpServer() g.startHttpServer()
} }
......
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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment