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