]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/systemd-notify.xml
man: fix link markup
[thirdparty/systemd.git] / man / systemd-notify.xml
1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1+ -->
5
6 <refentry id="systemd-notify"
7 xmlns:xi="http://www.w3.org/2001/XInclude">
8
9 <refentryinfo>
10 <title>systemd-notify</title>
11 <productname>systemd</productname>
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>
28 </refsynopsisdiv>
29
30 <refsect1>
31 <title>Description</title>
32
33 <para><command>systemd-notify</command> may be called by daemon
34 scripts to notify the init system about status changes. It can be
35 used to send arbitrary information, encoded in an
36 environment-block-like list of strings. Most importantly, it can be
37 used for start-up completion notification.</para>
38
39 <para>This is mostly just a wrapper around
40 <function>sd_notify()</function> and makes this functionality
41 available to shell scripts. For details see
42 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
43 </para>
44
45 <para>The command line may carry a list of environment variables
46 to send as part of the status update.</para>
47
48 <para>Note that systemd will refuse reception of status updates from this command unless
49 <varname>NotifyAccess=</varname> is set for the service unit this command is called from.</para>
50
51 <para>Note that <function>sd_notify()</function> notifications may be attributed to units correctly only if either
52 the sending process is still around at the time PID 1 processes the message, or if the sending process is
53 explicitly runtime-tracked by the service manager. The latter is the case if the service manager originally forked
54 off the process, i.e. on all processes that match <varname>NotifyAccess=</varname><option>main</option> or
55 <varname>NotifyAccess=</varname><option>exec</option>. Conversely, if an auxiliary process of the unit sends an
56 <function>sd_notify()</function> message and immediately exits, the service manager might not be able to properly
57 attribute the message to the unit, and thus will ignore it, even if <varname>NotifyAccess=</varname><option>all
58 </option> is set for it. When <option>--no-block</option> is used, all synchronization for reception of notifications
59 is disabled, and hence the aforementioned race may occur if the invoking process is not the service manager or spawned
60 by the service manager.</para>
61
62 <para>Hence, <command>systemd-notify</command> will first attempt to invoke <function>sd_notify()</function>
63 pretending to have the PID of the invoking process. This will only succeed when invoked with sufficient privileges.
64 On failure, it will then fall back to invoking it under its own PID. This behaviour is useful in order that when
65 the tool is invoked from a shell script the shell process — and not the <command>systemd-notify</command> process
66 — appears as sender of the message, which in turn is helpful if the shell process is the main process of a service,
67 due to the limitations of <varname>NotifyAccess=</varname><option>all</option>. Use the <option>--pid=</option>
68 switch to tweak this behaviour.</para>
69
70 </refsect1>
71
72 <refsect1>
73 <title>Options</title>
74
75 <para>The following options are understood:</para>
76
77 <variablelist>
78 <varlistentry>
79 <term><option>--ready</option></term>
80
81 <listitem><para>Inform the init system about service start-up
82 completion. This is equivalent to <command>systemd-notify
83 READY=1</command>. For details about the semantics of this
84 option see
85 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para></listitem>
86 </varlistentry>
87
88 <varlistentry>
89 <term><option>--pid=</option></term>
90
91 <listitem><para>Inform the service manager about the main PID of the daemon. Takes a PID as
92 argument. If the argument is specified as <literal>auto</literal> or omitted, the PID of the process
93 that invoked <command>systemd-notify</command> is used, except if that's the service manager. If the
94 argument is specified as <literal>self</literal>, the PID of the <command>systemd-notify</command>
95 command itself is used, and if <literal>parent</literal> is specified the calling process' PID is
96 used — even if it is the service manager. This is equivalent to <command>systemd-notify
97 MAINPID=$PID</command>. For details about the semantics of this option see
98 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para></listitem>
99 </varlistentry>
100
101 <varlistentry>
102 <term><option>--uid=</option><replaceable>USER</replaceable></term>
103
104 <listitem><para>Set the user ID to send the notification from. Takes a UNIX user name or numeric UID. When
105 specified the notification message will be sent with the specified UID as sender, in place of the user the
106 command was invoked as. This option requires sufficient privileges in order to be able manipulate the user
107 identity of the process.</para></listitem>
108 </varlistentry>
109
110 <varlistentry>
111 <term><option>--status=</option></term>
112
113 <listitem><para>Send a free-form status string for the daemon
114 to the init systemd. This option takes the status string as
115 argument. This is equivalent to <command>systemd-notify
116 STATUS=…</command>. For details about the semantics of this
117 option see
118 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para></listitem>
119 </varlistentry>
120
121 <varlistentry>
122 <term><option>--booted</option></term>
123
124 <listitem><para>Returns 0 if the system was booted up with
125 systemd, non-zero otherwise. If this option is passed, no
126 message is sent. This option is hence unrelated to the other
127 options. For details about the semantics of this option, see
128 <citerefentry><refentrytitle>sd_booted</refentrytitle><manvolnum>3</manvolnum></citerefentry>. An
129 alternate way to check for this state is to call
130 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
131 with the <command>is-system-running</command> command. It will
132 return <literal>offline</literal> if the system was not booted
133 with systemd. </para></listitem>
134 </varlistentry>
135
136 <varlistentry>
137 <term><option>--no-block</option></term>
138
139 <listitem><para>Do not synchronously wait for the requested operation to finish.
140 Use of this option is only recommended when <command>systemd-notify</command>
141 is spawned by the service manager, or when the invoking process is directly spawned
142 by the service manager and has enough privileges to allow <command>systemd-notify
143 </command> to send the notification on its behalf. Sending notifications with
144 this option set is prone to race conditions in all other cases.</para></listitem>
145 </varlistentry>
146
147 <xi:include href="standard-options.xml" xpointer="help" />
148 <xi:include href="standard-options.xml" xpointer="version" />
149 </variablelist>
150
151 </refsect1>
152
153 <refsect1>
154 <title>Exit status</title>
155
156 <para>On success, 0 is returned, a non-zero failure code
157 otherwise.</para>
158 </refsect1>
159
160 <refsect1>
161 <title>Example</title>
162
163 <example>
164 <title>Start-up Notification and Status Updates</title>
165
166 <para>A simple shell daemon that sends start-up notifications
167 after having set up its communication channel. During runtime it
168 sends further status updates to the init system:</para>
169
170 <programlisting>#!/bin/bash
171
172 mkfifo /tmp/waldo
173 systemd-notify --ready --status="Waiting for data…"
174
175 while : ; do
176 read a &lt; /tmp/waldo
177 systemd-notify --status="Processing $a"
178
179 # Do something with $a …
180
181 systemd-notify --status="Waiting for data…"
182 done</programlisting>
183 </example>
184 </refsect1>
185
186 <refsect1>
187 <title>See Also</title>
188 <para>
189 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
190 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
191 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
192 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
193 <citerefentry><refentrytitle>sd_booted</refentrytitle><manvolnum>3</manvolnum></citerefentry>
194 </para>
195 </refsect1>
196
197 </refentry>