]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/systemd-notify.xml
tree-wide: remove Lennart's copyright lines
[thirdparty/systemd.git] / man / systemd-notify.xml
CommitLineData
c5abba08
LP
1<?xml version='1.0'?> <!--*-nxml-*-->
2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
12b42c76 3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
c5abba08
LP
4
5<!--
572eb058 6 SPDX-License-Identifier: LGPL-2.1+
c5abba08
LP
7-->
8
dfdebb1b 9<refentry id="systemd-notify"
798d3a52
ZJS
10 xmlns:xi="http://www.w3.org/2001/XInclude">
11
12 <refentryinfo>
13 <title>systemd-notify</title>
14 <productname>systemd</productname>
15
16 <authorgroup>
17 <author>
18 <contrib>Developer</contrib>
19 <firstname>Lennart</firstname>
20 <surname>Poettering</surname>
21 <email>lennart@poettering.net</email>
22 </author>
23 </authorgroup>
24 </refentryinfo>
25
26 <refmeta>
27 <refentrytitle>systemd-notify</refentrytitle>
28 <manvolnum>1</manvolnum>
29 </refmeta>
30
31 <refnamediv>
32 <refname>systemd-notify</refname>
33 <refpurpose>Notify service manager about start-up completion and other daemon status changes</refpurpose>
34 </refnamediv>
35
36 <refsynopsisdiv>
37 <cmdsynopsis>
38 <command>systemd-notify <arg choice="opt" rep="repeat">OPTIONS</arg> <arg choice="opt" rep="repeat">VARIABLE=VALUE</arg></command>
39 </cmdsynopsis>
40 </refsynopsisdiv>
41
42 <refsect1>
43 <title>Description</title>
44
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
b938cb90 48 environment-block-like list of strings. Most importantly, it can be
798d3a52
ZJS
49 used for start-up completion notification.</para>
50
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>.
55 </para>
56
57 <para>The command line may carry a list of environment variables
58 to send as part of the status update.</para>
59
b3bb6476
LP
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>
62
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>
aa203945
LP
71
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>
798d3a52
ZJS
78 </refsect1>
79
80 <refsect1>
81 <title>Options</title>
82
83 <para>The following options are understood:</para>
84
85 <variablelist>
86 <varlistentry>
87 <term><option>--ready</option></term>
88
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
92 option see
93 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para></listitem>
94 </varlistentry>
95
96 <varlistentry>
97 <term><option>--pid=</option></term>
98
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>
106 </varlistentry>
107
65c6b990
LP
108 <varlistentry>
109 <term><option>--uid=</option><replaceable>USER</replaceable></term>
110
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>
115 </varlistentry>
116
798d3a52
ZJS
117 <varlistentry>
118 <term><option>--status=</option></term>
119
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
1eecafb8 123 STATUS=…</command>. For details about the semantics of this
798d3a52
ZJS
124 option see
125 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para></listitem>
126 </varlistentry>
127
128 <varlistentry>
129 <term><option>--booted</option></term>
130
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
94f099d8 135 <citerefentry><refentrytitle>sd_booted</refentrytitle><manvolnum>3</manvolnum></citerefentry>. An
a8eaaee7 136 alternate way to check for this state is to call
94f099d8
LP
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>
798d3a52
ZJS
141 </varlistentry>
142
143 <xi:include href="standard-options.xml" xpointer="help" />
144 <xi:include href="standard-options.xml" xpointer="version" />
145 </variablelist>
146
147 </refsect1>
148
149 <refsect1>
150 <title>Exit status</title>
151
152 <para>On success, 0 is returned, a non-zero failure code
153 otherwise.</para>
154 </refsect1>
155
156 <refsect1>
157 <title>Example</title>
158
159 <example>
160 <title>Start-up Notification and Status Updates</title>
161
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>
165
166 <programlisting>#!/bin/bash
c61fbdfc
LP
167
168mkfifo /tmp/waldo
1eecafb8 169systemd-notify --ready --status="Waiting for data…"
c61fbdfc
LP
170
171while : ; do
0521e286
LP
172 read a &lt; /tmp/waldo
173 systemd-notify --status="Processing $a"
c61fbdfc 174
1eecafb8 175 # Do something with $a …
c61fbdfc 176
1eecafb8 177 systemd-notify --status="Waiting for data…"
c61fbdfc 178done</programlisting>
798d3a52
ZJS
179 </example>
180 </refsect1>
181
182 <refsect1>
183 <title>See Also</title>
184 <para>
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>
190 </para>
191 </refsect1>
c5abba08
LP
192
193</refentry>