sdNotify sends a notification to systemd via the NOTIFY_SOCKET. If NOTIFY_SOCKET is not set (i.e. not running under systemd), this is a no-op.
(state string)
| 9 | // sdNotify sends a notification to systemd via the NOTIFY_SOCKET. |
| 10 | // If NOTIFY_SOCKET is not set (i.e. not running under systemd), this is a no-op. |
| 11 | func sdNotify(state string) error { |
| 12 | socketPath := os.Getenv("NOTIFY_SOCKET") |
| 13 | if socketPath == "" { |
| 14 | return nil |
| 15 | } |
| 16 | |
| 17 | conn, err := net.Dial("unixgram", socketPath) |
| 18 | if err != nil { |
| 19 | return fmt.Errorf("dial NOTIFY_SOCKET: %w", err) |
| 20 | } |
| 21 | defer func() { _ = conn.Close() }() |
| 22 | |
| 23 | if _, err := conn.Write([]byte(state)); err != nil { |
| 24 | return fmt.Errorf("write to NOTIFY_SOCKET: %w", err) |
| 25 | } |
| 26 | return nil |
| 27 | } |
no test coverage detected