File systemd-notification.patch of Package grafana

Commit: `git diff 142c3a6bc2bd59ccd6194b095b3a207ac9b8f015 17bf87fb626ecb7b8a338e486403861e43deae171` on master branch with CHANGELOG diff removed
Author: Johannes Grassler <johannes.grassler@suse.com> and Carl Bergquist <carl.bergquist@gmail.com>
Date:   Tue Nov 28 18:16:38 2017 +0100
Subject: Use systemd notification where applicable
Upstream: merged into master
URL: https://github.com/grafana/grafana/pull/10025 and https://github.com/grafana/grafana/issues/10024

Index: grafana-4.5.1/packaging/rpm/systemd/grafana-server.service
===================================================================
--- grafana-4.5.1.orig/packaging/rpm/systemd/grafana-server.service
+++ grafana-4.5.1/packaging/rpm/systemd/grafana-server.service
@@ -9,7 +9,7 @@ After=postgresql.service mariadb.service
 EnvironmentFile=/etc/sysconfig/grafana-server
 User=grafana
 Group=grafana
-Type=simple
+Type=notify
 Restart=on-failure
 WorkingDirectory=/usr/share/grafana
 RuntimeDirectory=grafana
Index: grafana-4.5.1/pkg/cmd/grafana-server/server.go
===================================================================
--- grafana-4.5.1.orig/pkg/cmd/grafana-server/server.go
+++ grafana-4.5.1/pkg/cmd/grafana-server/server.go
@@ -3,7 +3,9 @@ package main
 import (
 	"context"
 	"flag"
+	"fmt"
 	"io/ioutil"
+	"net"
 	"os"
 	"path/filepath"
 	"strconv"
@@ -77,6 +79,7 @@ func (g *GrafanaServerImpl) Start() {
 		return
 	}
 
+	SendSystemdNotification("READY=1")
 	g.startHttpServer()
 }
 
@@ -145,3 +148,28 @@ func (g *GrafanaServerImpl) writePIDFile
 
 	g.log.Info("Writing PID file", "path", *pidFile, "pid", pid)
 }
+
+func SendSystemdNotification(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
+}
openSUSE Build Service is sponsored by