The official documentation is in the sd_notify(3) manual page.
Very short summary:
- Change your systemd service to
Type=notify
. - Your daemon will receive an environment variable
NOTIFY_SOCKET
, which contains a path to an AF_UNIX socket.
(If the first path byte is@
, this means an "abstract" socket, and you should change the 1st byte to 0x00 before using.) - The protocol consists of sending datagrams containing textual (UTF-8) status messages.
Each message contains newline-separatedKEY=value
parameters. - When the daemon is ready, it must send
READY=1
, and systemd will transition the service from "starting" to "running". - At any point, you can send
STATUS=Some text
and the text will be shown insystemctl status
. You can use this to show e.g. current client count or other statistics. This can be combined with the above, e.g.READY=1\nSTATUS=All systems go!
UNIXSocket
appears to open a stream but a dgram is wanted. the below works:https://gist.github.com/zimbatm/9f1bc26446af0ee3e5c5?permalink_comment_id=1902920#gistcomment-1902920