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