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">
6 SPDX-License-Identifier: LGPL-2.1+
9 <refentry id=
"systemd-notify"
10 xmlns:
xi=
"http://www.w3.org/2001/XInclude">
13 <title>systemd-notify
</title>
14 <productname>systemd
</productname>
18 <contrib>Developer
</contrib>
19 <firstname>Lennart
</firstname>
20 <surname>Poettering
</surname>
21 <email>lennart@poettering.net
</email>
27 <refentrytitle>systemd-notify
</refentrytitle>
28 <manvolnum>1</manvolnum>
32 <refname>systemd-notify
</refname>
33 <refpurpose>Notify service manager about start-up completion and other daemon status changes
</refpurpose>
38 <command>systemd-notify
<arg choice=
"opt" rep=
"repeat">OPTIONS
</arg> <arg choice=
"opt" rep=
"repeat">VARIABLE=VALUE
</arg></command>
43 <title>Description
</title>
45 <para><command>systemd-notify
</command> may be called by daemon
46 scripts to notify the init system about status changes. It can be
47 used to send arbitrary information, encoded in an
48 environment-block-like list of strings. Most importantly, it can be
49 used for start-up completion notification.
</para>
51 <para>This is mostly just a wrapper around
52 <function>sd_notify()
</function> and makes this functionality
53 available to shell scripts. For details see
54 <citerefentry><refentrytitle>sd_notify
</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
57 <para>The command line may carry a list of environment variables
58 to send as part of the status update.
</para>
60 <para>Note that systemd will refuse reception of status updates from this command unless
61 <varname>NotifyAccess=
</varname> is set for the service unit this command is called from.
</para>
63 <para>Note that
<function>sd_notify()
</function> notifications may be attributed to units correctly only if either
64 the sending process is still around at the time PID
1 processes the message, or if the sending process is
65 explicitly runtime-tracked by the service manager. The latter is the case if the service manager originally forked
66 off the process, i.e. on all processes that match
<varname>NotifyAccess=
</varname><option>main
</option> or
67 <varname>NotifyAccess=
</varname><option>exec
</option>. Conversely, if an auxiliary process of the unit sends an
68 <function>sd_notify()
</function> message and immediately exits, the service manager might not be able to properly
69 attribute the message to the unit, and thus will ignore it, even if
70 <varname>NotifyAccess=
</varname><option>all
</option> is set for it.
</para>
72 <para><command>systemd-notify
</command> will first attempt to invoke
<function>sd_notify()
</function> pretending to
73 have the PID of the invoking process. This will only succeed when invoked with sufficient privileges. On failure,
74 it will then fall back to invoking it under its own PID. This behaviour is useful in order that when the tool is
75 invoked from a shell script the shell process — and not the
<command>systemd-notify
</command> process — appears as
76 sender of the message, which in turn is helpful if the shell process is the main process of a service, due to the
77 limitations of
<varname>NotifyAccess=
</varname><option>all
</option> described above.
</para>
81 <title>Options
</title>
83 <para>The following options are understood:
</para>
87 <term><option>--ready
</option></term>
89 <listitem><para>Inform the init system about service start-up
90 completion. This is equivalent to
<command>systemd-notify
91 READY=
1</command>. For details about the semantics of this
93 <citerefentry><refentrytitle>sd_notify
</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
</para></listitem>
97 <term><option>--pid=
</option></term>
99 <listitem><para>Inform the init system about the main PID of
100 the daemon. Takes a PID as argument. If the argument is
101 omitted, the PID of the process that invoked
102 <command>systemd-notify
</command> is used. This is equivalent
103 to
<command>systemd-notify MAINPID=$PID
</command>. For details
104 about the semantics of this option see
105 <citerefentry><refentrytitle>sd_notify
</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
</para></listitem>
109 <term><option>--uid=
</option><replaceable>USER
</replaceable></term>
111 <listitem><para>Set the user ID to send the notification from. Takes a UNIX user name or numeric UID. When
112 specified the notification message will be sent with the specified UID as sender, in place of the user the
113 command was invoked as. This option requires sufficient privileges in order to be able manipulate the user
114 identity of the process.
</para></listitem>
118 <term><option>--status=
</option></term>
120 <listitem><para>Send a free-form status string for the daemon
121 to the init systemd. This option takes the status string as
122 argument. This is equivalent to
<command>systemd-notify
123 STATUS=…
</command>. For details about the semantics of this
125 <citerefentry><refentrytitle>sd_notify
</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
</para></listitem>
129 <term><option>--booted
</option></term>
131 <listitem><para>Returns
0 if the system was booted up with
132 systemd, non-zero otherwise. If this option is passed, no
133 message is sent. This option is hence unrelated to the other
134 options. For details about the semantics of this option, see
135 <citerefentry><refentrytitle>sd_booted
</refentrytitle><manvolnum>3</manvolnum></citerefentry>. An
136 alternate way to check for this state is to call
137 <citerefentry><refentrytitle>systemctl
</refentrytitle><manvolnum>1</manvolnum></citerefentry>
138 with the
<command>is-system-running
</command> command. It will
139 return
<literal>offline
</literal> if the system was not booted
140 with systemd.
</para></listitem>
143 <xi:include href=
"standard-options.xml" xpointer=
"help" />
144 <xi:include href=
"standard-options.xml" xpointer=
"version" />
150 <title>Exit status
</title>
152 <para>On success,
0 is returned, a non-zero failure code
157 <title>Example
</title>
160 <title>Start-up Notification and Status Updates
</title>
162 <para>A simple shell daemon that sends start-up notifications
163 after having set up its communication channel. During runtime it
164 sends further status updates to the init system:
</para>
166 <programlisting>#!/bin/bash
169 systemd-notify --ready
--status=
"Waiting for data…"
172 read a
< /tmp/waldo
173 systemd-notify
--status=
"Processing $a"
175 # Do something with $a …
177 systemd-notify
--status=
"Waiting for data…"
178 done
</programlisting>
183 <title>See Also
</title>
185 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
186 <citerefentry><refentrytitle>systemctl
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
187 <citerefentry><refentrytitle>systemd.unit
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
188 <citerefentry><refentrytitle>sd_notify
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
189 <citerefentry><refentrytitle>sd_booted
</refentrytitle><manvolnum>3</manvolnum></citerefentry>