-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
agent: notify systemd after JoinLAN (#2121)
This patch adds support for notifying systemd via the NOTIFY_SOCKET by sending 'READY=1' to the socket after a successful JoinLAN. Fixes #2121
- Loading branch information
1 parent
ea5b0f2
commit e08c536
Showing
3 changed files
with
94 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package systemd | ||
|
||
import ( | ||
"errors" | ||
"net" | ||
"os" | ||
) | ||
|
||
var NotifyNoSocket = errors.New("No socket") | ||
|
||
// Notifier provides a method to send a message to systemd. | ||
type Notifier struct{} | ||
|
||
// Notify sends a message to the init daemon. It is common to ignore the error. | ||
func (n *Notifier) Notify(state string) error { | ||
addr := &net.UnixAddr{ | ||
Name: os.Getenv("NOTIFY_SOCKET"), | ||
Net: "unixgram", | ||
} | ||
|
||
if addr.Name == "" { | ||
return NotifyNoSocket | ||
} | ||
|
||
conn, err := net.DialUnix(addr.Net, nil, addr) | ||
if err != nil { | ||
return err | ||
} | ||
defer conn.Close() | ||
|
||
_, err = conn.Write([]byte(state)) | ||
return err | ||
} |