]>
Commit | Line | Data |
---|---|---|
c5abba08 | 1 | <?xml version='1.0'?> <!--*-nxml-*--> |
3a54a157 | 2 | <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
12b42c76 | 3 | "http://www.oasis-open.org/docbook/xml/4.2/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> | |
26 | <command>systemd-notify <arg choice="opt" rep="repeat">OPTIONS</arg> <arg choice="opt" rep="repeat">VARIABLE=VALUE</arg></command> | |
27 | </cmdsynopsis> | |
c4ef4df4 LP |
28 | <cmdsynopsis> |
29 | <command>systemd-notify --exec <arg choice="opt" rep="repeat">OPTIONS</arg> <arg choice="opt" rep="repeat">VARIABLE=VALUE</arg> ; <arg rep="repeat">CMDLINE</arg></command> | |
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 LP |
102 | for details). For details about the semantics of this option see |
103 | <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para></listitem> | |
104 | </varlistentry> | |
105 | ||
106 | <varlistentry> | |
107 | <term><option>--stopping</option></term> | |
108 | ||
109 | <listitem><para>Inform the invoking service manager about the beginning of the shutdown phase of the | |
110 | service. This is equivalent to <command>systemd-notify STOPPING=1</command>. For details about the | |
111 | semantics of this option see | |
798d3a52 ZJS |
112 | <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para></listitem> |
113 | </varlistentry> | |
114 | ||
115 | <varlistentry> | |
116 | <term><option>--pid=</option></term> | |
117 | ||
fd0f4da5 | 118 | <listitem><para>Inform the service manager about the main PID of the service. Takes a PID as |
9dcd43b1 LP |
119 | argument. If the argument is specified as <literal>auto</literal> or omitted, the PID of the process |
120 | that invoked <command>systemd-notify</command> is used, except if that's the service manager. If the | |
121 | argument is specified as <literal>self</literal>, the PID of the <command>systemd-notify</command> | |
122 | command itself is used, and if <literal>parent</literal> is specified the calling process' PID is | |
fd0f4da5 | 123 | used — even if it is the service manager. The latter is equivalent to <command>systemd-notify |
9dcd43b1 | 124 | MAINPID=$PID</command>. For details about the semantics of this option see |
b7d963e5 LP |
125 | <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para> |
126 | ||
127 | <para>If this switch is used in an <command>systemd-notify</command> invocation from a process that | |
128 | shall become the new main process of a service — and which is not the process forked off by the | |
129 | service manager (or the current main process) —, then it is essential to set | |
130 | <varname>NotifyAccess=all</varname> in the service unit file, or otherwise the notification will be | |
131 | ignored for security reasons. See | |
132 | <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry> | |
133 | for details.</para></listitem> | |
798d3a52 ZJS |
134 | </varlistentry> |
135 | ||
65c6b990 LP |
136 | <varlistentry> |
137 | <term><option>--uid=</option><replaceable>USER</replaceable></term> | |
138 | ||
139 | <listitem><para>Set the user ID to send the notification from. Takes a UNIX user name or numeric UID. When | |
140 | specified the notification message will be sent with the specified UID as sender, in place of the user the | |
141 | command was invoked as. This option requires sufficient privileges in order to be able manipulate the user | |
142 | identity of the process.</para></listitem> | |
143 | </varlistentry> | |
144 | ||
798d3a52 ZJS |
145 | <varlistentry> |
146 | <term><option>--status=</option></term> | |
147 | ||
fd0f4da5 LP |
148 | <listitem><para>Send a free-form human readable status string for the daemon to the service |
149 | manager. This option takes the status string as argument. This is equivalent to | |
150 | <command>systemd-notify STATUS=…</command>. For details about the semantics of this option see | |
151 | <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>. This | |
152 | information is shown in | |
153 | <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s | |
154 | <command>status</command> output, among other places.</para></listitem> | |
798d3a52 ZJS |
155 | </varlistentry> |
156 | ||
157 | <varlistentry> | |
158 | <term><option>--booted</option></term> | |
159 | ||
fd0f4da5 LP |
160 | <listitem><para>Returns 0 if the system was booted up with systemd, non-zero otherwise. If this |
161 | option is passed, no message is sent. This option is hence unrelated to the other options. For | |
162 | details about the semantics of this option, see | |
94f099d8 | 163 | <citerefentry><refentrytitle>sd_booted</refentrytitle><manvolnum>3</manvolnum></citerefentry>. An |
a8eaaee7 | 164 | alternate way to check for this state is to call |
fd0f4da5 LP |
165 | <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry> with |
166 | the <command>is-system-running</command> command. It will return <literal>offline</literal> if the | |
167 | system was not booted with systemd. </para></listitem> | |
798d3a52 ZJS |
168 | </varlistentry> |
169 | ||
5ec7a994 KKD |
170 | <varlistentry> |
171 | <term><option>--no-block</option></term> | |
172 | ||
885a4e6c ZJS |
173 | <listitem><para>Do not synchronously wait for the requested operation to finish. Use of this option |
174 | is only recommended when <command>systemd-notify</command> is spawned by the service manager, or when | |
175 | the invoking process is directly spawned by the service manager and has enough privileges to allow | |
176 | <command>systemd-notify</command> to send the notification on its behalf. Sending notifications with | |
5ec7a994 KKD |
177 | this option set is prone to race conditions in all other cases.</para></listitem> |
178 | </varlistentry> | |
179 | ||
c4ef4df4 LP |
180 | <varlistentry> |
181 | <term><option>--exec</option></term> | |
182 | ||
183 | <listitem><para>If specified <command>systemd-notify</command> will execute another command line | |
184 | after it completed its operation, replacing its own process. If used, the list of assignments to | |
185 | include in the message sent must be followed by a <literal>;</literal> character (as separate | |
186 | argument), followed by the command line to execute. This permits "chaining" of commands, i.e. issuing | |
187 | one operation, followed immediately by another, without changing PIDs.</para> | |
188 | ||
189 | <para>Note that many shells interpret <literal>;</literal> as their own separator for command lines, | |
190 | hence when <command>systemd-notify</command> is invoked from a shell the semicolon must usually be | |
191 | escaped as <literal>\;</literal>.</para></listitem> | |
192 | </varlistentry> | |
193 | ||
6e4a3245 LP |
194 | <varlistentry> |
195 | <term><option>--fd=</option></term> | |
196 | ||
197 | <listitem><para>Send a file descriptor along with the notification message. This is useful when | |
198 | invoked in services that have the <varname>FileDescriptorStoreMax=</varname> setting enabled, see | |
199 | <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry> | |
200 | for details. The specified file descriptor must be passed to <command>systemd-notify</command> when | |
201 | invoked. This option may be used multiple times to pass multiple file descriptors in a single | |
202 | notification message.</para> | |
203 | ||
204 | <para>To use this functionality from a <command>bash</command> shell, use an expression like the following:</para> | |
205 | <programlisting>systemd-notify --fd=4 --fd=5 4</some/file 5</some/other/file</programlisting></listitem> | |
206 | </varlistentry> | |
207 | ||
208 | <varlistentry> | |
209 | <term><option>--fdname=</option></term> | |
210 | ||
211 | <listitem><para>Set a name to assign to the file descriptors passed via <option>--fd=</option> (see | |
212 | above). This controls the <literal>FDNAME=</literal> field. This setting may only be specified once, | |
213 | and applies to all file descriptors passed. Invoke this tool multiple times in case multiple file | |
214 | descriptors with different file descriptor names shall be submitted.</para></listitem> | |
215 | </varlistentry> | |
216 | ||
798d3a52 ZJS |
217 | <xi:include href="standard-options.xml" xpointer="help" /> |
218 | <xi:include href="standard-options.xml" xpointer="version" /> | |
219 | </variablelist> | |
220 | ||
221 | </refsect1> | |
222 | ||
223 | <refsect1> | |
224 | <title>Exit status</title> | |
225 | ||
226 | <para>On success, 0 is returned, a non-zero failure code | |
227 | otherwise.</para> | |
228 | </refsect1> | |
229 | ||
230 | <refsect1> | |
231 | <title>Example</title> | |
232 | ||
233 | <example> | |
234 | <title>Start-up Notification and Status Updates</title> | |
235 | ||
fd0f4da5 LP |
236 | <para>A simple shell daemon that sends start-up notifications after having set up its communication |
237 | channel. During runtime it sends further status updates to the init system:</para> | |
798d3a52 | 238 | |
a6ac4cbc | 239 | <programlisting>#!/bin/sh |
c61fbdfc LP |
240 | |
241 | mkfifo /tmp/waldo | |
1eecafb8 | 242 | systemd-notify --ready --status="Waiting for data…" |
c61fbdfc LP |
243 | |
244 | while : ; do | |
a6ac4cbc | 245 | read -r a < /tmp/waldo |
0521e286 | 246 | systemd-notify --status="Processing $a" |
c61fbdfc | 247 | |
1eecafb8 | 248 | # Do something with $a … |
c61fbdfc | 249 | |
1eecafb8 | 250 | systemd-notify --status="Waiting for data…" |
c61fbdfc | 251 | done</programlisting> |
798d3a52 ZJS |
252 | </example> |
253 | </refsect1> | |
254 | ||
255 | <refsect1> | |
256 | <title>See Also</title> | |
257 | <para> | |
258 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
259 | <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
260 | <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>, | |
b7d963e5 | 261 | <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>, |
798d3a52 ZJS |
262 | <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
263 | <citerefentry><refentrytitle>sd_booted</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
264 | </para> | |
265 | </refsect1> | |
c5abba08 | 266 | </refentry> |