]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/systemd-notify.xml
travis: add more ASan options
[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
58 <varname>NotifyAccess=</varname><option>all</option> is set for it.</para>
59
60 <para><command>systemd-notify</command> will first attempt to invoke <function>sd_notify()</function> pretending to
61 have the PID of the invoking process. This will only succeed when invoked with sufficient privileges. On failure,
62 it will then fall back to invoking it under its own PID. This behaviour is useful in order that when the tool is
63 invoked from a shell script the shell process — and not the <command>systemd-notify</command> process — appears as
64 sender of the message, which in turn is helpful if the shell process is the main process of a service, due to the
65 limitations of <varname>NotifyAccess=</varname><option>all</option> described above.</para>
66 </refsect1>
67
68 <refsect1>
69 <title>Options</title>
70
71 <para>The following options are understood:</para>
72
73 <variablelist>
74 <varlistentry>
75 <term><option>--ready</option></term>
76
77 <listitem><para>Inform the init system about service start-up
78 completion. This is equivalent to <command>systemd-notify
79 READY=1</command>. For details about the semantics of this
80 option see
81 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para></listitem>
82 </varlistentry>
83
84 <varlistentry>
85 <term><option>--pid=</option></term>
86
87 <listitem><para>Inform the init system about the main PID of
88 the daemon. Takes a PID as argument. If the argument is
89 omitted, the PID of the process that invoked
90 <command>systemd-notify</command> is used. This is equivalent
91 to <command>systemd-notify MAINPID=$PID</command>. For details
92 about the semantics of this option see
93 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para></listitem>
94 </varlistentry>
95
96 <varlistentry>
97 <term><option>--uid=</option><replaceable>USER</replaceable></term>
98
99 <listitem><para>Set the user ID to send the notification from. Takes a UNIX user name or numeric UID. When
100 specified the notification message will be sent with the specified UID as sender, in place of the user the
101 command was invoked as. This option requires sufficient privileges in order to be able manipulate the user
102 identity of the process.</para></listitem>
103 </varlistentry>
104
105 <varlistentry>
106 <term><option>--status=</option></term>
107
108 <listitem><para>Send a free-form status string for the daemon
109 to the init systemd. This option takes the status string as
110 argument. This is equivalent to <command>systemd-notify
111 STATUS=…</command>. For details about the semantics of this
112 option see
113 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para></listitem>
114 </varlistentry>
115
116 <varlistentry>
117 <term><option>--booted</option></term>
118
119 <listitem><para>Returns 0 if the system was booted up with
120 systemd, non-zero otherwise. If this option is passed, no
121 message is sent. This option is hence unrelated to the other
122 options. For details about the semantics of this option, see
123 <citerefentry><refentrytitle>sd_booted</refentrytitle><manvolnum>3</manvolnum></citerefentry>. An
124 alternate way to check for this state is to call
125 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
126 with the <command>is-system-running</command> command. It will
127 return <literal>offline</literal> if the system was not booted
128 with systemd. </para></listitem>
129 </varlistentry>
130
131 <xi:include href="standard-options.xml" xpointer="help" />
132 <xi:include href="standard-options.xml" xpointer="version" />
133 </variablelist>
134
135 </refsect1>
136
137 <refsect1>
138 <title>Exit status</title>
139
140 <para>On success, 0 is returned, a non-zero failure code
141 otherwise.</para>
142 </refsect1>
143
144 <refsect1>
145 <title>Example</title>
146
147 <example>
148 <title>Start-up Notification and Status Updates</title>
149
150 <para>A simple shell daemon that sends start-up notifications
151 after having set up its communication channel. During runtime it
152 sends further status updates to the init system:</para>
153
154 <programlisting>#!/bin/bash
155
156 mkfifo /tmp/waldo
157 systemd-notify --ready --status="Waiting for data…"
158
159 while : ; do
160 read a &lt; /tmp/waldo
161 systemd-notify --status="Processing $a"
162
163 # Do something with $a …
164
165 systemd-notify --status="Waiting for data…"
166 done</programlisting>
167 </example>
168 </refsect1>
169
170 <refsect1>
171 <title>See Also</title>
172 <para>
173 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
174 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
175 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
176 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
177 <citerefentry><refentrytitle>sd_booted</refentrytitle><manvolnum>3</manvolnum></citerefentry>
178 </para>
179 </refsect1>
180
181 </refentry>