You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

notify_linux.go 430B

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