dependencies/pkg/mod/github.com/okzk/[email protected]/notify_linux.go
raw| 1 | package sdnotify |
| 2 | |
| 3 | import ( |
| 4 | "net" |
| 5 | "os" |
| 6 | ) |
| 7 | |
| 8 | // SdNotify sends a specified string to the systemd notification socket. |
| 9 | func SdNotify(state string) error { |
| 10 | name := os.Getenv("NOTIFY_SOCKET") |
| 11 | if name == "" { |
| 12 | return ErrSdNotifyNoSocket |
| 13 | } |
| 14 | |
| 15 | conn, err := net.DialUnix("unixgram", nil, &net.UnixAddr{Name: name, Net: "unixgram"}) |
| 16 | if err != nil { |
| 17 | return err |
| 18 | } |
| 19 | defer conn.Close() |
| 20 | |
| 21 | _, err = conn.Write([]byte(state)) |
| 22 | return err |
| 23 | } |