]>
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 | ||
87 | <listitem><para>Inform the init system about the main PID of | |
88 | the daemon. Takes a PID as argument. If the argument is | |
89 | omitted, the PID of the process that invoked | |
90 | <command>systemd-notify</command> is used. This is equivalent | |
91 | to <command>systemd-notify MAINPID=$PID</command>. For details | |
92 | about the semantics of this option see | |
93 | <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para></listitem> | |
94 | </varlistentry> | |
95 | ||
65c6b990 LP |
96 | <varlistentry> |
97 | <term><option>--uid=</option><replaceable>USER</replaceable></term> | |
98 | ||
99 | <listitem><para>Set the user ID to send the notification from. Takes a UNIX user name or numeric UID. When | |
100 | specified the notification message will be sent with the specified UID as sender, in place of the user the | |
101 | command was invoked as. This option requires sufficient privileges in order to be able manipulate the user | |
102 | identity of the process.</para></listitem> | |
103 | </varlistentry> | |
104 | ||
798d3a52 ZJS |
105 | <varlistentry> |
106 | <term><option>--status=</option></term> | |
107 | ||
108 | <listitem><para>Send a free-form status string for the daemon | |
109 | to the init systemd. This option takes the status string as | |
110 | argument. This is equivalent to <command>systemd-notify | |
1eecafb8 | 111 | STATUS=…</command>. For details about the semantics of this |
798d3a52 ZJS |
112 | option see |
113 | <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para></listitem> | |
114 | </varlistentry> | |
115 | ||
116 | <varlistentry> | |
117 | <term><option>--booted</option></term> | |
118 | ||
119 | <listitem><para>Returns 0 if the system was booted up with | |
120 | systemd, non-zero otherwise. If this option is passed, no | |
121 | message is sent. This option is hence unrelated to the other | |
122 | options. For details about the semantics of this option, see | |
94f099d8 | 123 | <citerefentry><refentrytitle>sd_booted</refentrytitle><manvolnum>3</manvolnum></citerefentry>. An |
a8eaaee7 | 124 | alternate way to check for this state is to call |
94f099d8 LP |
125 | <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry> |
126 | with the <command>is-system-running</command> command. It will | |
127 | return <literal>offline</literal> if the system was not booted | |
128 | with systemd. </para></listitem> | |
798d3a52 ZJS |
129 | </varlistentry> |
130 | ||
131 | <xi:include href="standard-options.xml" xpointer="help" /> | |
132 | <xi:include href="standard-options.xml" xpointer="version" /> | |
133 | </variablelist> | |
134 | ||
135 | </refsect1> | |
136 | ||
137 | <refsect1> | |
138 | <title>Exit status</title> | |
139 | ||
140 | <para>On success, 0 is returned, a non-zero failure code | |
141 | otherwise.</para> | |
142 | </refsect1> | |
143 | ||
144 | <refsect1> | |
145 | <title>Example</title> | |
146 | ||
147 | <example> | |
148 | <title>Start-up Notification and Status Updates</title> | |
149 | ||
150 | <para>A simple shell daemon that sends start-up notifications | |
151 | after having set up its communication channel. During runtime it | |
152 | sends further status updates to the init system:</para> | |
153 | ||
154 | <programlisting>#!/bin/bash | |
c61fbdfc LP |
155 | |
156 | mkfifo /tmp/waldo | |
1eecafb8 | 157 | systemd-notify --ready --status="Waiting for data…" |
c61fbdfc LP |
158 | |
159 | while : ; do | |
0521e286 LP |
160 | read a < /tmp/waldo |
161 | systemd-notify --status="Processing $a" | |
c61fbdfc | 162 | |
1eecafb8 | 163 | # Do something with $a … |
c61fbdfc | 164 | |
1eecafb8 | 165 | systemd-notify --status="Waiting for data…" |
c61fbdfc | 166 | done</programlisting> |
798d3a52 ZJS |
167 | </example> |
168 | </refsect1> | |
169 | ||
170 | <refsect1> | |
171 | <title>See Also</title> | |
172 | <para> | |
173 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
174 | <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
175 | <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>, | |
176 | <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
177 | <citerefentry><refentrytitle>sd_booted</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
178 | </para> | |
179 | </refsect1> | |
c5abba08 LP |
180 | |
181 | </refentry> |