3 .\" Author: Lennart Poettering <lennart@poettering.net>
4 .\" Generator: DocBook XSL Stylesheets v1.76.1 <http://docbook.sf.net/>
10 .TH "SD_NOTIFY" "3" "02/15/2012" "systemd" "sd_notify"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 sd_notify, sd_notifyf \- Notify init system about start\-up completion and other daemon status changes
36 #include <systemd/sd\-daemon\&.h>
39 .HP \w'int\ sd_notify('u
40 .BI "int sd_notify(int\ " "unset_environment" ", const\ char\ *" "state" ");"
41 .HP \w'int\ sd_notifyf('u
42 .BI "int sd_notifyf(int\ " "unset_environment" ", const\ char\ *" "format" ", \&.\&.\&.);"
46 shall be called by a daemon to notify the init system about status changes\&. It can be used to send arbitrary information, encoded in an environment\-block\-like string\&. Most importantly it can be used for start\-up completion notification\&.
49 \fIunset_environment\fR
50 parameter is non\-zero
54 environment variable before returning (regardless whether the function call itself succeeded or not)\&. Further calls to
56 will then fail, but the variable is no longer inherited by child processes\&.
60 parameter should contain an newline\-separated list of variable assignments, similar in style to an environment block\&. A trailing newline is implied if none is specified\&. The string may contain any kind of variable assignments, but the following shall be considered well\-known:
64 Tells the init system that daemon startup is finished\&. This is only used by systemd if the service definition file has Type=notify set\&. The passed argument is a boolean "1" or "0"\&. Since there is little value in signalling non\-readiness, the only value daemons should send is "READY=1"\&.
69 Passes a single\-line status string back to the init system that describes the daemon state\&. This is free\-form and can be used for various purposes: general state feedback, fsck\-like programs could pass completion percentages and failing programs could pass a human readable error message\&. Example: "STATUS=Completed 66% of file system check\&.\&.\&."
74 If a daemon fails, the errno\-style error code, formatted as string\&. Example: "ERRNO=2" for ENOENT\&.
79 If a daemon fails, the D\-Bus error\-style error code\&. Example: "BUSERROR=org\&.freedesktop\&.DBus\&.Error\&.TimedOut"
84 The main pid of the daemon, in case the init system did not fork off the process itself\&. Example: "MAINPID=4711"
89 Tells systemd to update the watchdog timestamp\&. Services using this feature should do this in regular intervals\&. A watchdog framework can use the timestamps to detect failed services\&.
92 It is recommended to prefix variable names that are not shown in the list above with
94 to avoid namespace clashes\&.
96 Note that systemd will accept status data sent from a daemon only if the
98 option is correctly set in the service definition file\&. See
99 \fBsystemd.service\fR(5)
106 \fBprintf()\fR\-like format string plus arguments\&.
109 On failure, these calls return a negative errno\-style error code\&. If
111 was not set and hence no status data could be sent, 0 is returned\&. If the status was sent these functions return with a positive return value\&. In order to support both, init systems that implement this scheme and those which don\*(Aqt, it is generally recommended to ignore the return value of this call\&.
114 These functions are provided by the reference implementation of APIs for new\-style daemons and distributed with the systemd package\&. The algorithms they implement are simple, and can easily be reimplemented in daemons if it is important to support this interface without using the reference implementation\&.
116 Internally, these functions send a single datagram with the state string as payload to the AF_UNIX socket referenced in the
118 environment variable\&. If the first character of
120 is @ the string is understood as Linux abstract namespace socket\&. The datagram is accompanied by the process credentials of the sending daemon, using SCM_CREDENTIALS\&.
122 For details about the algorithms check the liberally licensed reference implementation sources:
123 \m[blue]\fB\%http://cgit.freedesktop.org/systemd/systemd/plain/src/sd-daemon.c\fR\m[]
125 \m[blue]\fB\%http://cgit.freedesktop.org/systemd/systemd/plain/src/systemd/sd-daemon.h\fR\m[]
130 are implemented in the reference implementation\*(Aqs
134 files\&. These interfaces are available as shared library, which can be compiled and linked to with the
137 file\&. Alternatively, applications consuming these APIs may copy the implementation into their source tree\&. For more details about the reference implementation see
138 \fBsd_daemon\fR(7)\&.
140 If the reference implementation is used as drop\-in files and \-DDISABLE_SYSTEMD is set during compilation these functions will always return 0 and otherwise become a NOP\&.
145 Set by the init system for supervised processes for status and start\-up completion notification\&. This environment variable specifies the socket
147 talks to\&. See above for details\&.
151 \fBExample\ \&1.\ \&Start-up Notification\fR
153 When a daemon finished starting up, it might issue the following call to notify the init system:
159 sd_notify(0, "READY=1");
165 \fBExample\ \&2.\ \&Extended Start-up Notification\fR
167 A daemon could send the following after completing initialization:
173 sd_notifyf(0, "READY=1\en"
174 "STATUS=Processing requests\&.\&.\&.\en"
176 (unsigned long) getpid());
182 \fBExample\ \&3.\ \&Error Cause Notification\fR
184 A daemon could send the following shortly before exiting, on failure
190 sd_notifyf(0, "STATUS=Failed to start up: %s\en"
204 \fBsystemd.service\fR(5)
207 \fBLennart Poettering\fR <\&lennart@poettering\&.net\&>