]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/systemd-notify.xml
verify: use manager_load_startable_unit_or_warn() to load units for verification
[thirdparty/systemd.git] / man / systemd-notify.xml
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">
4
5 <!--
6 SPDX-License-Identifier: LGPL-2.1+
7
8 This file is part of systemd.
9
10 Copyright 2010 Lennart Poettering
11
12 systemd is free software; you can redistribute it and/or modify it
13 under the terms of the GNU Lesser General Public License as published by
14 the Free Software Foundation; either version 2.1 of the License, or
15 (at your option) any later version.
16
17 systemd is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 Lesser General Public License for more details.
21
22 You should have received a copy of the GNU Lesser General Public License
23 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 -->
25
26 <refentry id="systemd-notify"
27 xmlns:xi="http://www.w3.org/2001/XInclude">
28
29 <refentryinfo>
30 <title>systemd-notify</title>
31 <productname>systemd</productname>
32
33 <authorgroup>
34 <author>
35 <contrib>Developer</contrib>
36 <firstname>Lennart</firstname>
37 <surname>Poettering</surname>
38 <email>lennart@poettering.net</email>
39 </author>
40 </authorgroup>
41 </refentryinfo>
42
43 <refmeta>
44 <refentrytitle>systemd-notify</refentrytitle>
45 <manvolnum>1</manvolnum>
46 </refmeta>
47
48 <refnamediv>
49 <refname>systemd-notify</refname>
50 <refpurpose>Notify service manager about start-up completion and other daemon status changes</refpurpose>
51 </refnamediv>
52
53 <refsynopsisdiv>
54 <cmdsynopsis>
55 <command>systemd-notify <arg choice="opt" rep="repeat">OPTIONS</arg> <arg choice="opt" rep="repeat">VARIABLE=VALUE</arg></command>
56 </cmdsynopsis>
57 </refsynopsisdiv>
58
59 <refsect1>
60 <title>Description</title>
61
62 <para><command>systemd-notify</command> may be called by daemon
63 scripts to notify the init system about status changes. It can be
64 used to send arbitrary information, encoded in an
65 environment-block-like list of strings. Most importantly, it can be
66 used for start-up completion notification.</para>
67
68 <para>This is mostly just a wrapper around
69 <function>sd_notify()</function> and makes this functionality
70 available to shell scripts. For details see
71 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
72 </para>
73
74 <para>The command line may carry a list of environment variables
75 to send as part of the status update.</para>
76
77 <para>Note that systemd will refuse reception of status updates from this command unless
78 <varname>NotifyAccess=</varname> is set for the service unit this command is called from.</para>
79
80 <para>Note that <function>sd_notify()</function> notifications may be attributed to units correctly only if either
81 the sending process is still around at the time PID 1 processes the message, or if the sending process is
82 explicitly runtime-tracked by the service manager. The latter is the case if the service manager originally forked
83 off the process, i.e. on all processes that match <varname>NotifyAccess=</varname><option>main</option> or
84 <varname>NotifyAccess=</varname><option>exec</option>. Conversely, if an auxiliary process of the unit sends an
85 <function>sd_notify()</function> message and immediately exits, the service manager might not be able to properly
86 attribute the message to the unit, and thus will ignore it, even if
87 <varname>NotifyAccess=</varname><option>all</option> is set for it.</para>
88
89 <para><command>systemd-notify</command> will first attempt to invoke <function>sd_notify()</function> pretending to
90 have the PID of the invoking process. This will only succeed when invoked with sufficient privileges. On failure,
91 it will then fall back to invoking it under its own PID. This behaviour is useful in order that when the tool is
92 invoked from a shell script the shell process — and not the <command>systemd-notify</command> process — appears as
93 sender of the message, which in turn is helpful if the shell process is the main process of a service, due to the
94 limitations of <varname>NotifyAccess=</varname><option>all</option> described above.</para>
95 </refsect1>
96
97 <refsect1>
98 <title>Options</title>
99
100 <para>The following options are understood:</para>
101
102 <variablelist>
103 <varlistentry>
104 <term><option>--ready</option></term>
105
106 <listitem><para>Inform the init system about service start-up
107 completion. This is equivalent to <command>systemd-notify
108 READY=1</command>. For details about the semantics of this
109 option see
110 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para></listitem>
111 </varlistentry>
112
113 <varlistentry>
114 <term><option>--pid=</option></term>
115
116 <listitem><para>Inform the init system about the main PID of
117 the daemon. Takes a PID as argument. If the argument is
118 omitted, the PID of the process that invoked
119 <command>systemd-notify</command> is used. This is equivalent
120 to <command>systemd-notify MAINPID=$PID</command>. For details
121 about the semantics of this option see
122 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para></listitem>
123 </varlistentry>
124
125 <varlistentry>
126 <term><option>--uid=</option><replaceable>USER</replaceable></term>
127
128 <listitem><para>Set the user ID to send the notification from. Takes a UNIX user name or numeric UID. When
129 specified the notification message will be sent with the specified UID as sender, in place of the user the
130 command was invoked as. This option requires sufficient privileges in order to be able manipulate the user
131 identity of the process.</para></listitem>
132 </varlistentry>
133
134 <varlistentry>
135 <term><option>--status=</option></term>
136
137 <listitem><para>Send a free-form status string for the daemon
138 to the init systemd. This option takes the status string as
139 argument. This is equivalent to <command>systemd-notify
140 STATUS=…</command>. For details about the semantics of this
141 option see
142 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para></listitem>
143 </varlistentry>
144
145 <varlistentry>
146 <term><option>--booted</option></term>
147
148 <listitem><para>Returns 0 if the system was booted up with
149 systemd, non-zero otherwise. If this option is passed, no
150 message is sent. This option is hence unrelated to the other
151 options. For details about the semantics of this option, see
152 <citerefentry><refentrytitle>sd_booted</refentrytitle><manvolnum>3</manvolnum></citerefentry>. An
153 alternate way to check for this state is to call
154 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
155 with the <command>is-system-running</command> command. It will
156 return <literal>offline</literal> if the system was not booted
157 with systemd. </para></listitem>
158 </varlistentry>
159
160 <xi:include href="standard-options.xml" xpointer="help" />
161 <xi:include href="standard-options.xml" xpointer="version" />
162 </variablelist>
163
164 </refsect1>
165
166 <refsect1>
167 <title>Exit status</title>
168
169 <para>On success, 0 is returned, a non-zero failure code
170 otherwise.</para>
171 </refsect1>
172
173 <refsect1>
174 <title>Example</title>
175
176 <example>
177 <title>Start-up Notification and Status Updates</title>
178
179 <para>A simple shell daemon that sends start-up notifications
180 after having set up its communication channel. During runtime it
181 sends further status updates to the init system:</para>
182
183 <programlisting>#!/bin/bash
184
185 mkfifo /tmp/waldo
186 systemd-notify --ready --status="Waiting for data…"
187
188 while : ; do
189 read a &lt; /tmp/waldo
190 systemd-notify --status="Processing $a"
191
192 # Do something with $a …
193
194 systemd-notify --status="Waiting for data…"
195 done</programlisting>
196 </example>
197 </refsect1>
198
199 <refsect1>
200 <title>See Also</title>
201 <para>
202 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
203 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
204 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
205 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
206 <citerefentry><refentrytitle>sd_booted</refentrytitle><manvolnum>3</manvolnum></citerefentry>
207 </para>
208 </refsect1>
209
210 </refentry>