mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
move systemd ready notification to server.go
This commit is contained in:
parent
94446fb85c
commit
7a497fd617
@ -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
|
||||||
|
}
|
||||||
|
@ -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
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user