mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
* Chore: Add initial support for deployment modes * revert CLI changes and start modules independently * add modules to codeowners * additional comments * add Engine and Manager interface to fix test issues * convert background service registry to dskit module * remove extra context from serviceListener logger Co-authored-by: Will Browne <wbrowne@users.noreply.github.com> * Remove whitespace * fix import * undo ide changes * only register All by default * with registry * add test * add comments * re-add debug log * fix import * reorganize arg * undo kind changes * add provide service test * fix import * rejig systemd calls * update codeowners --------- Co-authored-by: Todd Treece <todd.treece@grafana.com> Co-authored-by: Todd Treece <360020+toddtreece@users.noreply.github.com>
44 lines
969 B
Go
44 lines
969 B
Go
package systemd
|
|
|
|
import (
|
|
"net"
|
|
"os"
|
|
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
|
)
|
|
|
|
// NotifyReady sends READY state notifications to systemd.
|
|
func NotifyReady(log log.Logger) {
|
|
notify(log, "READY=1")
|
|
}
|
|
|
|
// notify sends state notifications to systemd.
|
|
func notify(log log.Logger, state string) {
|
|
notifySocket := os.Getenv("NOTIFY_SOCKET")
|
|
if notifySocket == "" {
|
|
log.Debug(
|
|
"NOTIFY_SOCKET environment variable empty or unset, can't send systemd notification")
|
|
return
|
|
}
|
|
|
|
socketAddr := &net.UnixAddr{
|
|
Name: notifySocket,
|
|
Net: "unixgram",
|
|
}
|
|
conn, err := net.DialUnix(socketAddr.Net, nil, socketAddr)
|
|
if err != nil {
|
|
log.Warn("Failed to connect to systemd", "err", err, "socket", notifySocket)
|
|
return
|
|
}
|
|
defer func() {
|
|
if err = conn.Close(); err != nil {
|
|
log.Warn("Failed to close connection", "err", err)
|
|
}
|
|
}()
|
|
|
|
_, err = conn.Write([]byte(state))
|
|
if err != nil {
|
|
log.Warn("Failed to write notification to systemd", "err", err)
|
|
}
|
|
}
|