chiark / gitweb /
tmpfiles: get rid of "m" lines, make them redundant by "z"
[elogind.git] / man / sd_notify.xml
1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3         "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4
5 <!--
6   This file is part of systemd.
7
8   Copyright 2010 Lennart Poettering
9
10   systemd is free software; you can redistribute it and/or modify it
11   under the terms of the GNU Lesser General Public License as published by
12   the Free Software Foundation; either version 2.1 of the License, or
13   (at your option) any later version.
14
15   systemd is distributed in the hope that it will be useful, but
16   WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18   Lesser General Public License for more details.
19
20   You should have received a copy of the GNU Lesser General Public License
21   along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 -->
23
24 <refentry id="sd_notify"
25         xmlns:xi="http://www.w3.org/2001/XInclude">
26
27         <refentryinfo>
28                 <title>sd_notify</title>
29                 <productname>systemd</productname>
30
31                 <authorgroup>
32                         <author>
33                                 <contrib>Developer</contrib>
34                                 <firstname>Lennart</firstname>
35                                 <surname>Poettering</surname>
36                                 <email>lennart@poettering.net</email>
37                         </author>
38                 </authorgroup>
39         </refentryinfo>
40
41         <refmeta>
42                 <refentrytitle>sd_notify</refentrytitle>
43                 <manvolnum>3</manvolnum>
44         </refmeta>
45
46         <refnamediv>
47                 <refname>sd_notify</refname>
48                 <refname>sd_notifyf</refname>
49                 <refpurpose>Notify service manager about start-up completion and other daemon status changes</refpurpose>
50         </refnamediv>
51
52         <refsynopsisdiv>
53                 <funcsynopsis>
54                         <funcsynopsisinfo>#include &lt;systemd/sd-daemon.h&gt;</funcsynopsisinfo>
55
56                         <funcprototype>
57                                 <funcdef>int <function>sd_notify</function></funcdef>
58                                 <paramdef>int <parameter>unset_environment</parameter></paramdef>
59                                 <paramdef>const char *<parameter>state</parameter></paramdef>
60                         </funcprototype>
61
62                         <funcprototype>
63                                 <funcdef>int <function>sd_notifyf</function></funcdef>
64                                 <paramdef>int <parameter>unset_environment</parameter></paramdef>
65                                 <paramdef>const char *<parameter>format</parameter></paramdef>
66                                 <paramdef>...</paramdef>
67                         </funcprototype>
68                 </funcsynopsis>
69         </refsynopsisdiv>
70
71         <refsect1>
72                 <title>Description</title>
73                 <para><function>sd_notify()</function> shall be called
74                 by a daemon to notify the init system about status
75                 changes. It can be used to send arbitrary information,
76                 encoded in an environment-block-like string. Most
77                 importantly it can be used for start-up completion
78                 notification.</para>
79
80                 <para>If the <parameter>unset_environment</parameter>
81                 parameter is non-zero, <function>sd_notify()</function>
82                 will unset the <varname>$NOTIFY_SOCKET</varname>
83                 environment variable before returning (regardless of
84                 whether the function call itself succeeded or
85                 not). Further calls to
86                 <function>sd_notify()</function> will then fail, but
87                 the variable is no longer inherited by child
88                 processes.</para>
89
90                 <para>The <parameter>state</parameter> parameter
91                 should contain a newline-separated list of variable
92                 assignments, similar in style to an environment
93                 block. A trailing newline is implied if none is
94                 specified. The string may contain any kind of variable
95                 assignments, but the following shall be considered
96                 well-known:</para>
97
98                 <variablelist>
99                         <varlistentry>
100                                 <term>READY=1</term>
101
102                                 <listitem><para>Tells the init system
103                                 that daemon startup is finished. This
104                                 is only used by systemd if the service
105                                 definition file has Type=notify
106                                 set. The passed argument is a boolean
107                                 "1" or "0". Since there is little
108                                 value in signaling non-readiness, the
109                                 only value daemons should send is
110                                 "READY=1".</para></listitem>
111                         </varlistentry>
112
113                         <varlistentry>
114                                 <term>STATUS=...</term>
115
116                                 <listitem><para>Passes a single-line
117                                 status string back to the init system
118                                 that describes the daemon state. This
119                                 is free-form and can be used for
120                                 various purposes: general state
121                                 feedback, fsck-like programs could
122                                 pass completion percentages and
123                                 failing programs could pass a human
124                                 readable error message. Example:
125                                 "STATUS=Completed 66% of file system
126                                 check..."</para></listitem>
127                         </varlistentry>
128
129                         <varlistentry>
130                                 <term>ERRNO=...</term>
131
132                                 <listitem><para>If a daemon fails, the
133                                 errno-style error code, formatted as
134                                 string. Example: "ERRNO=2" for
135                                 ENOENT.</para></listitem>
136                         </varlistentry>
137
138                         <varlistentry>
139                                 <term>BUSERROR=...</term>
140
141                                 <listitem><para>If a daemon fails, the
142                                 D-Bus error-style error code. Example:
143                                 "BUSERROR=org.freedesktop.DBus.Error.TimedOut"</para></listitem>
144                         </varlistentry>
145
146                         <varlistentry>
147                                 <term>MAINPID=...</term>
148
149                                 <listitem><para>The main pid of the
150                                 daemon, in case the init system did
151                                 not fork off the process
152                                 itself. Example:
153                                 "MAINPID=4711"</para></listitem>
154                         </varlistentry>
155
156                         <varlistentry>
157                                 <term>WATCHDOG=1</term>
158
159                                 <listitem><para>Tells systemd to
160                                 update the watchdog timestamp. This is
161                                 the keep-alive ping that services need
162                                 to issue in regular intervals if
163                                 <varname>WatchdogSec=</varname> is
164                                 enabled for it. See
165                                 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
166                                 for details. It is recommended to send
167                                 this message if the
168                                 <varname>$WATCHDOG_PID</varname>
169                                 environment variable has been set to
170                                 the PID of the service process, in
171                                 every half the time interval that is
172                                 specified in the
173                                 <varname>$WATCHDOG_USEC</varname>
174                                 environment variable. See
175                                 <citerefentry><refentrytitle>sd_watchdog_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>
176                                 for details.</para></listitem>
177                         </varlistentry>
178                 </variablelist>
179
180                 <para>It is recommended to prefix variable names that
181                 are not shown in the list above with
182                 <varname>X_</varname> to avoid namespace
183                 clashes.</para>
184
185                 <para>Note that systemd will accept status data sent
186                 from a daemon only if the
187                 <varname>NotifyAccess=</varname> option is correctly
188                 set in the service definition file. See
189                 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
190                 for details.</para>
191
192                 <para><function>sd_notifyf()</function> is similar to
193                 <function>sd_notify()</function> but takes a
194                 <function>printf()</function>-like format string plus
195                 arguments.</para>
196         </refsect1>
197
198         <refsect1>
199                 <title>Return Value</title>
200
201                 <para>On failure, these calls return a negative
202                 errno-style error code. If
203                 <varname>$NOTIFY_SOCKET</varname> was not set and
204                 hence no status data could be sent, 0 is returned. If
205                 the status was sent, these functions return with a
206                 positive return value. In order to support both, init
207                 systems that implement this scheme and those which
208                 do not, it is generally recommended to ignore the return
209                 value of this call.</para>
210         </refsect1>
211
212         <refsect1>
213                 <title>Notes</title>
214
215                 <xi:include href="libsystemd-pkgconfig.xml" xpointer="pkgconfig-text"/>
216
217                 <para>Internally, these functions send a single
218                 datagram with the state string as payload to the
219                 <constant>AF_UNIX</constant> socket referenced in the
220                 <varname>$NOTIFY_SOCKET</varname> environment
221                 variable. If the first character of
222                 <varname>$NOTIFY_SOCKET</varname> is <literal>@</literal>, the string is
223                 understood as Linux abstract namespace socket. The
224                 datagram is accompanied by the process credentials of
225                 the sending daemon, using SCM_CREDENTIALS.</para>
226         </refsect1>
227
228         <refsect1>
229                 <title>Environment</title>
230
231                 <variablelist class='environment-variables'>
232                         <varlistentry>
233                                 <term><varname>$NOTIFY_SOCKET</varname></term>
234
235                                 <listitem><para>Set by the init system
236                                 for supervised processes for status
237                                 and start-up completion
238                                 notification. This environment variable
239                                 specifies the socket
240                                 <function>sd_notify()</function> talks
241                                 to. See above for details.</para></listitem>
242                         </varlistentry>
243                 </variablelist>
244         </refsect1>
245
246         <refsect1>
247                 <title>Examples</title>
248
249                 <example>
250                         <title>Start-up Notification</title>
251
252                         <para>When a daemon finished starting up, it
253                         might issue the following call to notify
254                         the init system:</para>
255
256                         <programlisting>sd_notify(0, "READY=1");</programlisting>
257                 </example>
258
259                 <example>
260                         <title>Extended Start-up Notification</title>
261
262                         <para>A daemon could send the following after
263                         completing initialization:</para>
264
265                         <programlisting>sd_notifyf(0, "READY=1\n"
266               "STATUS=Processing requests...\n"
267               "MAINPID=%lu",
268               (unsigned long) getpid());</programlisting>
269                 </example>
270
271                 <example>
272                         <title>Error Cause Notification</title>
273
274                         <para>A daemon could send the following shortly before exiting, on failure</para>
275
276                         <programlisting>sd_notifyf(0, "STATUS=Failed to start up: %s\n"
277               "ERRNO=%i",
278               strerror(errno),
279               errno);</programlisting>
280                 </example>
281         </refsect1>
282
283         <refsect1>
284                 <title>See Also</title>
285                 <para>
286                         <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
287                         <citerefentry><refentrytitle>sd-daemon</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
288                         <citerefentry><refentrytitle>daemon</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
289                         <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
290                         <citerefentry><refentrytitle>sd_watchdog_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>
291                 </para>
292         </refsect1>
293
294 </refentry>