1SYSTEMD-NOTIFY(1)               systemd-notify               SYSTEMD-NOTIFY(1)
2
3
4

NAME

6       systemd-notify - Notify service manager about start-up completion and
7       other daemon status changes
8

SYNOPSIS

10       systemd-notify [OPTIONS...] [VARIABLE=VALUE...]
11
12       systemd-notify --exec [OPTIONS...] [VARIABLE=VALUE...] ; [CMDLINE...]
13

DESCRIPTION

15       systemd-notify may be called by service scripts to notify the invoking
16       service manager about status changes. It can be used to send arbitrary
17       information, encoded in an environment-block-like list of strings. Most
18       importantly, it can be used for start-up completion notification.
19
20       This is mostly just a wrapper around sd_notify() and makes this
21       functionality available to shell scripts. For details see sd_notify(3).
22
23       The command line may carry a list of environment variables to send as
24       part of the status update.
25
26       Note that systemd will refuse reception of status updates from this
27       command unless NotifyAccess= is appropriately set for the service unit
28       this command is called from. See systemd.service(5) for details.
29
30       Note that sd_notify() notifications may be attributed to units
31       correctly only if either the sending process is still around at the
32       time the service manager processes the message, or if the sending
33       process is explicitly runtime-tracked by the service manager. The
34       latter is the case if the service manager originally forked off the
35       process, i.e. on all processes that match NotifyAccess=main or
36       NotifyAccess=exec. Conversely, if an auxiliary process of the unit
37       sends an sd_notify() message and immediately exits, the service manager
38       might not be able to properly attribute the message to the unit, and
39       thus will ignore it, even if NotifyAccess=all is set for it. To address
40       this systemd-notify will wait until the notification message has been
41       processed by the service manager. When --no-block is used, this
42       synchronization for reception of notifications is disabled, and hence
43       the aforementioned race may occur if the invoking process is not the
44       service manager or spawned by the service manager.
45
46       systemd-notify will first attempt to invoke sd_notify() pretending to
47       have the PID of the parent process of systemd-notify (i.e. the invoking
48       process). This will only succeed when invoked with sufficient
49       privileges. On failure, it will then fall back to invoking it under its
50       own PID. This behaviour is useful in order that when the tool is
51       invoked from a shell script the shell process — and not the
52       systemd-notify process — appears as sender of the message, which in
53       turn is helpful if the shell process is the main process of a service,
54       due to the limitations of NotifyAccess=all. Use the --pid= switch to
55       tweak this behaviour.
56

OPTIONS

