commit 6d59201bde6fdd81402356a9e67dbb5ab9747b1d Author: Solomon Hykes Date: Mon Dec 23 23:07:01 2013 +0000 Move utility package 'systemd' to pkg/systemd diff --git a/systemd/sd_notify.go b/systemd/sd_notify.go new file mode 100644 index 0000000..1993cab --- /dev/null +++ b/systemd/sd_notify.go @@ -0,0 +1,33 @@ +package systemd + +import ( + "errors" + "net" + "os" +) + +var SdNotifyNoSocket = errors.New("No socket") + +// Send 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 + } + + _, err = conn.Write([]byte(state)) + if err != nil { + return err + } + + return nil +}