]>
Commit | Line | Data |
---|---|---|
c5abba08 | 1 | <?xml version='1.0'?> <!--*-nxml-*--> |
3a54a157 | 2 | <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
12b42c76 | 3 | "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> |
0307f791 | 4 | <!-- SPDX-License-Identifier: LGPL-2.1+ --> |
c5abba08 | 5 | |
dfdebb1b | 6 | <refentry id="systemd-notify" |
798d3a52 ZJS |
7 | xmlns:xi="http://www.w3.org/2001/XInclude"> |
8 | ||
9 | <refentryinfo> | |
10 | <title>systemd-notify</title> | |
11 | <productname>systemd</productname> | |
798d3a52 ZJS |
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 | |
b938cb90 | 36 | environment-block-like list of strings. Most importantly, it can be |
798d3a52 ZJS |
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 | ||
b3bb6476 LP |
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> | |
aa203945 LP |
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> | |
798d3a52 ZJS |
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 | ||
9dcd43b1 LP |
87 | <listitem><para>Inform the service manager about the main PID of the daemon. Takes a PID as |
88 | argument. If the argument is specified as <literal>auto</literal> or omitted, the PID of the process | |
89 | that invoked <command>systemd-notify</command> is used, except if that's the service manager. If the | |
90 | argument is specified as <literal>self</literal>, the PID of the <command>systemd-notify</command> | |
91 | command itself is used, and if <literal>parent</literal> is specified the calling process' PID is | |
92 | used — even if it is the service manager. This is equivalent to <command>systemd-notify | |
93 | MAINPID=$PID</command>. For details about the semantics of this option see | |
798d3a52 ZJS |
94 | <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para></listitem> |
95 | </varlistentry> | |
96 | ||
65c6b990 LP |
97 | <varlistentry> |
98 | <term><option>--uid=</option><replaceable>USER</replaceable></term> | |
99 | ||
100 | <listitem><para>Set the user ID to send the notification from. Takes a UNIX user name or numeric UID. When | |
101 | specified the notification message will be sent with the specified UID as sender, in place of the user the | |
102 | command was invoked as. This option requires sufficient privileges in order to be able manipulate the user | |
103 | identity of the process.</para></listitem> | |
104 | </varlistentry> | |
105 | ||
798d3a52 ZJS |
106 | <varlistentry> |
107 | <term><option>--status=</option></term> | |
108 | ||
109 | <listitem><para>Send a free-form status string for the daemon | |
110 | to the init systemd. This option takes the status string as | |
111 | argument. This is equivalent to <command>systemd-notify | |
1eecafb8 | 112 | STATUS=…</command>. For details about the semantics of this |
798d3a52 ZJS |
113 | option see |
114 | <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para></listitem> | |
115 | </varlistentry> | |
116 | ||
117 | <varlistentry> | |
118 | <term><option>--booted</option></term> | |
119 | ||
120 | <listitem><para>Returns 0 if the system was booted up with | |
121 | systemd, non-zero otherwise. If this option is passed, no | |
122 | message is sent. This option is hence unrelated to the other | |
123 | options. For details about the semantics of this option, see | |
94f099d8 | 124 | <citerefentry><refentrytitle>sd_booted</refentrytitle><manvolnum>3</manvolnum></citerefentry>. An |
a8eaaee7 | 125 | alternate way to check for this state is to call |
94f099d8 LP |
126 | <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry> |
127 | with the <command>is-system-running</command> command. It will | |
128 | return <literal>offline</literal> if the system was not booted | |
129 | with systemd. </para></listitem> | |
798d3a52 ZJS |
130 | </varlistentry> |
131 | ||
132 | <xi:include href="standard-options.xml" xpointer="help" /> | |
133 | <xi:include href="standard-options.xml" xpointer="version" /> | |
134 | </variablelist> | |
135 | ||
136 | </refsect1> | |
137 | ||
138 | <refsect1> | |
139 | <title>Exit status</title> | |
140 | ||
141 | <para>On success, 0 is returned, a non-zero failure code | |
142 | otherwise.</para> | |
143 | </refsect1> | |
144 | ||
145 | <refsect1> | |
146 | <title>Example</title> | |
147 | ||
148 | <example> | |
149 | <title>Start-up Notification and Status Updates</title> | |
150 | ||
151 | <para>A simple shell daemon that sends start-up notifications | |
152 | after having set up its communication channel. During runtime it | |
153 | sends further status updates to the init system:</para> | |
154 | ||
155 | <programlisting>#!/bin/bash | |
c61fbdfc LP |
156 | |
157 | mkfifo /tmp/waldo | |
1eecafb8 | 158 | systemd-notify --ready --status="Waiting for data…" |
c61fbdfc LP |
159 | |
160 | while : ; do | |
0521e286 LP |
161 | read a < /tmp/waldo |
162 | systemd-notify --status="Processing $a" | |
c61fbdfc | 163 | |
1eecafb8 | 164 | # Do something with $a … |
c61fbdfc | 165 | |
1eecafb8 | 166 | systemd-notify --status="Waiting for data…" |
c61fbdfc | 167 | done</programlisting> |
798d3a52 ZJS |
168 | </example> |
169 | </refsect1> | |
170 | ||
171 | <refsect1> | |
172 | <title>See Also</title> | |
173 | <para> | |
174 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
175 | <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
176 | <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>, | |
177 | <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
178 | <citerefentry><refentrytitle>sd_booted</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
179 | </para> | |
180 | </refsect1> | |
c5abba08 LP |
181 | |
182 | </refentry> |