Commit 7a497fd6 by bergquist

move systemd ready notification to server.go

parent 94446fb8
...@@ -3,7 +3,9 @@ package main ...@@ -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 ( ...@@ -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() { ...@@ -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() { ...@@ -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
}
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