Add support for sd_notify
Signed-off-by: Dan Walsh <dwalsh@redhat.com>
This commit is contained in:
parent
c1b9838af5
commit
09bed25074
4 changed files with 56 additions and 0 deletions
20
cmd/server/daemon_linux.go
Normal file
20
cmd/server/daemon_linux.go
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
// +build linux
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/Sirupsen/logrus"
|
||||||
|
systemdDaemon "github.com/coreos/go-systemd/daemon"
|
||||||
|
)
|
||||||
|
|
||||||
|
func sdNotify() {
|
||||||
|
if err := systemdDaemon.SdNotify("READY=1"); err != nil {
|
||||||
|
logrus.Warnf("Failed to sd_notify systemd: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// notifySystem sends a message to the host when the server is ready to be used
|
||||||
|
func notifySystem() {
|
||||||
|
// Tell the init daemon we are accepting requests
|
||||||
|
go sdNotify()
|
||||||
|
}
|
|
@ -188,6 +188,10 @@ func main() {
|
||||||
|
|
||||||
runtime.RegisterRuntimeServiceServer(s, service)
|
runtime.RegisterRuntimeServiceServer(s, service)
|
||||||
runtime.RegisterImageServiceServer(s, service)
|
runtime.RegisterImageServiceServer(s, service)
|
||||||
|
|
||||||
|
// after the daemon is done setting up we can notify systemd api
|
||||||
|
notifySystem()
|
||||||
|
|
||||||
if err := s.Serve(lis); err != nil {
|
if err := s.Serve(lis); err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ case $# in
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
clone git github.com/coreos/go-systemd/daemon
|
||||||
clone git github.com/BurntSushi/toml v0.2.0
|
clone git github.com/BurntSushi/toml v0.2.0
|
||||||
clone git github.com/Sirupsen/logrus v0.10.0
|
clone git github.com/Sirupsen/logrus v0.10.0
|
||||||
clone git github.com/containers/image f6f11ab5cf8b1e70ef4aa3f8b6fdb4b671d16abd
|
clone git github.com/containers/image f6f11ab5cf8b1e70ef4aa3f8b6fdb4b671d16abd
|
||||||
|
|
31
vendor/src/github.com/coreos/go-systemd/daemon/sdnotify.go
vendored
Normal file
31
vendor/src/github.com/coreos/go-systemd/daemon/sdnotify.go
vendored
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
// Code forked from Docker project
|
||||||
|
package daemon
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
var SdNotifyNoSocket = errors.New("No socket")
|
||||||
|
|
||||||
|
// SdNotify sends a message to the init daemon. It is common to ignore the error.
|
||||||
|
func SdNotify(state string) error {
|
||||||
|
socketAddr := &net.UnixAddr{
|
||||||
|
Name: os.Getenv("NOTIFY_SOCKET"),
|
||||||
|
Net: "unixgram",
|
||||||
|
}
|
||||||
|
|
||||||
|
if socketAddr.Name == "" {
|
||||||
|
return SdNotifyNoSocket
|
||||||
|
}
|
||||||
|
|
||||||
|
conn, err := net.DialUnix(socketAddr.Net, nil, socketAddr)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
_, err = conn.Write([]byte(state))
|
||||||
|
return err
|
||||||
|
}
|
Loading…
Reference in a new issue