]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/systemd-notify.xml
journal: Serialize __MONOTONIC_TIMESTAMP metadata field as well
[thirdparty/systemd.git] / man / systemd-notify.xml
CommitLineData
c5abba08 1<?xml version='1.0'?> <!--*-nxml-*-->
3a54a157 2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
eea10b26 3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
db9ecf05 4<!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
c5abba08 5
dfdebb1b 6<refentry id="systemd-notify"
798d3a52
ZJS
7 xmlns:xi="http://www.w3.org/2001/XInclude">
8
9 <refentryinfo>
10 <title>systemd-notify</title>
11 <productname>systemd</productname>
798d3a52
ZJS
12 </refentryinfo>
13
14 <refmeta>
15 <refentrytitle>systemd-notify</refentrytitle>
16 <manvolnum>1</manvolnum>
17 </refmeta>
18
19 <refnamediv>
20 <refname>systemd-notify</refname>
21 <refpurpose>Notify service manager about start-up completion and other daemon status changes</refpurpose>
22 </refnamediv>
23
24 <refsynopsisdiv>
25 <cmdsynopsis>
dfa6c32a 26 <command>systemd-notify</command> <arg choice="opt" rep="repeat">OPTIONS</arg> <arg choice="opt" rep="repeat">VARIABLE=VALUE</arg>
798d3a52 27 </cmdsynopsis>
c4ef4df4 28 <cmdsynopsis>
b239fc72 29 <command>systemd-notify</command> <arg>--exec</arg> <arg choice="opt" rep="repeat">OPTIONS</arg> <arg choice="opt" rep="repeat">VARIABLE=VALUE</arg> <arg>;</arg> <arg rep="repeat">CMDLINE</arg>
c4ef4df4 30 </cmdsynopsis>
798d3a52
ZJS
31 </refsynopsisdiv>
32
33 <refsect1>
34 <title>Description</title>
35
fd0f4da5
LP
36 <para><command>systemd-notify</command> may be called by service scripts to notify the invoking service
37 manager about status changes. It can be used to send arbitrary information, encoded in an
38 environment-block-like list of strings. Most importantly, it can be used for start-up completion
39 notification.</para>
40
41 <para>This is mostly just a wrapper around <function>sd_notify()</function> and makes this functionality
798d3a52
ZJS
42 available to shell scripts. For details see
43 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
44 </para>
45
fd0f4da5
LP
46 <para>The command line may carry a list of environment variables to send as part of the status
47 update.</para>
798d3a52 48
b3bb6476 49 <para>Note that systemd will refuse reception of status updates from this command unless
b7d963e5
LP
50 <varname>NotifyAccess=</varname> is appropriately set for the service unit this command is called
51 from. See
52 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
53 details.</para>
54
55 <para>Note that <function>sd_notify()</function> notifications may be attributed to units correctly only
fd0f4da5
LP
56 if either the sending process is still around at the time the service manager processes the message, or
57 if the sending process is explicitly runtime-tracked by the service manager. The latter is the case if
58 the service manager originally forked off the process, i.e. on all processes that match
b7d963e5
LP
59 <varname>NotifyAccess=</varname><option>main</option> or
60 <varname>NotifyAccess=</varname><option>exec</option>. Conversely, if an auxiliary process of the unit
61 sends an <function>sd_notify()</function> message and immediately exits, the service manager might not be
62 able to properly attribute the message to the unit, and thus will ignore it, even if
63 <varname>NotifyAccess=</varname><option>all</option> is set for it. To address this
64 <command>systemd-notify</command> will wait until the notification message has been processed by the
65 service manager. When <option>--no-block</option> is used, this synchronization for reception of
66 notifications is disabled, and hence the aforementioned race may occur if the invoking process is not the
67 service manager or spawned by the service manager.</para>
68
69 <para><command>systemd-notify</command> will first attempt to invoke <function>sd_notify()</function>
70 pretending to have the PID of the parent process of <command>systemd-notify</command> (i.e. the invoking
71 process). This will only succeed when invoked with sufficient privileges. On failure, it will then fall
72 back to invoking it under its own PID. This behaviour is useful in order that when the tool is invoked
73 from a shell script the shell process — and not the <command>systemd-notify</command> process — appears
74 as sender of the message, which in turn is helpful if the shell process is the main process of a service,
75 due to the limitations of <varname>NotifyAccess=</varname><option>all</option>. Use the
76 <option>--pid=</option> switch to tweak this behaviour.</para>
798d3a52
ZJS
77 </refsect1>
78
79 <refsect1>
80 <title>Options</title>
81
82 <para>The following options are understood:</para>
83
84 <variablelist>
85 <varlistentry>
86 <term><option>--ready</option></term>
87
fd0f4da5
LP
88 <listitem><para>Inform the invoking service manager about service start-up or configuration reload
89 completion. This is equivalent to <command>systemd-notify READY=1</command>. For details about the
90 semantics of this option see
91 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para></listitem>
92 </varlistentry>
93
94 <varlistentry>
95 <term><option>--reloading</option></term>
96
97 <listitem><para>Inform the invoking service manager about the beginning of a configuration reload
98 cycle. This is equivalent to <command>systemd-notify RELOADING=1</command> (but implicitly also sets
99 a <varname>MONOTONIC_USEC=</varname> field as required for <varname>Type=notify-reload</varname>
100 services, see
8fb35004 101 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
fd0f4da5 102 for details). For details about the semantics of this option see
ec07c3c8
AK
103 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
104
105 <xi:include href="version-info.xml" xpointer="v253"/></listitem>
fd0f4da5
LP
106 </varlistentry>
107
108 <varlistentry>
109 <term><option>--stopping</option></term>
110
111 <listitem><para>Inform the invoking service manager about the beginning of the shutdown phase of the
112 service. This is equivalent to <command>systemd-notify STOPPING=1</command>. For details about the
113 semantics of this option see
ec07c3c8
AK
114 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
115
116 <xi:include href="version-info.xml" xpointer="v253"/></listitem>
798d3a52
ZJS
117 </varlistentry>
118
119 <varlistentry>
120 <term><option>--pid=</option></term>
121
5d4cf5a8
MY
122 <listitem><para>Inform the service manager about the main PID of the service. Takes a PID as argument.
123 If the argument is specified as <literal>auto</literal> or omitted, the PID of the process that
124 invoked <command>systemd-notify</command> is used, except if that's the service manager. If the
9dcd43b1
LP
125 argument is specified as <literal>self</literal>, the PID of the <command>systemd-notify</command>
126 command itself is used, and if <literal>parent</literal> is specified the calling process' PID is
5d4cf5a8 127 used — even if it is the service manager. <option>--pid=auto</option> is equivalent to <command>systemd-notify
9dcd43b1 128 MAINPID=$PID</command>. For details about the semantics of this option see
b7d963e5
LP
129 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
130
131 <para>If this switch is used in an <command>systemd-notify</command> invocation from a process that
132 shall become the new main process of a service — and which is not the process forked off by the
133 service manager (or the current main process) —, then it is essential to set
134 <varname>NotifyAccess=all</varname> in the service unit file, or otherwise the notification will be
135 ignored for security reasons. See
136 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
137 for details.</para></listitem>
798d3a52
ZJS
138 </varlistentry>
139
65c6b990 140 <varlistentry>
9bfabe14 141 <term><option>--uid=<replaceable>USER</replaceable></option></term>
65c6b990
LP
142
143 <listitem><para>Set the user ID to send the notification from. Takes a UNIX user name or numeric UID. When
144 specified the notification message will be sent with the specified UID as sender, in place of the user the
145 command was invoked as. This option requires sufficient privileges in order to be able manipulate the user
ec07c3c8
AK
146 identity of the process.</para>
147
148 <xi:include href="version-info.xml" xpointer="v237"/></listitem>
65c6b990
LP
149 </varlistentry>
150
798d3a52
ZJS
151 <varlistentry>
152 <term><option>--status=</option></term>
153
fd0f4da5
LP
154 <listitem><para>Send a free-form human readable status string for the daemon to the service
155 manager. This option takes the status string as argument. This is equivalent to
156 <command>systemd-notify STATUS=…</command>. For details about the semantics of this option see
157 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>. This
158 information is shown in
159 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
160 <command>status</command> output, among other places.</para></listitem>
798d3a52
ZJS
161 </varlistentry>
162
163 <varlistentry>
164 <term><option>--booted</option></term>
165
fd0f4da5
LP
166 <listitem><para>Returns 0 if the system was booted up with systemd, non-zero otherwise. If this
167 option is passed, no message is sent. This option is hence unrelated to the other options. For
168 details about the semantics of this option, see
94f099d8 169 <citerefentry><refentrytitle>sd_booted</refentrytitle><manvolnum>3</manvolnum></citerefentry>. An
a8eaaee7 170 alternate way to check for this state is to call
fd0f4da5
LP
171 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry> with
172 the <command>is-system-running</command> command. It will return <literal>offline</literal> if the
173 system was not booted with systemd. </para></listitem>
798d3a52
ZJS
174 </varlistentry>
175
5ec7a994
KKD
176 <varlistentry>
177 <term><option>--no-block</option></term>
178
885a4e6c
ZJS
179 <listitem><para>Do not synchronously wait for the requested operation to finish. Use of this option
180 is only recommended when <command>systemd-notify</command> is spawned by the service manager, or when
181 the invoking process is directly spawned by the service manager and has enough privileges to allow
182 <command>systemd-notify</command> to send the notification on its behalf. Sending notifications with
ec07c3c8
AK
183 this option set is prone to race conditions in all other cases.</para>
184
185 <xi:include href="version-info.xml" xpointer="v246"/></listitem>
5ec7a994
KKD
186 </varlistentry>
187
c4ef4df4
LP
188 <varlistentry>
189 <term><option>--exec</option></term>
190
191 <listitem><para>If specified <command>systemd-notify</command> will execute another command line
192 after it completed its operation, replacing its own process. If used, the list of assignments to
193 include in the message sent must be followed by a <literal>;</literal> character (as separate
194 argument), followed by the command line to execute. This permits "chaining" of commands, i.e. issuing
195 one operation, followed immediately by another, without changing PIDs.</para>
196
197 <para>Note that many shells interpret <literal>;</literal> as their own separator for command lines,
198 hence when <command>systemd-notify</command> is invoked from a shell the semicolon must usually be
ec07c3c8
AK
199 escaped as <literal>\;</literal>.</para>
200
201 <xi:include href="version-info.xml" xpointer="v254"/></listitem>
c4ef4df4
LP
202 </varlistentry>
203
6e4a3245
LP
204 <varlistentry>
205 <term><option>--fd=</option></term>
206
207 <listitem><para>Send a file descriptor along with the notification message. This is useful when
208 invoked in services that have the <varname>FileDescriptorStoreMax=</varname> setting enabled, see
209 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
210 for details. The specified file descriptor must be passed to <command>systemd-notify</command> when
211 invoked. This option may be used multiple times to pass multiple file descriptors in a single
212 notification message.</para>
213
bf63dadb
ZJS
214 <para>To use this functionality from a
215 <citerefentry project='man-pages'><refentrytitle>bash</refentrytitle><manvolnum>1</manvolnum></citerefentry>
216 shell, use an expression like the following:</para>
ec07c3c8
AK
217 <programlisting>systemd-notify --fd=4 --fd=5 4&lt;/some/file 5&lt;/some/other/file</programlisting>
218
219 <xi:include href="version-info.xml" xpointer="v254"/></listitem>
6e4a3245
LP
220 </varlistentry>
221
222 <varlistentry>
223 <term><option>--fdname=</option></term>
224
225 <listitem><para>Set a name to assign to the file descriptors passed via <option>--fd=</option> (see
226 above). This controls the <literal>FDNAME=</literal> field. This setting may only be specified once,
227 and applies to all file descriptors passed. Invoke this tool multiple times in case multiple file
ec07c3c8
AK
228 descriptors with different file descriptor names shall be submitted.</para>
229
230 <xi:include href="version-info.xml" xpointer="v254"/></listitem>
6e4a3245
LP
231 </varlistentry>
232
798d3a52
ZJS
233 <xi:include href="standard-options.xml" xpointer="help" />
234 <xi:include href="standard-options.xml" xpointer="version" />
235 </variablelist>
236
237 </refsect1>
238
239 <refsect1>
240 <title>Exit status</title>
241
242 <para>On success, 0 is returned, a non-zero failure code
243 otherwise.</para>
244 </refsect1>
245
246 <refsect1>
247 <title>Example</title>
248
249 <example>
250 <title>Start-up Notification and Status Updates</title>
251
fd0f4da5
LP
252 <para>A simple shell daemon that sends start-up notifications after having set up its communication
253 channel. During runtime it sends further status updates to the init system:</para>
798d3a52 254
a6ac4cbc 255 <programlisting>#!/bin/sh
c61fbdfc
LP
256
257mkfifo /tmp/waldo
1eecafb8 258systemd-notify --ready --status="Waiting for data…"
c61fbdfc
LP
259
260while : ; do
a6ac4cbc 261 read -r a &lt; /tmp/waldo
0521e286 262 systemd-notify --status="Processing $a"
c61fbdfc 263
1eecafb8 264 # Do something with $a …
c61fbdfc 265
1eecafb8 266 systemd-notify --status="Waiting for data…"
c61fbdfc 267done</programlisting>
798d3a52
ZJS
268 </example>
269 </refsect1>
270
271 <refsect1>
272 <title>See Also</title>
13a69c12
DT
273 <para><simplelist type="inline">
274 <member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
275 <member><citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
276 <member><citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
277 <member><citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
278 <member><citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
279 <member><citerefentry><refentrytitle>sd_booted</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
280 </simplelist></para>
798d3a52 281 </refsect1>
c5abba08 282</refentry>