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