mirror of
https://git.proxmox.com/git/systemd
synced 2026-01-23 14:50:25 +00:00
149 lines
15 KiB
HTML
149 lines
15 KiB
HTML
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>sd_notify</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><style>
|
||
a.headerlink {
|
||
color: #c60f0f;
|
||
font-size: 0.8em;
|
||
padding: 0 4px 0 4px;
|
||
text-decoration: none;
|
||
visibility: hidden;
|
||
}
|
||
|
||
a.headerlink:hover {
|
||
background-color: #c60f0f;
|
||
color: white;
|
||
}
|
||
|
||
h1:hover > a.headerlink, h2:hover > a.headerlink, h3:hover > a.headerlink, dt:hover > a.headerlink {
|
||
visibility: visible;
|
||
}
|
||
</style><a href="index.html">Index </a>·
|
||
<a href="systemd.directives.html">Directives </a>·
|
||
<a href="../python-systemd/index.html">Python </a>·
|
||
<a href="../libudev/index.html">libudev </a>·
|
||
<a href="../libudev/index.html">gudev </a><span style="float:right">systemd 218</span><hr><div class="refentry"><a name="sd_notify"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>sd_notify, sd_notifyf — Notify service manager about start-up completion and other service status changes</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include <systemd/sd-daemon.h></pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_notify</b>(</code></td><td>int <var class="pdparam">unset_environment</var>, </td></tr><tr><td> </td><td>const char *<var class="pdparam">state</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_notifyf</b>(</code></td><td>int <var class="pdparam">unset_environment</var>, </td></tr><tr><td> </td><td>const char *<var class="pdparam">format</var>, </td></tr><tr><td> </td><td>...<code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a name="idm139898376842944"></a><h2 id="Description">Description<a class="headerlink" title="Permalink to this headline" href="#Description">¶</a></h2><p><code class="function">sd_notify()</code> may be called
|
||
by a service to notify the service manager about
|
||
state 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.</p><p>If the <em class="parameter"><code>unset_environment</code></em>
|
||
parameter is non-zero, <code class="function">sd_notify()</code>
|
||
will unset the <code class="varname">$NOTIFY_SOCKET</code>
|
||
environment variable before returning (regardless of
|
||
whether the function call itself succeeded or
|
||
not). Further calls to
|
||
<code class="function">sd_notify()</code> will then fail, but
|
||
the variable is no longer inherited by child
|
||
processes.</p><p>The <em class="parameter"><code>state</code></em> parameter
|
||
should contain a 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:</p><div class="variablelist"><dl class="variablelist"><dt id="READY=1"><span class="term">READY=1</span><a class="headerlink" title="Permalink to this term" href="#READY=1">¶</a></dt><dd><p>Tells the service
|
||
manager that service startup is
|
||
finished. This is only used by systemd
|
||
if the service definition file has
|
||
Type=notify set. Since there is little
|
||
value in signaling non-readiness, the
|
||
only value services should send is
|
||
"<code class="literal">READY=1</code>"
|
||
(i.e. "<code class="literal">READY=0</code>" is
|
||
not defined).</p></dd><dt id="RELOADING=1"><span class="term">RELOADING=1</span><a class="headerlink" title="Permalink to this term" href="#RELOADING=1">¶</a></dt><dd><p>Tells the service manager
|
||
that the service is reloading its
|
||
configuration. This is useful to allow
|
||
the service manager to track the service's
|
||
internal state, and present it to the
|
||
user. Note that a service that sends
|
||
this notification must also send a
|
||
"<code class="literal">READY=1</code>"
|
||
notification when it completed
|
||
reloading its
|
||
configuration.</p></dd><dt id="STOPPING=1"><span class="term">STOPPING=1</span><a class="headerlink" title="Permalink to this term" href="#STOPPING=1">¶</a></dt><dd><p>Tells the service manager
|
||
that the service is beginning its
|
||
shutdown. This is useful to allow the
|
||
service manager to track the service's
|
||
internal state, and present it to the
|
||
user.</p></dd><dt id="STATUS=..."><span class="term">STATUS=...</span><a class="headerlink" title="Permalink to this term" href="#STATUS=...">¶</a></dt><dd><p>Passes a single-line
|
||
UTF-8 status string back to the service manager
|
||
that describes the service 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:
|
||
"<code class="literal">STATUS=Completed 66% of file
|
||
system
|
||
check...</code>"</p></dd><dt id="ERRNO=..."><span class="term">ERRNO=...</span><a class="headerlink" title="Permalink to this term" href="#ERRNO=...">¶</a></dt><dd><p>If a service fails, the
|
||
errno-style error code, formatted as
|
||
string. Example: "<code class="literal">ERRNO=2</code>" for
|
||
ENOENT.</p></dd><dt id="BUSERROR=..."><span class="term">BUSERROR=...</span><a class="headerlink" title="Permalink to this term" href="#BUSERROR=...">¶</a></dt><dd><p>If a service fails, the
|
||
D-Bus error-style error code. Example:
|
||
"<code class="literal">BUSERROR=org.freedesktop.DBus.Error.TimedOut</code>"</p></dd><dt id="MAINPID=..."><span class="term">MAINPID=...</span><a class="headerlink" title="Permalink to this term" href="#MAINPID=...">¶</a></dt><dd><p>The main pid of the
|
||
service, in case the service manager did
|
||
not fork off the process
|
||
itself. Example:
|
||
"<code class="literal">MAINPID=4711</code>"</p></dd><dt id="WATCHDOG=1"><span class="term">WATCHDOG=1</span><a class="headerlink" title="Permalink to this term" href="#WATCHDOG=1">¶</a></dt><dd><p>Tells systemd to
|
||
update the watchdog timestamp. This is
|
||
the keep-alive ping that services need
|
||
to issue in regular intervals if
|
||
<code class="varname">WatchdogSec=</code> is
|
||
enabled for it. See
|
||
<a href="systemd.service.html"><span class="citerefentry"><span class="refentrytitle">systemd.service</span>(5)</span></a>
|
||
for information how to enable this
|
||
functionality and
|
||
<a href="sd_watchdog_enabled.html"><span class="citerefentry"><span class="refentrytitle">sd_watchdog_enabled</span>(3)</span></a>
|
||
for the details of how the service can
|
||
check if the the watchdog is enabled.
|
||
</p></dd></dl></div><p>It is recommended to prefix variable names that
|
||
are not shown in the list above with
|
||
<code class="varname">X_</code> to avoid namespace
|
||
clashes.</p><p>Note that systemd will accept status data sent
|
||
from a service only if the
|
||
<code class="varname">NotifyAccess=</code> option is correctly
|
||
set in the service definition file. See
|
||
<a href="systemd.service.html"><span class="citerefentry"><span class="refentrytitle">systemd.service</span>(5)</span></a>
|
||
for details.</p><p><code class="function">sd_notifyf()</code> is similar to
|
||
<code class="function">sd_notify()</code> but takes a
|
||
<code class="function">printf()</code>-like format string plus
|
||
arguments.</p></div><div class="refsect1"><a name="idm139898380706672"></a><h2 id="Return Value">Return Value<a class="headerlink" title="Permalink to this headline" href="#Return%20Value">¶</a></h2><p>On failure, these calls return a negative
|
||
errno-style error code. If
|
||
<code class="varname">$NOTIFY_SOCKET</code> 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
|
||
do not, it is generally recommended to ignore the return
|
||
value of this call.</p></div><div class="refsect1"><a name="idm139898380704544"></a><h2 id="Notes">Notes<a class="headerlink" title="Permalink to this headline" href="#Notes">¶</a></h2><p><a name="pkgconfig-text"></a>These APIs are implemented as a shared
|
||
library, which can be compiled and linked to with the
|
||
<code class="constant">libsystemd</code> <a href="http://linux.die.net/man/1/pkg-config"><span class="citerefentry"><span class="refentrytitle">pkg-config</span>(1)</span></a>
|
||
file.</p><p>Internally, these functions send a single
|
||
datagram with the state string as payload to the
|
||
<code class="constant">AF_UNIX</code> socket referenced in the
|
||
<code class="varname">$NOTIFY_SOCKET</code> environment
|
||
variable. If the first character of
|
||
<code class="varname">$NOTIFY_SOCKET</code> is "<code class="literal">@</code>", the string is
|
||
understood as Linux abstract namespace socket. The
|
||
datagram is accompanied by the process credentials of
|
||
the sending service, using SCM_CREDENTIALS.</p></div><div class="refsect1"><a name="idm139898380700096"></a><h2 id="Environment">Environment<a class="headerlink" title="Permalink to this headline" href="#Environment">¶</a></h2><div class="variablelist"><dl class="variablelist"><dt id="$NOTIFY_SOCKET"><span class="term"><code class="varname">$NOTIFY_SOCKET</code></span><a class="headerlink" title="Permalink to this term" href="#%24NOTIFY_SOCKET">¶</a></dt><dd><p>Set by the service manager
|
||
for supervised processes for status
|
||
and start-up completion
|
||
notification. This environment variable
|
||
specifies the socket
|
||
<code class="function">sd_notify()</code> talks
|
||
to. See above for details.</p></dd></dl></div></div><div class="refsect1"><a name="idm139898380696192"></a><h2 id="Examples">Examples<a class="headerlink" title="Permalink to this headline" href="#Examples">¶</a></h2><div class="example"><a name="idm139898380695520"></a><p class="title"><b>Example 1. Start-up Notification</b></p><div class="example-contents"><p>When a service finished starting up, it
|
||
might issue the following call to notify
|
||
the service manager:</p><pre class="programlisting">sd_notify(0, "READY=1");</pre></div></div><br class="example-break"><div class="example"><a name="idm139898380693472"></a><p class="title"><b>Example 2. Extended Start-up Notification</b></p><div class="example-contents"><p>A service could send the following after
|
||
completing initialization:</p><pre class="programlisting">sd_notifyf(0, "READY=1\n"
|
||
"STATUS=Processing requests...\n"
|
||
"MAINPID=%lu",
|
||
(unsigned long) getpid());</pre></div></div><br class="example-break"><div class="example"><a name="idm139898375775424"></a><p class="title"><b>Example 3. Error Cause Notification</b></p><div class="example-contents"><p>A service could send the following shortly before exiting, on failure</p><pre class="programlisting">sd_notifyf(0, "STATUS=Failed to start up: %s\n"
|
||
"ERRNO=%i",
|
||
strerror(errno),
|
||
errno);</pre></div></div><br class="example-break"></div><div class="refsect1"><a name="idm139898375773376"></a><h2 id="See Also">See Also<a class="headerlink" title="Permalink to this headline" href="#See%20Also">¶</a></h2><p>
|
||
<a href="systemd.html"><span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span></a>,
|
||
<a href="sd-daemon.html"><span class="citerefentry"><span class="refentrytitle">sd-daemon</span>(3)</span></a>,
|
||
<a href="daemon.html"><span class="citerefentry"><span class="refentrytitle">daemon</span>(7)</span></a>,
|
||
<a href="systemd.service.html"><span class="citerefentry"><span class="refentrytitle">systemd.service</span>(5)</span></a>,
|
||
<a href="sd_watchdog_enabled.html"><span class="citerefentry"><span class="refentrytitle">sd_watchdog_enabled</span>(3)</span></a>
|
||
</p></div></div></body></html>
|