github.com/torfuzx/docker@v1.8.1/pkg/systemd/sd_notify.go (about)

     1  package systemd
     2  
     3  import (
     4  	"errors"
     5  	"net"
     6  	"os"
     7  )
     8  
     9  var SdNotifyNoSocket = errors.New("No socket")
    10  
    11  // Send a message to the init daemon. It is common to ignore the error.
    12  func SdNotify(state string) error {
    13  	socketAddr := &net.UnixAddr{
    14  		Name: os.Getenv("NOTIFY_SOCKET"),
    15  		Net:  "unixgram",
    16  	}
    17  
    18  	if socketAddr.Name == "" {
    19  		return SdNotifyNoSocket
    20  	}
    21  
    22  	conn, err := net.DialUnix(socketAddr.Net, nil, socketAddr)
    23  	if err != nil {
    24  		return err
    25  	}
    26  
    27  	_, err = conn.Write([]byte(state))
    28  	if err != nil {
    29  		return err
    30  	}
    31  
    32  	return nil
    33  }