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