58       The following options are understood:
59
60       --ready
61           Inform the invoking service manager about service start-up or
62           configuration reload completion. This is equivalent to
63           systemd-notify READY=1. For details about the semantics of this
64           option see sd_notify(3).
65
66       --reloading
67           Inform the invoking service manager about the beginning of a
68           configuration reload cycle. This is equivalent to systemd-notify
69           RELOADING=1 (but implicitly also sets a MONOTONIC_USEC= field as
70           required for Type=notify-reload services, see systemd.service(5)
71           for details). For details about the semantics of this option see
72           sd_notify(3).
73
74       --stopping
75           Inform the invoking service manager about the beginning of the
76           shutdown phase of the service. This is equivalent to systemd-notify
77           STOPPING=1. For details about the semantics of this option see
78           sd_notify(3).
79
80       --pid=
81           Inform the service manager about the main PID of the service. Takes
82           a PID as argument. If the argument is specified as "auto" or
83           omitted, the PID of the process that invoked systemd-notify is
84           used, except if that's the service manager. If the argument is
85           specified as "self", the PID of the systemd-notify command itself
86           is used, and if "parent" is specified the calling process' PID is
87           used — even if it is the service manager. The latter is equivalent
88           to systemd-notify MAINPID=$PID. For details about the semantics of
89           this option see sd_notify(3).
90
91           If this switch is used in an systemd-notify invocation from a
92           process that shall become the new main process of a service — and
93           which is not the process forked off by the service manager (or the
94           current main process) —, then it is essential to set
95           NotifyAccess=all in the service unit file, or otherwise the
96           notification will be ignored for security reasons. See
97           systemd.service(5) for details.
98
99       --uid=USER
100           Set the user ID to send the notification from. Takes a UNIX user
101           name or numeric UID. When specified the notification message will
102           be sent with the specified UID as sender, in place of the user the
103           command was invoked as. This option requires sufficient privileges
104           in order to be able manipulate the user identity of the process.
105
106       --status=
107           Send a free-form human readable status string for the daemon to the
108           service manager. This option takes the status string as argument.
109           This is equivalent to systemd-notify STATUS=.... For details about
110           the semantics of this option see sd_notify(3). This information is
111           shown in systemctl(1)'s status output, among other places.
112
113       --booted
114           Returns 0 if the system was booted up with systemd, non-zero
115           otherwise. If this option is passed, no message is sent. This
116           option is hence unrelated to the other options. For details about
117           the semantics of this option, see sd_booted(3). An alternate way to
118           check for this state is to call systemctl(1) with the
119           is-system-running command. It will return "offline" if the system
120           was not booted with systemd.
121
122       --no-block
123           Do not synchronously wait for the requested operation to finish.
124           Use of this option is only recommended when systemd-notify is
125           spawned by the service manager, or when the invoking process is
126           directly spawned by the service manager and has enough privileges
127           to allow systemd-notify to send the notification on its behalf.
128           Sending notifications with this option set is prone to race
129           conditions in all other cases.
130
131       --exec
132           If specified systemd-notify will execute another command line after
133           it completed its operation, replacing its own process. If used, the
134           list of assignments to include in the message sent must be followed
135           by a ";" character (as separate argument), followed by the command
136           line to execute. This permits "chaining" of commands, i.e. issuing
137           one operation, followed immediately by another, without changing
138           PIDs.
139
140           Note that many shells interpret ";" as their own separator for
141           command lines, hence when systemd-notify is invoked from a shell
142           the semicolon must usually be escaped as "\;".
143
144       --fd=
145           Send a file descriptor along with the notification message. This is
146           useful when invoked in services that have the
147           FileDescriptorStoreMax= setting enabled, see systemd.service(5) for
148           details. The specified file descriptor must be passed to
149           systemd-notify when invoked. This option may be used multiple times
150           to pass multiple file descriptors in a single notification message.
151
152           To use this functionality from a bash shell, use an expression like
153           the following:
154
155               systemd-notify --fd=4 --fd=5 4</some/file 5</some/other/file
156
157       --fdname=
158           Set a name to assign to the file descriptors passed via --fd= (see
159           above). This controls the "FDNAME=" field. This setting may only be
160           specified once, and applies to all file descriptors passed. Invoke
161           this tool multiple times in case multiple file descriptors with
162           different file descriptor names shall be submitted.
163
164       -h, --help
165           Print a short help text and exit.
166
167       --version
168           Print a short version string and exit.
169

EXIT STATUS

171       On success, 0 is returned, a non-zero failure code otherwise.
172

EXAMPLE

174       Example 1. Start-up Notification and Status Updates
175
176       A simple shell daemon that sends start-up notifications after having
177       set up its communication channel. During runtime it sends further
178       status updates to the init system:
179
180           #!/bin/sh
181
182           mkfifo /tmp/waldo
183           systemd-notify --ready --status="Waiting for data..."
184
185           while : ; do
186                   read -r a < /tmp/waldo
187                   systemd-notify --status="Processing $a"
188
189                   # Do something with $a ...
190
191                   systemd-notify --status="Waiting for data..."
192           done
193

SEE ALSO

195       systemd(1), systemctl(1), systemd.unit(5), systemd.service(5),
196       sd_notify(3), sd_booted(3)
197
198
199
200systemd 254                                                  SYSTEMD-NOTIFY(1)
Impressum