Debian Codegraph @

man/systemd.service.xml

raw
1 <?xml version='1.0'?>
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
5
6 <refentry id="systemd.service" xmlns:xi="http://www.w3.org/2001/XInclude">
7 <refentryinfo>
8 <title>systemd.service</title>
9 <productname>systemd</productname>
10 </refentryinfo>
11
12 <refmeta>
13 <refentrytitle>systemd.service</refentrytitle>
14 <manvolnum>5</manvolnum>
15 </refmeta>
16
17 <refnamediv>
18 <refname>systemd.service</refname>
19 <refpurpose>Service unit configuration</refpurpose>
20 </refnamediv>
21
22 <refsynopsisdiv>
23 <para><filename><replaceable>service</replaceable>.service</filename></para>
24 </refsynopsisdiv>
25
26 <refsect1>
27 <title>Description</title>
28
29 <para>A unit configuration file whose name ends in
30 <literal>.service</literal> encodes information about a process
31 controlled and supervised by systemd.</para>
32
33 <para>This man page lists the configuration options specific to
34 this unit type. See
35 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
36 for the common options of all unit configuration files. The common
37 configuration items are configured in the generic
38 [Unit] and [Install]
39 sections. The service specific configuration options are
40 configured in the [Service] section.</para>
41
42 <para>Additional options are listed in
43 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
44 which define the execution environment the commands are executed
45 in, and in
46 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
47 which define the way the processes of the service are terminated,
48 and in
49 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
50 which configure resource control settings for the processes of the
51 service.</para>
52
53 <para>The <citerefentry><refentrytitle>systemd-run</refentrytitle><manvolnum>1</manvolnum></citerefentry>
54 command allows creating <filename>.service</filename> and <filename>.scope</filename> units dynamically
55 and transiently from the command line.</para>
56 </refsect1>
57
58 <refsect1>
59 <title>Service Templates</title>
60
61 <para>It is possible for <command>systemd</command> services to take a single argument via the
62 <literal><replaceable>service</replaceable>@<replaceable>argument</replaceable>.service</literal>
63 syntax. Such services are called "instantiated" services, while the unit definition without the
64 <replaceable>argument</replaceable> parameter is called a "template". An example could be a
65 <filename>[email protected]</filename> service template which takes a network interface as a
66 parameter to form an instantiated service. Within the service file, this parameter or "instance
67 name" can be accessed with %-specifiers. See
68 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
69 for details.</para>
70 </refsect1>
71
72 <refsect1>
73 <title>Automatic Dependencies</title>
74
75 <refsect2>
76 <title>Implicit Dependencies</title>
77
78 <para>The following dependencies are implicitly added:</para>
79
80 <itemizedlist>
81 <listitem><para>Services with <varname>Type=dbus</varname> set automatically
82 acquire dependencies of type <varname>Requires=</varname> and
83 <varname>After=</varname> on
84 <filename>dbus.socket</filename>.</para></listitem>
85
86 <listitem><para>Socket activated services are automatically ordered after
87 their activating <filename>.socket</filename> units via an
88 automatic <varname>After=</varname> dependency.
89 Services also pull in all <filename>.socket</filename> units
90 listed in <varname>Sockets=</varname> via automatic
91 <varname>Wants=</varname> and <varname>After=</varname> dependencies.</para></listitem>
92 </itemizedlist>
93
94 <para>Additional implicit dependencies may be added as result of
95 execution and resource control parameters as documented in
96 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
97 and
98 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
99 </refsect2>
100
101 <refsect2>
102 <title>Default Dependencies</title>
103
104 <para>The following dependencies are added unless <varname>DefaultDependencies=no</varname> is set:</para>
105
106 <itemizedlist>
107 <listitem><para>Service units will have dependencies of type <varname>Requires=</varname> and
108 <varname>After=</varname> on <filename>sysinit.target</filename>, a dependency of type <varname>After=</varname> on
109 <filename>basic.target</filename> as well as dependencies of type <varname>Conflicts=</varname> and
110 <varname>Before=</varname> on <filename>shutdown.target</filename>. These ensure that normal service units pull in
111 basic system initialization, and are terminated cleanly prior to system shutdown. Only services involved with early
112 boot or late system shutdown should disable this option.</para></listitem>
113
114 <listitem><para>Instanced service units (i.e. service units with an <literal>@</literal> in their name) are assigned by
115 default a per-template slice unit (see
116 <citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry>), named after the
117 template unit, containing all instances of the specific template. This slice is normally stopped at shutdown,
118 together with all template instances. If that is not desired, set <varname>DefaultDependencies=no</varname> in the
119 template unit, and either define your own per-template slice unit file that also sets
120 <varname>DefaultDependencies=no</varname>, or set <varname>Slice=system.slice</varname> (or another suitable slice)
121 in the template unit. Also see
122 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
123 </para></listitem>
124 </itemizedlist>
125 </refsect2>
126 </refsect1>
127
128 <refsect1>
129 <title>Options</title>
130
131 <para>Service unit files may include [Unit] and [Install] sections, which are described in
132 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
133 </para>
134
135 <para>Service unit files must include a [Service]
136 section, which carries information about the service and the
137 process it supervises. A number of options that may be used in
138 this section are shared with other unit types. These options are
139 documented in
140 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
141 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>
142 and
143 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
144 The options specific to the [Service] section
145 of service units are the following:</para>
146
147 <variablelist class='unit-directives'>
148 <varlistentry>
149 <term><varname>Type=</varname></term>
150
151 <listitem>
152 <para>Configures the mechanism via which the service notifies the manager that the service start-up
153 has finished. One of <option>simple</option>, <option>exec</option>, <option>forking</option>,
154 <option>oneshot</option>, <option>dbus</option>, <option>notify</option>,
155 <option>notify-reload</option>, or <option>idle</option>:</para>
156
157 <itemizedlist>
158 <listitem><para>If set to <option>simple</option> (the default if <varname>ExecStart=</varname>
159 is specified but neither <varname>Type=</varname> nor <varname>BusName=</varname> are, and
160 credentials are not used), the service manager will consider the unit started immediately after
161 the main service process has been forked off (i.e. immediately after <function>fork()</function>,
162 and before various process attributes have been configured and in particular before the new process
163 has called <function>execve()</function> to invoke the actual service binary). Typically,
164 <varname>Type=</varname><option>exec</option> is the better choice, see below.</para>
165
166 <para>It is expected that the process configured with <varname>ExecStart=</varname> is the main
167 process of the service. In this mode, if the process offers functionality to other processes on
168 the system, its communication channels should be installed before the service is started up
169 (e.g. sockets set up by systemd, via socket activation), as the service manager will immediately
170 proceed starting follow-up units, right after creating the main service process, and before
171 executing the service's binary. Note that this means <command>systemctl start</command> command
172 lines for <option>simple</option> services will report success even if the service's binary
173 cannot be invoked successfully (for example because the selected <varname>User=</varname> does not
174 exist, or the service binary is missing).</para></listitem>
175
176 <listitem><para>The <option>exec</option> type is similar to <option>simple</option>, but the
177 service manager will consider the unit started immediately after the main service binary has been
178 executed. The service manager will delay starting of follow-up units until that point. (Or in
179 other words: <option>simple</option> proceeds with further jobs right after
180 <function>fork()</function> returns, while <option>exec</option> will not proceed before both
181 <function>fork()</function> and <function>execve()</function> in the service process succeeded.)
182 Note that this means <command>systemctl start</command> command lines for <option>exec</option>
183 services will report failure when the service's binary cannot be invoked successfully (for
184 example because the selected <varname>User=</varname> does not exist, or the service binary is
185 missing). This type is implied if credentials are used (refer to <varname>LoadCredential=</varname>
186 in <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
187 for details).</para></listitem>
188
189 <listitem><para>If set to <option>forking</option>, the manager will consider the unit started
190 immediately after the binary that forked off by the manager exits. <emphasis>The use of this type
191 is discouraged, use <option>notify</option>, <option>notify-reload</option>, or
192 <option>dbus</option> instead.</emphasis></para>
193
194 <para>It is expected that the process configured with <varname>ExecStart=</varname> will call
195 <function>fork()</function> as part of its start-up. The parent process is expected to exit when
196 start-up is complete and all communication channels are set up. The child continues to run as the
197 main service process, and the service manager will consider the unit started when the parent
198 process exits. This is the behavior of traditional UNIX services. If this setting is used, it is
199 recommended to also use the <varname>PIDFile=</varname> option, so that systemd can reliably
200 identify the main process of the service. The manager will proceed with starting follow-up units
201 after the parent process exits.</para></listitem>
202
203 <listitem><para>Behavior of <option>oneshot</option> is similar to <option>exec</option>;
204 however, the service manager will consider the unit up after the main process exits. It will then
205 start follow-up units. <varname>RemainAfterExit=</varname> is particularly useful for this type
206 of service. <varname>Type=</varname><option>oneshot</option> is the implied default if neither
207 <varname>Type=</varname> nor <varname>ExecStart=</varname> are specified. Note that if this
208 option is used without <varname>RemainAfterExit=</varname> the service will never enter
209 <literal>active</literal> unit state, but will directly transition from
210 <literal>activating</literal> to <literal>deactivating</literal> or <literal>dead</literal>,
211 since no process is configured that shall run continuously. In particular this means that after a
212 service of this type ran (and which has <varname>RemainAfterExit=</varname> not set) it will not
213 show up as started afterwards, but as dead.</para></listitem>
214
215 <listitem><para>Behavior of <option>dbus</option> is similar to <option>simple</option>; however,
216 units of this type must have the <varname>BusName=</varname> specified and the service manager
217 will consider the unit up when the specified bus name has been acquired. This type is the default
218 if <varname>BusName=</varname> is specified.</para>
219
220 <para>Service units with this option configured implicitly gain dependencies on the
221 <filename>dbus.socket</filename> unit. A service unit of this type is considered to be in the
222 activating state until the specified bus name is acquired. It is considered activated while the
223 bus name is taken. Once the bus name is released the service is considered being no longer
224 functional which has the effect that the service manager attempts to terminate any remaining
225 processes belonging to the service. Services that drop their bus name as part of their shutdown
226 logic thus should be prepared to receive a <constant>SIGTERM</constant> (or whichever signal is
227 configured in <varname>KillSignal=</varname>) as result.</para></listitem>
228
229 <listitem><para>Behavior of <option>notify</option> is similar to <option>exec</option>; however,
230 it is expected that the service sends a <literal>READY=1</literal> notification message via
231 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry> or
232 an equivalent call when it has finished starting up. systemd will proceed with starting follow-up
233 units after this notification message has been sent. If this option is used,
234 <varname>NotifyAccess=</varname> (see below) should be set to open access to the notification
235 socket provided by systemd. If <varname>NotifyAccess=</varname> is missing or set to
236 <option>none</option>, it will be forcibly set to <option>main</option>.</para>
237
238 <para>If the service supports reloading, and uses a signal to start the reload, using
239 <option>notify-reload</option> instead is recommended.</para></listitem>
240
241 <listitem><para>Behavior of <option>notify-reload</option> is similar to <option>notify</option>,
242 with one difference: the <constant>SIGHUP</constant> UNIX process signal is sent to the service's
243 main process when the service is asked to reload and the manager will wait for a notification
244 about the reload being finished.</para>
245
246 <para>When initiating the reload process the service is expected to reply with a notification
247 message via
248 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>
249 that contains the <literal>RELOADING=1</literal> field in combination with
250 <literal>MONOTONIC_USEC=</literal> set to the current monotonic time
251 (i.e. <constant>CLOCK_MONOTONIC</constant> in
252 <citerefentry><refentrytitle>clock_gettime</refentrytitle><manvolnum>2</manvolnum></citerefentry>)
253 in μs, formatted as decimal string. Once reloading is complete another notification message must
254 be sent, containing <literal>READY=1</literal>. Using this service type and implementing this
255 reload protocol is an efficient alternative to providing an <varname>ExecReload=</varname>
256 command for reloading of the service's configuration.</para>
257
258 <para>The signal to send can be tweaked via <varname>ReloadSignal=</varname>, see below.</para>
259 </listitem>
260
261 <listitem><para>Behavior of <option>idle</option> is very similar to <option>simple</option>; however,
262 actual execution of the service program is delayed until all active jobs are dispatched. This may be used
263 to avoid interleaving of output of shell services with the status output on the console. Note that this
264 type is useful only to improve console output, it is not useful as a general unit ordering tool, and the
265 effect of this service type is subject to a 5s timeout, after which the service program is invoked
266 anyway.</para></listitem>
267 </itemizedlist>
268
269 <para>It is recommended to use <varname>Type=</varname><option>exec</option> for long-running
270 services, as it ensures that process setup errors (e.g. errors such as a missing service
271 executable, or missing user) are properly tracked. However, as this service type will not propagate
272 the failures in the service's own startup code (as opposed to failures in the preparatory steps the
273 service manager executes before <function>execve()</function>) and does not allow ordering of other
274 units against completion of initialization of the service code itself (which for example is useful
275 if clients need to connect to the service through some form of IPC, and the IPC channel is only
276 established by the service itself — in contrast to doing this ahead of time through socket or bus
277 activation or similar), it might not be sufficient for many cases. If so, <option>notify</option>,
278 <option>notify-reload</option>, or <option>dbus</option> (the latter only in case the service
279 provides a D-Bus interface) are the preferred options as they allow service program code to
280 precisely schedule when to consider the service started up successfully and when to proceed with
281 follow-up units. The <option>notify</option>/<option>notify-reload</option> service types require
282 explicit support in the service codebase (as <function>sd_notify()</function> or an equivalent API
283 needs to be invoked by the service at the appropriate time) — if it is not supported, then
284 <option>forking</option> is an alternative: it supports the traditional heavy-weight UNIX service
285 start-up protocol. Note that using any type other than <option>simple</option> possibly delays the
286 boot process, as the service manager needs to wait for at least some service initialization to
287 complete. (Also note it is generally not recommended to use <option>idle</option> or
288 <option>oneshot</option> for long-running services.)</para>
289
290 <para>Note that various service settings (e.g. <varname>User=</varname>, <varname>Group=</varname>
291 through libc NSS) might result in "hidden" blocking IPC calls to other services when
292 used. Sometimes it might be advisable to use the <option>simple</option> service type to ensure
293 that the service manager's transaction logic is not affected by such potentially slow operations
294 and hidden dependencies, as this is the only service type where the service manager will not wait
295 for such service execution setup operations to complete before proceeding.</para></listitem>
296 </varlistentry>
297
298 <varlistentry>
299 <term><varname>ExitType=</varname></term>
300
301 <listitem>
302 <para>Specifies when the manager should consider the service to be finished. One of <option>main</option> or
303 <option>cgroup</option>:</para>
304
305 <itemizedlist>
306 <listitem><para>If set to <option>main</option> (the default), the service manager
307 will consider the unit stopped when the main process, which is determined according to the
308 <varname>Type=</varname>, exits. Consequently, it cannot be used with
309 <varname>Type=</varname><option>oneshot</option>.</para></listitem>
310
311 <listitem><para>If set to <option>cgroup</option>, the service will be considered running as long as at
312 least one process in the cgroup has not exited.</para></listitem>
313 </itemizedlist>
314
315 <para>It is generally recommended to use <varname>ExitType=</varname><option>main</option> when a service has
316 a known forking model and a main process can reliably be determined. <varname>ExitType=</varname>
317 <option>cgroup</option> is meant for applications whose forking model is not known ahead of time and which
318 might not have a specific main process. It is well suited for transient or automatically generated services,
319 such as graphical applications inside of a desktop environment.</para>
320
321 <xi:include href="version-info.xml" xpointer="v250"/>
322 </listitem>
323 </varlistentry>
324
325 <varlistentry>
326 <term><varname>RemainAfterExit=</varname></term>
327
328 <listitem><para>Takes a boolean value that specifies whether
329 the service shall be considered active even when all its
330 processes exited. Defaults to <option>no</option>.</para>
331 </listitem>
332 </varlistentry>
333
334 <varlistentry>
335 <term><varname>GuessMainPID=</varname></term>
336
337 <listitem><para>Takes a boolean value that specifies whether
338 systemd should try to guess the main PID of a service if it
339 cannot be determined reliably. This option is ignored unless
340 <option>Type=forking</option> is set and
341 <option>PIDFile=</option> is unset because for the other types
342 or with an explicitly configured PID file, the main PID is
343 always known. The guessing algorithm might come to incorrect
344 conclusions if a daemon consists of more than one process. If
345 the main PID cannot be determined, failure detection and
346 automatic restarting of a service will not work reliably.
347 Defaults to <option>yes</option>.</para>
348 </listitem>
349 </varlistentry>
350
351 <varlistentry>
352 <term><varname>PIDFile=</varname></term>
353
354 <listitem><para>Takes a path referring to the PID file of the service. Usage of this option is
355 recommended for services where <varname>Type=</varname> is set to <option>forking</option>. The path
356 specified typically points to a file below <filename>/run/</filename>. If a relative path is
357 specified for system service, then it is hence prefixed with <filename>/run/</filename>, and prefixed
358 with <filename>$XDG_RUNTIME_DIR</filename> if specified in a user service. The service manager will
359 read the PID of the main process of the service from this file after start-up of the service. The
360 service manager will not write to the file configured here, although it will remove the file after
361 the service has shut down if it still exists. The PID file does not need to be owned by a privileged
362 user, but if it is owned by an unprivileged user additional safety restrictions are enforced: the
363 file may not be a symlink to a file owned by a different user (neither directly nor indirectly), and
364 the PID file must refer to a process already belonging to the service.</para>
365
366 <para>Note that PID files should be avoided in modern projects. Use <option>Type=notify</option>,
367 <option>Type=notify-reload</option> or <option>Type=simple</option> where possible, which does not
368 require use of PID files to determine the main process of a service and avoids needless
369 forking.</para></listitem>
370 </varlistentry>
371
372 <varlistentry>
373 <term><varname>BusName=</varname></term>
374
375 <listitem><para>Takes a D-Bus destination name that this service shall use. This option is mandatory
376 for services where <varname>Type=</varname> is set to <option>dbus</option>. It is recommended to
377 always set this property if known to make it easy to map the service name to the D-Bus destination.
378 In particular, <command>systemctl service-log-level/service-log-target</command> verbs make use of
379 this.</para>
380 </listitem>
381 </varlistentry>
382
383 <varlistentry>
384 <term><varname>ExecStart=</varname></term>
385 <listitem><para>Commands that are executed when this service is started.</para>
386
387 <para>Unless <varname>Type=</varname> is <option>oneshot</option>, exactly one command must be
388 given. When <varname>Type=oneshot</varname> is used, this setting may be used multiple times to
389 define multiple commands to execute. If the empty string is assigned to this option, the list of
390 commands to start is reset, prior assignments of this option will have no effect. If no
391 <varname>ExecStart=</varname> is specified, then the service must have
392 <varname>RemainAfterExit=yes</varname> and at least one <varname>ExecStop=</varname> line
393 set. (Services lacking both <varname>ExecStart=</varname> and <varname>ExecStop=</varname> are not
394 valid.)</para>
395
396 <para>If more than one command is configured, the commands are invoked sequentially in the order they
397 appear in the unit file. If one of the commands fails (and is not prefixed with
398 <literal>-</literal>), other lines are not executed, and the unit is considered failed.</para>
399
400 <para>Unless <varname>Type=forking</varname> is set, the process started via this command line will
401 be considered the main process of the daemon.</para>
402 </listitem>
403 </varlistentry>
404
405 <varlistentry>
406 <term><varname>ExecStartPre=</varname></term>
407 <term><varname>ExecStartPost=</varname></term>
408
409 <listitem><para>Additional commands that are executed before or after the command in
410 <varname>ExecStart=</varname>, respectively. Syntax is the same as for <varname>ExecStart=</varname>.
411 Multiple command lines are allowed, regardless of the service type (i.e. <varname>Type=</varname>),
412 and the commands are executed one after the other, serially.</para>
413
414 <para>If any of those commands (not prefixed with
415 <literal>-</literal>) fail, the rest are not executed and the
416 unit is considered failed.</para>
417
418 <para><varname>ExecStart=</varname> commands are only run after
419 all <varname>ExecStartPre=</varname> commands that were not prefixed
420 with a <literal>-</literal> exit successfully.</para>
421
422 <para><varname>ExecStartPost=</varname> commands are only run after the commands specified in
423 <varname>ExecStart=</varname> have been invoked successfully, as determined by
424 <varname>Type=</varname> (i.e. the process has been started for <varname>Type=simple</varname> or
425 <varname>Type=idle</varname>, the last <varname>ExecStart=</varname> process exited successfully for
426 <varname>Type=oneshot</varname>, the initial process exited successfully for
427 <varname>Type=forking</varname>, <literal>READY=1</literal> is sent for
428 <varname>Type=notify</varname>/<varname>Type=notify-reload</varname>, or the
429 <varname>BusName=</varname> has been taken for <varname>Type=dbus</varname>).</para>
430
431 <para>Note that <varname>ExecStartPre=</varname> may not be
432 used to start long-running processes. All processes forked
433 off by processes invoked via <varname>ExecStartPre=</varname> will
434 be killed before the next service process is run.</para>
435
436 <para>Note that if any of the commands specified in <varname>ExecStartPre=</varname>,
437 <varname>ExecStart=</varname>, or <varname>ExecStartPost=</varname> fail (and are not prefixed with
438 <literal>-</literal>, see above) or time out before the service is fully up, execution continues with commands
439 specified in <varname>ExecStopPost=</varname>, the commands in <varname>ExecStop=</varname> are skipped.</para>
440
441 <para>Note that the execution of <varname>ExecStartPost=</varname> is taken into account for the purpose of
442 <varname>Before=</varname>/<varname>After=</varname> ordering constraints.</para>
443 </listitem>
444 </varlistentry>
445
446 <varlistentry>
447 <term><varname>ExecCondition=</varname></term>
448 <listitem><para>Optional commands that are executed before the commands in
449 <varname>ExecStartPre=</varname>. Syntax is the same as for <varname>ExecStart=</varname>. Multiple
450 command lines are allowed, regardless of the service type (i.e. <varname>Type=</varname>), and the
451 commands are executed one after the other, serially.</para>
452
453 <para>The behavior is like an <varname>ExecStartPre=</varname> and condition check hybrid: when an
454 <varname>ExecCondition=</varname> command exits with exit code 1 through 254 (inclusive), the remaining
455 commands are skipped and the unit is <emphasis>not</emphasis> marked as failed. However, if an
456 <varname>ExecCondition=</varname> command exits with 255 or abnormally (e.g. timeout, killed by a
457 signal, etc.), the unit will be considered failed (and remaining commands will be skipped). Exit code of 0 or
458 those matching <varname>SuccessExitStatus=</varname> will continue execution to the next commands.</para>
459
460 <para>Note that an <varname>ExecCondition=</varname> skip is <emphasis>not</emphasis> equivalent to a
461 unit-level <varname>Condition…=</varname> or <varname>Assert…=</varname> check failing. Because
462 <varname>ExecCondition=</varname> runs as part of the activation transition, a skip causes the unit to
463 transition from <constant>active</constant> to <constant>inactive</constant>, and consequently
464 <varname>SuccessAction=</varname> (see
465 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>) will be
466 honored. By contrast, <varname>Condition…=</varname> directives in the <literal>[Unit]</literal> section
467 prevent activation entirely and therefore do not trigger <varname>SuccessAction=</varname>.</para>
468
469 <para>The same recommendations about not running long-running processes in <varname>ExecStartPre=</varname>
470 also applies to <varname>ExecCondition=</varname>. <varname>ExecCondition=</varname> will also run the commands
471 in <varname>ExecStopPost=</varname>, as part of stopping the service, in the case of any non-zero or abnormal
472 exits, like the ones described above.</para>
473
474 <xi:include href="version-info.xml" xpointer="v243"/>
475 </listitem>
476 </varlistentry>
477
478 <varlistentry>
479 <term><varname>ExecReload=</varname></term>
480
481 <listitem><para>Commands to execute to trigger a configuration reload in the service. This setting
482 may take multiple command lines, following the same scheme as described for
483 <varname>ExecStart=</varname> above. Use of this setting is optional. Specifier and environment
484 variable substitution is supported here following the same scheme as for
485 <varname>ExecStart=</varname>.</para>
486
487 <para>One additional, special environment variable is set: if known, <varname>$MAINPID</varname> is
488 set to the main process of the daemon, and may be used for command lines like the following:</para>
489
490 <programlisting>ExecReload=kill -HUP $MAINPID</programlisting>
491
492 <para>Note however that reloading a daemon by enqueuing a signal without completion notification
493 (as is the case with the example line above) is usually not a good choice, because this is an
494 asynchronous operation and hence not suitable when ordering reloads of multiple services against
495 each other. It is thus strongly recommended to either use <varname>Type=notify-reload</varname>,
496 or to set <varname>ExecReload=</varname> to a command that not only triggers a configuration reload
497 of the daemon, but also synchronously waits for it to complete. For example, <citerefentry
498 project='mankier'><refentrytitle>dbus-broker</refentrytitle><manvolnum>1</manvolnum></citerefentry>
499 uses the following:</para>
500
501 <programlisting>ExecReload=busctl call org.freedesktop.DBus \
502 /org/freedesktop/DBus org.freedesktop.DBus \
503 ReloadConfig
504 </programlisting>
505
506 <para>This setting can be combined with <varname>Type=notify-reload</varname>, in which case
507 the service main process is signaled after all specified command lines finish execution. Specially,
508 if <literal>RELOADING=1</literal> notification is received before <varname>ExecReload=</varname>
509 completes, the signaling is skipped and the service manager immediately starts listening for
510 <literal>READY=1</literal>.</para>
511 </listitem>
512 </varlistentry>
513
514 <varlistentry>
515 <term><varname>ExecReloadPost=</varname></term>
516
517 <listitem><para>Commands to execute after a successful reload operation. Syntax for this setting
518 is exactly the same as <varname>ExecReload=</varname>.</para>
519
520 <xi:include href="version-info.xml" xpointer="v259"/>
521 </listitem>
522 </varlistentry>
523
524 <varlistentry>
525 <term><varname>ExecStop=</varname></term>
526 <listitem><para>Commands to execute to stop the service started via
527 <varname>ExecStart=</varname>. This argument takes multiple command lines, following the same scheme
528 as described for <varname>ExecStart=</varname> above. Use of this setting is optional. After the
529 commands configured in this option are run, it is implied that the service is stopped, and any
530 processes remaining for it are terminated according to the <varname>KillMode=</varname> setting (see
531 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
532 If this option is not specified, the process is terminated by sending the signal specified in
533 <varname>KillSignal=</varname> or <varname>RestartKillSignal=</varname> when service stop is
534 requested. Specifier and environment variable substitution is supported (including
535 <varname>$MAINPID</varname>, see above).</para>
536
537 <para>Note that it is usually not sufficient to specify a command for this setting that only asks the
538 service to terminate (for example, by sending some form of termination signal to it), but does not
539 wait for it to do so. Since the remaining processes of the services are killed according to
540 <varname>KillMode=</varname> and <varname>KillSignal=</varname> or
541 <varname>RestartKillSignal=</varname> as described above immediately after the command exited, this
542 may not result in a clean stop. The specified command should hence be a synchronous operation, not an
543 asynchronous one.</para>
544
545 <para>Note that the commands specified in <varname>ExecStop=</varname> are only executed when the service
546 started successfully first. They are not invoked if the service was never started at all, or in case its
547 start-up failed, for example because any of the commands specified in <varname>ExecStart=</varname>,
548 <varname>ExecStartPre=</varname> or <varname>ExecStartPost=</varname> failed (and were not prefixed with
549 <literal>-</literal>, see above) or timed out. Use <varname>ExecStopPost=</varname> to invoke commands when a
550 service failed to start up correctly and is shut down again. Also note that the stop operation is always
551 performed if the service started successfully, even if the processes in the service terminated on their
552 own or were killed. The stop commands must be prepared to deal with that case. <varname>$MAINPID</varname>
553 will be unset if systemd knows that the main process exited by the time the stop commands are called.</para>
554
555 <para>Service restart requests are implemented as stop operations followed by start operations. This
556 means that <varname>ExecStop=</varname> and <varname>ExecStopPost=</varname> are executed during a
557 service restart operation.</para>
558
559 <para>It is recommended to use this setting for commands that communicate with the service requesting
560 clean termination. For post-mortem clean-up steps use <varname>ExecStopPost=</varname> instead.
561 </para></listitem>
562 </varlistentry>
563
564 <varlistentry>
565 <term><varname>ExecStopPost=</varname></term>
566 <listitem><para>Additional commands that are executed after the service is stopped. This includes cases where
567 the commands configured in <varname>ExecStop=</varname> were used, where the service does not have any
568 <varname>ExecStop=</varname> defined, or where the service exited unexpectedly. This argument takes multiple
569 command lines, following the same scheme as described for <varname>ExecStart=</varname>. Use of these settings
570 is optional. Specifier and environment variable substitution is supported. Note that – unlike
571 <varname>ExecStop=</varname> – commands specified with this setting are invoked when a service failed to start
572 up correctly and is shut down again.</para>
573
574 <para>It is recommended to use this setting for clean-up operations that shall be executed even when
575 the service failed to start up correctly. Commands configured with this setting need to be able to
576 operate even if the service failed starting up half-way and left incompletely initialized data
577 around. As the service's processes have likely exited already when the commands specified with this
578 setting are executed they should not attempt to communicate with them.</para>
579
580 <para>Note that all commands that are configured with this setting are invoked with the result code of the
581 service, as well as the main process' exit code and status, set in the <varname>$SERVICE_RESULT</varname>,
582 <varname>$EXIT_CODE</varname> and <varname>$EXIT_STATUS</varname> environment variables, see
583 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
584 details.</para>
585
586 <para>Note that the execution of <varname>ExecStopPost=</varname> is taken into account for the purpose of
587 <varname>Before=</varname>/<varname>After=</varname> ordering constraints.</para></listitem>
588 </varlistentry>
589
590 <varlistentry>
591 <term><varname>RestartSec=</varname></term>
592 <listitem><para>Configures the time to sleep before restarting
593 a service (as configured with <varname>Restart=</varname>).
594 Takes a unit-less value in seconds, or a time span value such
595 as "5min 20s". Defaults to 100ms.</para></listitem>
596 </varlistentry>
597
598 <varlistentry>
599 <term><varname>RestartSteps=</varname></term>
600 <listitem><para>Configures the number of exponential steps to take to increase the interval
601 of auto-restarts from <varname>RestartSec=</varname> to <varname>RestartMaxDelaySec=</varname>.
602 Takes a positive integer or 0 to disable it. Defaults to 0. <emphasis>Hint:</emphasis> values
603 between 3 and 5 are good choices when exponential backoff is desired.</para>
604
605 <para>Example:</para>
606
607 <programlisting>RestartSec=10s
608 RestartSteps=4
609 RestartMaxDelaySec=160s</programlisting>
610
611 <para>This will produce the following restart intervals: 10s, 20s, 40s, 80s, 160s, 160s, 160s, etc.
612 Notice the geometric interpolation and the resulting constant ratio between intervals; here it is 2.
613 The formula for the <emphasis>ratio</emphasis> is
614 <inlineequation>
615 <mathphrase>
616 (<varname>RestartMaxDelaySec</varname> / <varname>RestartSec</varname>)^(1 / <varname>RestartSteps</varname>)
617 </mathphrase>
618 </inlineequation>. A (repeating) delay equal to <varname>RestartMaxDelaySec=</varname> is always
619 reached after
620 <inlineequation>
621 <mathphrase>
622 <varname>RestartSteps</varname> + 1
623 </mathphrase>
624 </inlineequation> steps.</para>
625
626 <para>This setting is effective only if <varname>RestartMaxDelaySec=</varname> is also set and
627 <varname>RestartSec=</varname> is not zero.</para>
628
629 <xi:include href="version-info.xml" xpointer="v254"/></listitem>
630 </varlistentry>
631
632 <varlistentry>
633 <term><varname>RestartMaxDelaySec=</varname></term>
634 <listitem><para>Configures the longest time to sleep before restarting a service
635 as the interval goes up with <varname>RestartSteps=</varname>. Takes a value
636 in the same format as <varname>RestartSec=</varname>, or <literal>infinity</literal>
637 to disable the setting. Defaults to <literal>infinity</literal>.</para>
638
639 <para>This setting is effective only if <varname>RestartSteps=</varname> is also set and
640 <varname>RestartSec=</varname> is not zero.</para>
641
642 <xi:include href="version-info.xml" xpointer="v254"/></listitem>
643 </varlistentry>
644
645 <varlistentry>
646 <term><varname>TimeoutStartSec=</varname></term>
647 <listitem><para>Configures the time to wait for start-up. If a daemon service does not signal
648 start-up completion within the configured time, the service will be considered failed and will be
649 shut down again. The precise action depends on the <varname>TimeoutStartFailureMode=</varname>
650 option. Takes a unit-less value in seconds, or a time span value such as "5min 20s". Pass
651 <literal>infinity</literal> to disable the timeout logic. Defaults to
652 <varname>DefaultTimeoutStartSec=</varname> set in the manager, except when
653 <varname>Type=oneshot</varname> is used, in which case the timeout is disabled by default (see
654 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
655 </para>
656
657 <para>If a service of <varname>Type=notify</varname>/<varname>Type=notify-reload</varname> sends
658 <literal>EXTEND_TIMEOUT_USEC=…</literal>, this may cause the start time to be extended beyond
659 <varname>TimeoutStartSec=</varname>. The first receipt of this message must occur before
660 <varname>TimeoutStartSec=</varname> is exceeded, and once the start time has extended beyond
661 <varname>TimeoutStartSec=</varname>, the service manager will allow the service to continue to start,
662 provided the service repeats <literal>EXTEND_TIMEOUT_USEC=…</literal> within the interval specified
663 until the service startup status is finished by <literal>READY=1</literal>. (see
664 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>).
665 </para>
666
667 <para>Note that the start timeout is also applied to service reloads, regardless of whether implemented
668 through <varname>ExecReload=</varname> or via the reload logic enabled via <varname>Type=notify-reload</varname>.
669 If the reload does not complete within the configured time, the reload will be considered failed and
670 the service will continue running with the old configuration. This will not affect the running service,
671 but will be logged and will cause e.g. <command>systemctl reload</command> to fail.</para>
672
673 <xi:include href="version-info.xml" xpointer="v188"/></listitem>
674 </varlistentry>
675
676 <varlistentry>
677 <term><varname>TimeoutStopSec=</varname></term>
678 <listitem><para>This option serves two purposes. First, it configures the time to wait for each
679 <varname>ExecStop=</varname> command. If any of them times out, subsequent <varname>ExecStop=</varname> commands
680 are skipped and the service will be terminated by <constant>SIGTERM</constant>. If no <varname>ExecStop=</varname>
681 commands are specified, the service gets the <constant>SIGTERM</constant> immediately. This default behavior
682 can be changed by the <varname>TimeoutStopFailureMode=</varname> option. Second, it configures the time
683 to wait for the service itself to stop. If it does not terminate in the specified time, it will be forcibly terminated
684 by <constant>SIGKILL</constant> (see <varname>KillMode=</varname> in
685 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
686 Takes a unit-less value in seconds, or a time span value such
687 as "5min 20s". Pass <literal>infinity</literal> to disable the
688 timeout logic. Defaults to
689 <varname>DefaultTimeoutStopSec=</varname> from the manager
690 configuration file (see
691 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
692 </para>
693
694 <para>If a service of <varname>Type=notify</varname>/<varname>Type=notify-reload</varname> sends
695 <literal>EXTEND_TIMEOUT_USEC=…</literal>, this may cause the stop time to be extended beyond
696 <varname>TimeoutStopSec=</varname>. The first receipt of this message must occur before
697 <varname>TimeoutStopSec=</varname> is exceeded, and once the stop time has extended beyond
698 <varname>TimeoutStopSec=</varname>, the service manager will allow the service to continue to stop,
699 provided the service repeats <literal>EXTEND_TIMEOUT_USEC=…</literal> within the interval specified,
700 or terminates itself (see
701 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>).
702 </para>
703
704 <xi:include href="version-info.xml" xpointer="v188"/></listitem>
705 </varlistentry>
706
707 <varlistentry>
708 <term><varname>TimeoutAbortSec=</varname></term>
709 <listitem><para>This option configures the time to wait for the service to terminate when it was aborted due to a
710 watchdog timeout (see <varname>WatchdogSec=</varname>). If the service has a short <varname>TimeoutStopSec=</varname>
711 this option can be used to give the system more time to write a core dump of the service. Upon expiration the service
712 will be forcibly terminated by <constant>SIGKILL</constant> (see <varname>KillMode=</varname> in
713 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>). The core file will
714 be truncated in this case. Use <varname>TimeoutAbortSec=</varname> to set a sensible timeout for the core dumping per
715 service that is large enough to write all expected data while also being short enough to handle the service failure
716 in due time.
717 </para>
718
719 <para>Takes a unit-less value in seconds, or a time span value such as "5min 20s". Pass an empty value to skip
720 the dedicated watchdog abort timeout handling and fall back <varname>TimeoutStopSec=</varname>. Pass
721 <literal>infinity</literal> to disable the timeout logic. Defaults to <varname>DefaultTimeoutAbortSec=</varname> from
722 the manager configuration file (see
723 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
724 </para>
725
726 <para>If a service of <varname>Type=notify</varname>/<varname>Type=notify-reload</varname> handles
727 <constant>SIGABRT</constant> itself (instead of relying on the kernel to write a core dump) it can
728 send <literal>EXTEND_TIMEOUT_USEC=…</literal> to extended the abort time beyond
729 <varname>TimeoutAbortSec=</varname>. The first receipt of this message must occur before
730 <varname>TimeoutAbortSec=</varname> is exceeded, and once the abort time has extended beyond
731 <varname>TimeoutAbortSec=</varname>, the service manager will allow the service to continue to abort,
732 provided the service repeats <literal>EXTEND_TIMEOUT_USEC=…</literal> within the interval specified,
733 or terminates itself (see
734 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>).
735 </para>
736
737 <xi:include href="version-info.xml" xpointer="v243"/></listitem>
738 </varlistentry>
739
740 <varlistentry>
741 <term><varname>TimeoutSec=</varname></term>
742 <listitem><para>A shorthand for configuring both
743 <varname>TimeoutStartSec=</varname> and
744 <varname>TimeoutStopSec=</varname> to the specified value.
745 </para></listitem>
746 </varlistentry>
747
748 <varlistentry>
749 <term><varname>TimeoutStartFailureMode=</varname></term>
750 <term><varname>TimeoutStopFailureMode=</varname></term>
751
752 <listitem><para>These options configure the action that is taken in case a daemon service does not signal
753 start-up within its configured <varname>TimeoutStartSec=</varname>, respectively if it does not stop within
754 <varname>TimeoutStopSec=</varname>. Takes one of <option>terminate</option>, <option>abort</option> and
755 <option>kill</option>. Both options default to <option>terminate</option>.</para>
756
757 <para>If <option>terminate</option> is set the service will be gracefully terminated by sending the signal
758 specified in <varname>KillSignal=</varname> (defaults to <constant>SIGTERM</constant>, see
759 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>). If the
760 service does not terminate the <varname>FinalKillSignal=</varname> is sent after
761 <varname>TimeoutStopSec=</varname>. If <option>abort</option> is set, <varname>WatchdogSignal=</varname> is sent
762 instead and <varname>TimeoutAbortSec=</varname> applies before sending <varname>FinalKillSignal=</varname>.
763 This setting may be used to analyze services that fail to start-up or shut-down intermittently.
764 By using <option>kill</option> the service is immediately terminated by sending
765 <varname>FinalKillSignal=</varname> without any further timeout. This setting can be used to expedite the
766 shutdown of failing services.
767 </para>
768
769 <xi:include href="version-info.xml" xpointer="v246"/></listitem>
770 </varlistentry>
771
772 <varlistentry>
773 <term><varname>RuntimeMaxSec=</varname></term>
774
775 <listitem><para>Configures a maximum time for the service to run. If this is used and the service has been
776 active for longer than the specified time it is terminated and put into a failure state. Note that this setting
777 does not have any effect on <varname>Type=oneshot</varname> services, as they terminate immediately after
778 activation completed (use <varname>TimeoutStartSec=</varname> to limit their activation).
779 Pass <literal>infinity</literal> (the default) to configure no runtime limit.</para>
780
781 <para>If a service of <varname>Type=notify</varname>/<varname>Type=notify-reload</varname> sends
782 <literal>EXTEND_TIMEOUT_USEC=…</literal>, this may cause the runtime to be extended beyond
783 <varname>RuntimeMaxSec=</varname>. The first receipt of this message must occur before
784 <varname>RuntimeMaxSec=</varname> is exceeded, and once the runtime has extended beyond
785 <varname>RuntimeMaxSec=</varname>, the service manager will allow the service to continue to run,
786 provided the service repeats <literal>EXTEND_TIMEOUT_USEC=…</literal> within the interval specified
787 until the service shutdown is achieved by <literal>STOPPING=1</literal> (or termination). (see
788 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>).
789 </para>
790
791 <xi:include href="version-info.xml" xpointer="v229"/></listitem>
792 </varlistentry>
793
794 <varlistentry>
795 <term><varname>RuntimeRandomizedExtraSec=</varname></term>
796
797 <listitem><para>This option modifies <varname>RuntimeMaxSec=</varname> by increasing the maximum runtime by an
798 evenly distributed duration between 0 and the specified value (in seconds). If <varname>RuntimeMaxSec=</varname> is
799 unspecified, then this feature will be disabled.
800 </para>
801
802 <xi:include href="version-info.xml" xpointer="v250"/></listitem>
803 </varlistentry>
804
805 <varlistentry>
806 <term><varname>WatchdogSec=</varname></term>
807 <listitem><para>Configures the watchdog timeout for a service.
808 The watchdog is activated when the start-up is completed. The
809 service must call
810 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>
811 regularly with <literal>WATCHDOG=1</literal> (i.e. the
812 "keep-alive ping"). If the time between two such calls is
813 larger than the configured time, then the service is placed in
814 a failed state and it will be terminated with
815 <constant>SIGABRT</constant> (or the signal specified by
816 <varname>WatchdogSignal=</varname>). By setting
817 <varname>Restart=</varname> to <option>on-failure</option>,
818 <option>on-watchdog</option>, <option>on-abnormal</option> or
819 <option>always</option>, the service will be automatically
820 restarted. The time configured here will be passed to the
821 executed service process in the
822 <varname>WATCHDOG_USEC=</varname> environment variable. This
823 allows daemons to automatically enable the keep-alive pinging
824 logic if watchdog support is enabled for the service. If this
825 option is used, <varname>NotifyAccess=</varname> (see below)
826 should be set to open access to the notification socket
827 provided by systemd. If <varname>NotifyAccess=</varname> is
828 not set, it will be implicitly set to <option>main</option>.
829 Defaults to 0, which disables this feature. The service can
830 check whether the service manager expects watchdog keep-alive
831 notifications. See
832 <citerefentry><refentrytitle>sd_watchdog_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>
833 for details.
834 <citerefentry><refentrytitle>sd_event_set_watchdog</refentrytitle><manvolnum>3</manvolnum></citerefentry>
835 may be used to enable automatic watchdog notification support.
836 </para></listitem>
837 </varlistentry>
838
839 <varlistentry>
840 <term><varname>Restart=</varname></term>
841 <listitem><para>Configures whether the service shall be restarted when the service process exits,
842 is killed, or a timeout is reached. The service process may be the main service process, but it may
843 also be one of the processes specified with <varname>ExecStartPre=</varname>,
844 <varname>ExecStartPost=</varname>, <varname>ExecStop=</varname>, <varname>ExecStopPost=</varname>,
845 or <varname>ExecReload=</varname>. When the death of the process is a result of systemd operation
846 (e.g. service stop or restart), the service will not be restarted. Timeouts include missing the watchdog
847 "keep-alive ping" deadline and a service start, reload, and stop operation timeouts.</para>
848
849 <para>Takes one of <option>no</option>, <option>on-success</option>, <option>on-failure</option>,
850 <option>on-abnormal</option>, <option>on-watchdog</option>, <option>on-abort</option>, or
851 <option>always</option>. If set to <option>no</option> (the default), the service will not be restarted.
852 If set to <option>on-success</option>, it will be restarted only when the service process exits cleanly.
853 In this context, a clean exit means any of the following:
854 <itemizedlist>
855 <listitem><simpara>exit code of 0;</simpara></listitem>
856 <listitem><simpara>for types other than <varname>Type=oneshot</varname>, one of the signals
857 <constant>SIGHUP</constant>, <constant>SIGINT</constant>,
858 <constant>SIGTERM</constant>, or <constant>SIGPIPE</constant>;
859 </simpara></listitem>
860 <listitem><simpara>exit statuses and signals specified in
861 <varname>SuccessExitStatus=</varname>.</simpara></listitem>
862 </itemizedlist>
863 If set to <option>on-failure</option>, the service will be restarted when the process exits with
864 a non-zero exit code, is terminated by a signal (including on core dump, but excluding the aforementioned
865 four signals), when an operation (such as service reload) times out, and when the configured watchdog
866 timeout is triggered. If set to <option>on-abnormal</option>, the service will be restarted when
867 the process is terminated by a signal (including on core dump, excluding the aforementioned four signals),
868 when an operation times out, or when the watchdog timeout is triggered. If set to <option>on-abort</option>,
869 the service will be restarted only if the service process exits due to an uncaught signal not specified
870 as a clean exit status. If set to <option>on-watchdog</option>, the service will be restarted
871 only if the watchdog timeout for the service expires. If set to <option>always</option>, the service
872 will be restarted regardless of whether it exited cleanly or not, got terminated abnormally by
873 a signal, or hit a timeout. Note that <varname>Type=oneshot</varname> services will never be restarted
874 on a clean exit status, i.e. <option>always</option> and <option>on-success</option> are rejected
875 for them.</para>
876
877 <table>
878 <title>Exit causes and the effect of the <varname>Restart=</varname> settings</title>
879
880 <tgroup cols='2'>
881 <colspec colname='path' />
882 <colspec colname='expl' />
883 <thead>
884 <row>
885 <entry>Restart settings/Exit causes</entry>
886 <entry><option>no</option></entry>
887 <entry><option>always</option></entry>
888 <entry><option>on-success</option></entry>
889 <entry><option>on-failure</option></entry>
890 <entry><option>on-abnormal</option></entry>
891 <entry><option>on-abort</option></entry>
892 <entry><option>on-watchdog</option></entry>
893 </row>
894 </thead>
895 <tbody>
896 <row>
897 <entry>Clean exit code or signal</entry>
898 <entry/>
899 <entry>X</entry>
900 <entry>X</entry>
901 <entry/>
902 <entry/>
903 <entry/>
904 <entry/>
905 </row>
906 <row>
907 <entry>Unclean exit code</entry>
908 <entry/>
909 <entry>X</entry>
910 <entry/>
911 <entry>X</entry>
912 <entry/>
913 <entry/>
914 <entry/>
915 </row>
916 <row>
917 <entry>Unclean signal</entry>
918 <entry/>
919 <entry>X</entry>
920 <entry/>
921 <entry>X</entry>
922 <entry>X</entry>
923 <entry>X</entry>
924 <entry/>
925 </row>
926 <row>
927 <entry>Timeout</entry>
928 <entry/>
929 <entry>X</entry>
930 <entry/>
931 <entry>X</entry>
932 <entry>X</entry>
933 <entry/>
934 <entry/>
935 </row>
936 <row>
937 <entry>Watchdog</entry>
938 <entry/>
939 <entry>X</entry>
940 <entry/>
941 <entry>X</entry>
942 <entry>X</entry>
943 <entry/>
944 <entry>X</entry>
945 </row>
946 <row>
947 <entry>Termination due to OOM</entry>
948 <entry/>
949 <entry>X</entry>
950 <entry/>
951 <entry>X</entry>
952 <entry>X</entry>
953 <entry/>
954 <entry/>
955 </row>
956 </tbody>
957 </tgroup>
958 </table>
959
960 <para>As exceptions to the setting above, the service will not
961 be restarted if the exit code or signal is specified in
962 <varname>RestartPreventExitStatus=</varname> (see below) or
963 the service is stopped with <command>systemctl stop</command>
964 or an equivalent operation. Also, the services will always be
965 restarted if the exit code or signal is specified in
966 <varname>RestartForceExitStatus=</varname> (see below).</para>
967
968 <para>Note that service restart is subject to unit start rate
969 limiting configured with <varname>StartLimitIntervalSec=</varname>
970 and <varname>StartLimitBurst=</varname>, see
971 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
972 for details.</para>
973
974 <para>Setting this to <option>on-failure</option> is the
975 recommended choice for long-running services, in order to
976 increase reliability by attempting automatic recovery from
977 errors. For services that shall be able to terminate on their
978 own choice (and avoid immediate restarting),
979 <option>on-abnormal</option> is an alternative choice.</para>
980 </listitem>
981 </varlistentry>
982
983 <varlistentry>
984 <term><varname>RestartMode=</varname></term>
985
986 <listitem>
987 <para>Takes a string value that specifies how a service should restart:
988 <itemizedlist>
989 <listitem>
990 <para>If set to <option>normal</option> (the default), the service restarts by going through
991 a failed/inactive state.</para>
992
993 <xi:include href="version-info.xml" xpointer="v254"/>
994 </listitem>
995
996 <listitem>
997 <para>If set to <option>direct</option>, the service transitions to the activating
998 state directly during auto-restart, skipping failed/inactive state.
999 <varname>ExecStopPost=</varname> is still invoked.
1000 <varname>OnSuccess=</varname> and <varname>OnFailure=</varname> are skipped.</para>
1001
1002 <para>This option is useful in cases where a dependency can fail temporarily but we do not
1003 want these temporary failures to make the dependent units fail. Dependent units are not
1004 notified of these temporary failures.</para>
1005
1006 <xi:include href="version-info.xml" xpointer="v254"/>
1007 </listitem>
1008
1009 <listitem>
1010 <para>If set to <option>debug</option>, the service manager will log messages that are
1011 related to this unit at debug level while automated restarts are attempted, until either the
1012 service hits the rate limit or it succeeds, and the <varname>$DEBUG_INVOCATION=1</varname>
1013 environment variable will be set for the unit. This is useful to be able to get additional
1014 information when a service fails to start, without needing to proactively or permanently
1015 enable debug level logging in systemd, which is very verbose. This is otherwise equivalent
1016 to <option>normal</option> mode.</para>
1017
1018 <xi:include href="version-info.xml" xpointer="v257"/>
1019 </listitem>
1020 </itemizedlist>
1021 </para>
1022
1023 <xi:include href="version-info.xml" xpointer="v254"/>
1024 </listitem>
1025 </varlistentry>
1026
1027 <varlistentry>
1028 <term><varname>SuccessExitStatus=</varname></term>
1029
1030 <listitem><para>Takes a list of exit status definitions that, when returned by the main service
1031 process, will be considered successful termination, in addition to the normal successful exit status
1032 0 and, except for <varname>Type=oneshot</varname>, the signals <constant>SIGHUP</constant>, <constant>SIGINT</constant>,
1033 <constant>SIGTERM</constant>, and <constant>SIGPIPE</constant>. Exit status definitions can be
1034 numeric termination statuses, termination status names, or termination signal names, separated by
1035 spaces. See the Process Exit Codes section in
1036 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
1037 a list of termination status names (for this setting only the part without the
1038 <literal>EXIT_</literal> or <literal>EX_</literal> prefix should be used). See <citerefentry
1039 project='man-pages'><refentrytitle>signal</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
1040 a list of signal names.</para>
1041
1042 <para>Note that this setting does not change the mapping between numeric exit statuses and their
1043 names, i.e. regardless how this setting is used 0 will still be mapped to <literal>SUCCESS</literal>
1044 (and thus typically shown as <literal>0/SUCCESS</literal> in tool outputs) and 1 to
1045 <literal>FAILURE</literal> (and thus typically shown as <literal>1/FAILURE</literal>), and so on. It
1046 only controls what happens as effect of these exit statuses, and how it propagates to the state of
1047 the service as a whole.</para>
1048
1049 <para>This option may appear more than once, in which case the list of successful exit statuses is
1050 merged. If the empty string is assigned to this option, the list is reset, all prior assignments of
1051 this option will have no effect.</para>
1052
1053 <example>
1054 <title>A service with the <varname>SuccessExitStatus=</varname> setting</title>
1055
1056 <programlisting>SuccessExitStatus=TEMPFAIL 250 SIGKILL</programlisting>
1057
1058 <para>Exit status 75 (<constant>TEMPFAIL</constant>), 250, and the termination signal
1059 <constant>SIGKILL</constant> are considered clean service terminations.</para>
1060 </example>
1061
1062 <para>Note: <command>systemd-analyze exit-status</command> may be used to list exit statuses and
1063 translate between numerical status values and names.</para>
1064
1065 <xi:include href="version-info.xml" xpointer="v189"/></listitem>
1066 </varlistentry>
1067
1068 <varlistentry>
1069 <term><varname>RestartPreventExitStatus=</varname></term>
1070
1071 <listitem><para>Takes a list of exit status definitions that, when returned by the main service
1072 process, will prevent automatic service restarts, regardless of the restart setting configured with
1073 <varname>Restart=</varname>. Exit status definitions can be numeric termination statuses, termination
1074 status names, or termination signal names, separated by spaces. Defaults to the empty list, so that,
1075 by default, no exit status is excluded from the configured restart logic.
1076
1077 <example>
1078 <title>A service with the <varname>RestartPreventExitStatus=</varname> setting</title>
1079
1080 <programlisting>RestartPreventExitStatus=TEMPFAIL 250 SIGKILL</programlisting>
1081
1082 <para>Exit status 75 (<constant>TEMPFAIL</constant>), 250, and the termination signal
1083 <constant>SIGKILL</constant> will not result in automatic service restarting.</para>
1084 </example>
1085
1086 This option may appear more than once, in which case the list of restart-preventing statuses is merged.
1087 If the empty string is assigned to this option, the list is reset and all prior assignments of this
1088 option will have no effect.</para>
1089
1090 <para>Note that this setting has no effect on processes configured via
1091 <varname>ExecStartPre=</varname>, <varname>ExecStartPost=</varname>, <varname>ExecStop=</varname>,
1092 <varname>ExecStopPost=</varname> or <varname>ExecReload=</varname>, but only on the main service
1093 process, i.e. either the one invoked by <varname>ExecStart=</varname> or (depending on
1094 <varname>Type=</varname>, <varname>PIDFile=</varname>, …) the otherwise configured main
1095 process.</para>
1096
1097 <xi:include href="version-info.xml" xpointer="v189"/></listitem>
1098 </varlistentry>
1099
1100 <varlistentry>
1101 <term><varname>RestartForceExitStatus=</varname></term>
1102
1103 <listitem><para>Takes a list of exit status definitions that, when returned by the main service
1104 process, will force automatic service restarts, regardless of the restart setting configured with
1105 <varname>Restart=</varname>. The argument format is similar to <varname>RestartPreventExitStatus=</varname>.
1106 </para>
1107
1108 <para>Note that for <varname>Type=oneshot</varname> services, a success exit status will prevent
1109 them from auto-restarting, no matter whether the corresponding exit statuses are listed in this
1110 option or not.</para>
1111
1112 <xi:include href="version-info.xml" xpointer="v215"/></listitem>
1113 </varlistentry>
1114
1115 <varlistentry>
1116 <term><varname>RootDirectoryStartOnly=</varname></term>
1117 <listitem><para>Takes a boolean argument. If true, the root directory, as configured with the
1118 <varname>RootDirectory=</varname> option (see
1119 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
1120 for more information), is only applied to the process started with <varname>ExecStart=</varname>,
1121 and not to the various other <varname>ExecStartPre=</varname>, <varname>ExecStartPost=</varname>,
1122 <varname>ExecReload=</varname>, <varname>ExecReloadPost=</varname>, <varname>ExecStop=</varname>,
1123 and <varname>ExecStopPost=</varname> commands. If false, the setting is applied to all
1124 configured commands the same way. Defaults to false.</para></listitem>
1125 </varlistentry>
1126
1127 <varlistentry>
1128 <term><varname>NonBlocking=</varname></term>
1129 <listitem><para>Set the <constant>O_NONBLOCK</constant> flag for all file descriptors passed via
1130 socket-based activation. If true, all file descriptors >= 3 (i.e. all except stdin, stdout, stderr),
1131 excluding those passed in via the file descriptor storage logic (see
1132 <varname>FileDescriptorStoreMax=</varname> for details), will have the
1133 <constant>O_NONBLOCK</constant> flag set and hence are in non-blocking mode. This option is only
1134 useful in conjunction with a socket unit, as described in
1135 <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>
1136 and has no effect on file descriptors which were previously saved in the file-descriptor store for
1137 example. Defaults to false.</para>
1138
1139 <para>Note that if the same socket unit is configured to be passed to multiple service units (via the
1140 <varname>Sockets=</varname> setting, see below), and these services have different
1141 <varname>NonBlocking=</varname> configurations, the precise state of <constant>O_NONBLOCK</constant>
1142 depends on the order in which these services are invoked, and will possibly change after service code
1143 already took possession of the socket file descriptor, simply because the
1144 <constant>O_NONBLOCK</constant> state of a socket is shared by all file descriptors referencing
1145 it. Hence it is essential that all services sharing the same socket use the same
1146 <varname>NonBlocking=</varname> configuration, and do not change the flag in service code
1147 either.</para></listitem>
1148 </varlistentry>
1149
1150 <varlistentry>
1151 <term><varname>NotifyAccess=</varname></term>
1152 <listitem><para>Controls access to the service status notification socket, as accessible via the
1153 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>
1154 call. Takes one of <option>none</option> (the default), <option>main</option>, <option>exec</option>
1155 or <option>all</option>. If <option>none</option>, no daemon status updates are accepted from the
1156 service processes, all status update messages are ignored. If <option>main</option>, only service
1157 updates sent from the main process of the service are accepted. If <option>exec</option>, only
1158 service updates sent from any of the main or control processes originating from one of the
1159 <varname>Exec*=</varname> commands are accepted. If <option>all</option>, all services updates from
1160 all members of the service's control group are accepted. This option should be set to open access to
1161 the notification socket when using
1162 <varname>Type=notify</varname>/<varname>Type=notify-reload</varname> or
1163 <varname>WatchdogSec=</varname> (see above). If those options are used but
1164 <varname>NotifyAccess=</varname> is not configured, it will be implicitly set to
1165 <option>main</option>.</para>
1166
1167 <para>Note that <function>sd_notify()</function> notifications may be attributed to units correctly only if
1168 either the sending process is still around at the time PID 1 processes the message, or if the sending process
1169 is explicitly runtime-tracked by the service manager. The latter is the case if the service manager originally
1170 forked off the process, i.e. on all processes that match <option>main</option> or
1171 <option>exec</option>. Conversely, if an auxiliary process of the unit sends an
1172 <function>sd_notify()</function> message and immediately exits, the service manager might not be able to
1173 properly attribute the message to the unit, and thus will ignore it, even if
1174 <varname>NotifyAccess=</varname><option>all</option> is set for it.</para>
1175
1176 <para>Hence, to eliminate all race conditions involving lookup of the client's unit and attribution of notifications
1177 to units correctly, <function>sd_notify_barrier()</function> may be used. This call acts as a synchronization point
1178 and ensures all notifications sent before this call have been picked up by the service manager when it returns
1179 successfully. Use of <function>sd_notify_barrier()</function> is needed for clients which are not invoked by the
1180 service manager, otherwise this synchronization mechanism is unnecessary for attribution of notifications to the
1181 unit.</para></listitem>
1182 </varlistentry>
1183
1184 <varlistentry>
1185 <term><varname>Sockets=</varname></term>
1186 <listitem><para>Specifies the name of the socket units this
1187 service shall inherit socket file descriptors from when the
1188 service is started. Normally, it should not be necessary to use
1189 this setting, as all socket file descriptors whose unit shares
1190 the same name as the service (subject to the different unit
1191 name suffix of course) are passed to the spawned
1192 process.</para>
1193
1194 <para>Note that the same socket file descriptors may be passed
1195 to multiple processes simultaneously. Also note that a
1196 different service may be activated on incoming socket traffic
1197 than the one which is ultimately configured to inherit the
1198 socket file descriptors. Or, in other words: the
1199 <varname>Service=</varname> setting of
1200 <filename>.socket</filename> units does not have to match the
1201 inverse of the <varname>Sockets=</varname> setting of the
1202 <filename>.service</filename> it refers to.</para>
1203
1204 <para>This option may appear more than once, in which case the list of socket units is merged. Note
1205 that once set, clearing the list of sockets again (for example, by assigning the empty string to this
1206 option) is not supported.</para></listitem>
1207 </varlistentry>
1208
1209 <varlistentry>
1210 <term><varname>FileDescriptorStoreMax=</varname></term>
1211 <listitem><para>Configure how many file descriptors may be stored in the service manager for the
1212 service using
1213 <citerefentry><refentrytitle>sd_pid_notify_with_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>'s
1214 <literal>FDSTORE=1</literal> messages. This is useful for implementing services that can restart
1215 after an explicit request or a crash without losing state. Any open sockets and other file
1216 descriptors which should not be closed during the restart may be stored this way. Application state
1217 can either be serialized to a file in <varname>RuntimeDirectory=</varname>, or stored in a
1218 <citerefentry><refentrytitle>memfd_create</refentrytitle><manvolnum>2</manvolnum></citerefentry>
1219 memory file descriptor. Defaults to 0, i.e. no file descriptors may be stored in the service
1220 manager. All file descriptors passed to the service manager from a specific service are passed back
1221 to the service's main process on the next service restart (see
1222 <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry> for
1223 details about the precise protocol used and the order in which the file descriptors are passed). Any
1224 file descriptors passed to the service manager are automatically closed when
1225 <constant>POLLHUP</constant> or <constant>POLLERR</constant> is seen on them, or when the service is
1226 fully stopped and no job is queued or being executed for it (the latter can be tweaked with
1227 <varname>FileDescriptorStorePreserve=</varname>, see below). If this option is used,
1228 <varname>NotifyAccess=</varname> (see above) should be set to open access to the notification socket
1229 provided by systemd. If <varname>NotifyAccess=</varname> is not set, it will be implicitly set to
1230 <option>main</option>.</para>
1231
1232 <para>The <command>fdstore</command> command of
1233 <citerefentry><refentrytitle>systemd-analyze</refentrytitle><manvolnum>1</manvolnum></citerefentry>
1234 may be used to list the current contents of a service's file descriptor store.</para>
1235
1236 <para>Note that the service manager will only pass file descriptors contained in the file descriptor
1237 store to the service's own processes, never to other clients via IPC or similar. However, it does
1238 allow unprivileged clients to query the list of currently open file descriptors of a
1239 service. Sensitive data may hence be safely placed inside the referenced files, but should not be
1240 attached to the metadata (e.g. included in filenames) of the stored file
1241 descriptors.</para>
1242
1243 <para>If this option is set to a non-zero value the <varname>$FDSTORE</varname> environment variable
1244 will be set for processes invoked for this service. See
1245 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
1246 details.</para>
1247
1248 <para>For further information on the file descriptor store see the <ulink
1249 url="https://systemd.io/FILE_DESCRIPTOR_STORE">File Descriptor Store</ulink> overview.</para>
1250
1251 <xi:include href="version-info.xml" xpointer="v219"/></listitem>
1252 </varlistentry>
1253
1254 <varlistentry>
1255 <term><varname>FileDescriptorStorePreserve=</varname></term>
1256 <listitem><para>Takes one of <constant>no</constant>, <constant>yes</constant>,
1257 <constant>restart</constant>, <constant>on-success</constant> and controls when to release the
1258 service's file descriptor store (i.e. when to close the contained file descriptors, if any). If set
1259 to <constant>no</constant> the file descriptor store is automatically released when the service is
1260 stopped; if <constant>restart</constant> (the default) it is kept around as long as the unit is
1261 neither inactive nor failed, or a job is queued for the service, or the service is expected to be
1262 restarted. If <constant>yes</constant> the file descriptor store is kept around and garbage
1263 collection of the unit is disabled. The latter is useful to keep entries in the file descriptor
1264 store pinned until the unit is removed, the service manager exits, or the file descriptors get
1265 <constant>EPOLLHUP</constant> or <constant>EPOLLERR</constant>. If <constant>on-success</constant>
1266 the behaviour is identical to <constant>yes</constant>, except that the file descriptor store is
1267 discarded if the unit enters the permanent <literal>failed</literal> state (i.e. once all automated
1268 restart attempts driven by <varname>Restart=</varname> have been exhausted). The store is preserved
1269 across the transitionary failed states that precede each individual auto-restart attempt.</para>
1270
1271 <para>When set to <constant>yes</constant> or <constant>on-success</constant>, and the service is
1272 itself running under another service manager (e.g. a service of <filename>[email protected]</filename>,
1273 or a payload inside
1274 <citerefentry><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry>),
1275 file descriptors pushed into the store are also forwarded one level up via the enveloping manager's
1276 <varname>$NOTIFY_SOCKET</varname>, tagged with the originating unit id, so that they are preserved
1277 across restarts of the inner manager and handed back to the originating unit when it is started
1278 again. For this to take effect, the enveloping unit must itself enable
1279 <varname>FileDescriptorStoreMax=</varname> and a non-<constant>no</constant>/<constant>restart</constant>
1280 value for <varname>FileDescriptorStorePreserve=</varname>.
1281 See the <ulink url="https://systemd.io/FILE_DESCRIPTOR_STORE">File Descriptor Store</ulink>
1282 overview for details.</para>
1283
1284 <para>Setting this to <constant>yes</constant> or <constant>on-success</constant> also ensures the
1285 file descriptor store is kept loaded across a <literal>kexec</literal>-based reboot on kernels
1286 supporting the <ulink
1287 url="https://docs.kernel.org/userspace-api/liveupdate.html">Live Update Orchestrator</ulink>,
1288 so that compatible file descriptors (such as <citerefentry
1289 project='man-pages'><refentrytitle>memfd_create</refentrytitle><manvolnum>2</manvolnum></citerefentry>)
1290 are preserved and handed back to the service on the other side. See the <ulink
1291 url="https://systemd.io/FILE_DESCRIPTOR_STORE">File Descriptor Store</ulink> overview for
1292 details.</para>
1293
1294 <para>Use <command>systemctl clean --what=fdstore …</command> to release the file descriptor store
1295 explicitly.</para>
1296
1297 <xi:include href="version-info.xml" xpointer="v254"/></listitem>
1298 </varlistentry>
1299
1300 <varlistentry>
1301 <term><varname>USBFunctionDescriptors=</varname></term>
1302 <listitem><para>Configure the location of a file containing
1303 <ulink
1304 url="https://docs.kernel.org/usb/functionfs.html">USB
1305 FunctionFS</ulink> descriptors, for implementation of USB
1306 gadget functions. This is used only in conjunction with a
1307 socket unit with <varname>ListenUSBFunction=</varname>
1308 configured. The contents of this file are written to the
1309 <filename>ep0</filename> file after it is
1310 opened.</para>
1311
1312 <xi:include href="version-info.xml" xpointer="v227"/></listitem>
1313 </varlistentry>
1314
1315 <varlistentry>
1316 <term><varname>USBFunctionStrings=</varname></term>
1317 <listitem><para>Configure the location of a file containing
1318 USB FunctionFS strings. Behavior is similar to
1319 <varname>USBFunctionDescriptors=</varname>
1320 above.</para>
1321
1322 <xi:include href="version-info.xml" xpointer="v227"/></listitem>
1323 </varlistentry>
1324
1325 <varlistentry id='oom-policy'>
1326 <term><varname>OOMPolicy=</varname></term>
1327
1328 <listitem><para>Configure the out-of-memory (OOM) killing policy for the kernel and the userspace OOM
1329 killer
1330 <citerefentry><refentrytitle>systemd-oomd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
1331 On Linux, when memory becomes scarce to the point that the kernel has trouble allocating memory for
1332 itself, it might decide to kill a running process in order to free up memory and reduce memory
1333 pressure. Note that <filename>systemd-oomd.service</filename> is a more flexible solution that aims
1334 to prevent out-of-memory situations for the userspace too, not just the kernel, by attempting to
1335 terminate services earlier, before the kernel would have to act.</para>
1336
1337 <para>This setting takes one of <constant>continue</constant>, <constant>stop</constant> or
1338 <constant>kill</constant>. If set to <constant>continue</constant> and a process in the unit is
1339 killed by the OOM killer, this is logged but the unit continues running. If set to
1340 <constant>stop</constant> the event is logged and the unit's processes are terminated cleanly by the
1341 service manager. If set to <constant>kill</constant> and one of the unit's processes is killed by the
1342 OOM killer the kernel is instructed to kill all remaining processes of the unit too, by setting the
1343 <filename>memory.oom.group</filename> attribute to <constant>1</constant>; also see kernel page
1344 <ulink url="https://docs.kernel.org/admin-guide/cgroup-v2.html">Control Group v2</ulink>. In case of
1345 both <constant>stop</constant> and <constant>kill</constant>, the service ultimately ends up in the
1346 <constant>oom-kill</constant> failed state after which <varname>Restart=</varname> may apply.
1347 </para>
1348
1349 <para>Defaults to the setting <varname>DefaultOOMPolicy=</varname> in
1350 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>
1351 is set to, except for units where <varname>Delegate=</varname> is turned on, where it defaults to
1352 <constant>continue</constant>.</para>
1353
1354 <para>Use the <varname>OOMScoreAdjust=</varname> setting to configure whether processes of the unit
1355 shall be considered preferred or less preferred candidates for process termination by the Linux OOM
1356 killer logic. See
1357 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
1358 details.</para>
1359
1360 <para>This setting also applies to
1361 <citerefentry><refentrytitle>systemd-oomd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
1362 Similarly to the kernel OOM kills performed by the kernel, this setting determines the state of the
1363 unit after <command>systemd-oomd</command> kills a cgroup associated with it.</para>
1364
1365 <xi:include href="version-info.xml" xpointer="v243"/></listitem>
1366 </varlistentry>
1367
1368 <varlistentry>
1369 <term><varname>OpenFile=</varname></term>
1370 <listitem><para>Takes an argument of the form <literal>path<optional><replaceable>:fd-name:options</replaceable></optional></literal>,
1371 where:
1372 <itemizedlist>
1373 <listitem><simpara><literal>path</literal> is a path to a file or an <constant>AF_UNIX</constant> socket in the file system;</simpara></listitem>
1374 <listitem><simpara><literal>fd-name</literal> is a name that will be associated with the file descriptor;
1375 the name may contain any ASCII character, but must exclude control characters and ":", and must be at most 255 characters in length;
1376 it is optional and, if not provided, defaults to the file name;</simpara></listitem>
1377 <listitem><simpara><literal>options</literal> is a comma-separated list of access options;
1378 possible values are
1379 <literal>read-only</literal>,
1380 <literal>append</literal>,
1381 <literal>truncate</literal>,
1382 <literal>graceful</literal>;
1383 if not specified, files will be opened in <constant>rw</constant> mode;
1384 if <literal>graceful</literal> is specified, errors during file/socket opening are ignored.
1385 Specifying the same option several times is treated as an error.</simpara></listitem>
1386 </itemizedlist>
1387 The file or socket is opened by the service manager and the file descriptor is passed to the service.
1388 If the path is a socket, we call <function>connect()</function> on it.
1389 See <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>
1390 for more details on how to retrieve these file descriptors.</para>
1391
1392 <para>This setting is useful to allow services to access files/sockets that they cannot access themselves
1393 (due to running in a separate mount namespace, not having privileges, ...).</para>
1394
1395 <para>This setting can be specified multiple times, in which case all the specified paths are opened and the file descriptors passed to the service.
1396 If the empty string is assigned, the entire list of open files defined prior to this is reset.</para>
1397
1398 <xi:include href="version-info.xml" xpointer="v253"/></listitem>
1399 </varlistentry>
1400
1401 <varlistentry>
1402 <term><varname>ReloadSignal=</varname></term>
1403 <listitem><para>Configures the UNIX process signal to send to the service's main process when asked
1404 to reload the service's configuration. Defaults to <constant>SIGHUP</constant>. This option has no
1405 effect unless <varname>Type=</varname><option>notify-reload</option> is used, see
1406 above.</para>
1407
1408 <xi:include href="version-info.xml" xpointer="v253"/></listitem>
1409 </varlistentry>
1410
1411 <varlistentry>
1412 <term><varname>RefreshOnReload=</varname></term>
1413
1414 <listitem><para>Takes a boolean argument, or a list of resources defined in
1415 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
1416 Possible values are <option>extensions</option> and <option>credentials</option>, separated by space.
1417 Prepending the list with a single tilde character (<literal>~</literal>) inverts the effect.
1418 Defaults to <option>extensions</option>. An empty assignment resets the list to default. If enabled,
1419 the corresponding resources (<option>ExtensionImages=</option>/<option>ExtensionDirectories=</option>
1420 for <option>extensions</option> and <option>LoadCredential=</option>/<option>ImportCredential=</option>/
1421 <option>SetCredential=</option> (along with their <option>Encrypted</option> counterparts)
1422 for <option>credentials</option>) will be refreshed on service reload. If <option>yes</option>,
1423 all resources listed above that are used by the service shall be refreshed.</para>
1424
1425 <para>Specially, if this option is set explicitly, and the respective resources are in use,
1426 the service may be reloaded without any actual reload mechanism (<option>ExecReload=</option>
1427 or <option>Type=notify-reload</option>) for notifying the main process, in which case the reload
1428 is considered complete immediately after refreshing.</para>
1429
1430 <xi:include href="version-info.xml" xpointer="v260"/></listitem>
1431 </varlistentry>
1432
1433 </variablelist>
1434
1435 <para id='shared-unit-options'>Check
1436 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1437 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>, and
1438 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry> for more
1439 settings.</para>
1440 </refsect1>
1441
1442 <refsect1>
1443 <title>Command lines</title>
1444
1445 <para>This section describes command line parsing and
1446 variable and specifier substitutions for
1447 <varname>ExecStart=</varname>,
1448 <varname>ExecStartPre=</varname>,
1449 <varname>ExecStartPost=</varname>,
1450 <varname>ExecReload=</varname>,
1451 <varname>ExecStop=</varname>,
1452 <varname>ExecStopPost=</varname>, and
1453 <varname>ExecCondition=</varname> options.</para>
1454
1455 <para>Multiple command lines may be specified by using the relevant setting multiple times.</para>
1456
1457 <para>Each command line is unquoted using the rules described in "Quoting" section in
1458 <citerefentry><refentrytitle>systemd.syntax</refentrytitle><manvolnum>7</manvolnum></citerefentry>. The
1459 first item becomes the command to execute, and the subsequent items the arguments.</para>
1460
1461 <para>This syntax is inspired by shell syntax, but only the meta-characters and expansions
1462 described in the following paragraphs are understood, and the expansion of variables is
1463 different. Specifically, redirection using
1464 <literal>&lt;</literal>,
1465 <literal>&lt;&lt;</literal>,
1466 <literal>&gt;</literal>, and
1467 <literal>&gt;&gt;</literal>, pipes using
1468 <literal>|</literal>, running programs in the background using
1469 <literal>&amp;</literal>, and <emphasis>other elements of shell
1470 syntax are not supported</emphasis>.</para>
1471
1472 <para>The command to execute may contain spaces, but control characters are not allowed.</para>
1473
1474 <para>Each command may be prefixed with a number of special characters:</para>
1475
1476 <table>
1477 <title>Special executable prefixes</title>
1478
1479 <tgroup cols='2'>
1480 <colspec colname='prefix'/>
1481 <colspec colname='meaning'/>
1482
1483 <thead>
1484 <row>
1485 <entry>Prefix</entry>
1486 <entry>Effect</entry>
1487 </row>
1488 </thead>
1489 <tbody>
1490 <row>
1491 <entry><literal>@</literal></entry>
1492 <entry>If the executable path is prefixed with <literal>@</literal>, the second specified token will be passed as <constant>argv[0]</constant> to the executed process (instead of the actual filename), followed by the further arguments specified, unless <literal>|</literal> is also specified, in which case it enables login shell semantics for the shell spawned by prefixing <literal>-</literal> to <constant>argv[0]</constant>.</entry>
1493 </row>
1494
1495 <row>
1496 <entry><literal>-</literal></entry>
1497 <entry>If the executable path is prefixed with <literal>-</literal>, an exit code of the command normally considered a failure (i.e. non-zero exit status or abnormal exit due to signal) is recorded, but has no further effect and is considered equivalent to success.</entry>
1498 </row>
1499
1500 <row>
1501 <entry><literal>:</literal></entry>
1502 <entry>If the executable path is prefixed with <literal>:</literal>, environment variable substitution (as described below this table) is not applied.</entry>
1503 </row>
1504
1505 <row>
1506 <entry><literal>+</literal></entry>
1507 <entry>If the executable path is prefixed with <literal>+</literal> then the process is executed with full privileges. In this mode privilege restrictions configured with <varname>User=</varname>, <varname>Group=</varname>, <varname>CapabilityBoundingSet=</varname> or the various file system namespacing options (such as <varname>PrivateDevices=</varname>, <varname>PrivateTmp=</varname>) are not applied to the invoked command line (but still affect any other <varname>ExecStart=</varname>, <varname>ExecStop=</varname>, … lines). However, note that this will not bypass options that apply to the whole control group, such as <varname>DevicePolicy=</varname>, see <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry> for the full list.</entry>
1508 </row>
1509
1510 <row>
1511 <entry><literal>!</literal></entry>
1512
1513 <entry>Similar to the <literal>+</literal> character discussed above this permits invoking command lines with elevated privileges. However, unlike <literal>+</literal> the <literal>!</literal> character exclusively alters the effect of <varname>User=</varname>, <varname>Group=</varname> and <varname>SupplementaryGroups=</varname>, i.e. only the stanzas that affect user and group credentials. Note that this setting may be combined with <varname>DynamicUser=</varname>, in which case a dynamic user/group pair is allocated before the command is invoked, but credential changing is left to the executed process itself.</entry>
1514 </row>
1515
1516 <row>
1517 <entry><literal>|</literal></entry>
1518
1519 <entry>If <literal>|</literal> is specified standalone as executable path, invoke the default shell of <varname>User=</varname>. If specified as a prefix, use the shell (<literal>-c</literal>) to spawn the executable. When <literal>@</literal> is used in conjunction, <constant>argv[0]</constant> of shell will be prefixed with <literal>-</literal> to enable login shell semantics.</entry>
1520 </row>
1521 </tbody>
1522 </tgroup>
1523 </table>
1524
1525 <para><literal>@</literal>, <literal>|</literal>, <literal>-</literal>, <literal>:</literal>, and one of
1526 <literal>+</literal>/<literal>!</literal> may be used together and they can appear in any order.
1527 However, <literal>+</literal> and <literal>!</literal> may not be specified at the same time.</para>
1528
1529 <para>For each command, the first argument must be either an absolute path to an executable or a simple
1530 file name without any slashes. If the command is not a full (absolute) path, it will be resolved to a
1531 full path using a fixed search path determined at compilation time. Searched directories include
1532 <filename>/usr/local/bin/</filename>, <filename>/usr/bin/</filename>, and their
1533 <filename>sbin/</filename> counterparts (only on systems using split <filename>bin/</filename> and
1534 <filename>sbin/</filename>). It is thus safe to use just the executable name in case of executables
1535 located in any of the "standard" directories, and an absolute path must be used in other cases. Hint:
1536 this search path may be queried using <command>systemd-path search-binaries-default</command>.</para>
1537
1538 <para>The command line accepts <literal>%</literal> specifiers as described in
1539 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
1540
1541 <para>An argument solely consisting of <literal>;</literal> must be escaped, i.e. specified as <literal>\;</literal>.</para>
1542
1543 <para>Basic environment variable substitution is supported. Use
1544 <literal>${FOO}</literal> as part of a word, or as a word of its
1545 own, on the command line, in which case it will be erased and replaced
1546 by the exact value of the environment variable (if any) including all
1547 whitespace it contains, always resulting in exactly a single argument.
1548 Use <literal>$FOO</literal> as a separate word on the command line, in
1549 which case it will be replaced by the value of the environment
1550 variable split at whitespace, resulting in zero or more arguments.
1551 For this type of expansion, quotes are respected when splitting
1552 into words, and afterwards removed.</para>
1553
1554 <para>Example:</para>
1555
1556 <programlisting>Environment="ONE=one" 'TWO=two two'
1557 ExecStart=echo $ONE $TWO ${TWO}</programlisting>
1558
1559 <para>This will execute <command>/bin/echo</command> with four
1560 arguments: <literal>one</literal>, <literal>two</literal>,
1561 <literal>two</literal>, and <literal>two two</literal>.</para>
1562
1563 <para>Example:</para>
1564 <programlisting>Environment=ONE='one' "TWO='two two' too" THREE=
1565 ExecStart=/bin/echo ${ONE} ${TWO} ${THREE}
1566 ExecStart=/bin/echo $ONE $TWO $THREE</programlisting>
1567 <para>This results in <filename>/bin/echo</filename> being
1568 called twice, the first time with arguments
1569 <literal>'one'</literal>,
1570 <literal>'two two' too</literal>, <literal></literal>,
1571 and the second time with arguments
1572 <literal>one</literal>, <literal>two two</literal>,
1573 <literal>too</literal>.
1574 </para>
1575
1576 <para>Unless for commands with the special executable prefix <literal>:</literal>,
1577 to pass a literal dollar sign, use <literal>$$</literal>.
1578 Variables whose value is not known at expansion time are treated
1579 as empty strings. Note that the first argument (i.e. the program
1580 to execute) may not be a variable.</para>
1581
1582 <para>Variables to be used in this fashion may be defined through
1583 <varname>Environment=</varname> and
1584 <varname>EnvironmentFile=</varname>. In addition, variables listed
1585 in the section "Environment variables in spawned processes" in
1586 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1587 which are considered "static configuration", may be used (this
1588 includes e.g. <varname>$USER</varname>, but not
1589 <varname>$TERM</varname>).</para>
1590
1591 <para>Note that shell command lines are not directly supported, and <literal>|</literal> invokes the user's
1592 default shell which isn't deterministic. It's recommended to specify a shell implementation explicitly
1593 if portability is desired. Example:</para>
1594 <programlisting>ExecStart=sh -c 'dmesg | tac'</programlisting>
1595
1596 <para>Example:</para>
1597
1598 <programlisting>ExecStart=echo one
1599 ExecStart=echo "two two"</programlisting>
1600
1601 <para>This will execute <command>echo</command> two times,
1602 each time with one argument: <literal>one</literal> and
1603 <literal>two two</literal>, respectively. Because two commands are
1604 specified, <varname>Type=oneshot</varname> must be used.</para>
1605
1606 <para>Example:</para>
1607
1608 <programlisting>Type=oneshot
1609 ExecStart=:echo $USER
1610 ExecStart=-false
1611 ExecStart=+:@true $TEST</programlisting>
1612
1613 <para>This will execute <command>/usr/bin/echo</command> with the literal argument
1614 <literal>$USER</literal> (<literal>:</literal> suppresses variable expansion), and then
1615 <command>/usr/bin/false</command> (the return value will be ignored because <literal>-</literal>
1616 suppresses checking of the return value), and <command>/usr/bin/true</command> (with elevated privileges,
1617 with <literal>$TEST</literal> as <constant>argv[0]</constant>).</para>
1618
1619 <para>Example:</para>
1620
1621 <programlisting>ExecStart=echo / &gt;/dev/null &amp; \; \
1622 ls</programlisting>
1623
1624 <para>This will execute <command>echo</command>
1625 with five arguments: <literal>/</literal>,
1626 <literal>&gt;/dev/null</literal>,
1627 <literal>&amp;</literal>, <literal>;</literal>, and
1628 <literal>ls</literal>.</para>
1629 </refsect1>
1630
1631 <refsect1>
1632 <title>Examples</title>
1633
1634 <example>
1635 <title>Simple service</title>
1636
1637 <para>The following unit file creates a service that will
1638 execute <filename index="false">/usr/sbin/foo-daemon</filename>. Since no
1639 <varname>Type=</varname> is specified, the default
1640 <varname>Type=</varname><option>simple</option> will be assumed.
1641 systemd will assume the unit to be started immediately after the
1642 program has begun executing.</para>
1643
1644 <programlisting>[Unit]
1645 Description=Foo
1646
1647 [Service]
1648 ExecStart=/usr/sbin/foo-daemon
1649
1650 [Install]
1651 WantedBy=multi-user.target</programlisting>
1652
1653 <para>Note that systemd assumes here that the process started by
1654 systemd will continue running until the service terminates. If
1655 the program daemonizes itself (i.e. forks), please use
1656 <varname>Type=</varname><option>forking</option> instead.</para>
1657
1658 <para>Since no <varname>ExecStop=</varname> was specified,
1659 systemd will send SIGTERM to all processes started from this
1660 service, and after a timeout also SIGKILL. This behavior can be
1661 modified, see
1662 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>
1663 for details.</para>
1664
1665 <para>Note that this unit type does not include any type of notification when a service has completed
1666 initialization. For this, you should use other unit types, such as
1667 <varname>Type=</varname><option>notify</option>/<varname>Type=</varname><option>notify-reload</option>
1668 if the service understands systemd's notification protocol,
1669 <varname>Type=</varname><option>forking</option> if the service can background itself or
1670 <varname>Type=</varname><option>dbus</option> if the unit acquires a DBus name once initialization is
1671 complete. See below.</para>
1672 </example>
1673
1674 <example>
1675 <title>Oneshot service</title>
1676
1677 <para>Sometimes, units should just execute an action without
1678 keeping active processes, such as a filesystem check or a
1679 cleanup action on boot. For this,
1680 <varname>Type=</varname><option>oneshot</option> exists. Units
1681 of this type will wait until the process specified terminates
1682 and then fall back to being inactive. The following unit will
1683 perform a cleanup action:</para>
1684
1685 <programlisting>[Unit]
1686 Description=Cleanup old Foo data
1687
1688 [Service]
1689 Type=oneshot
1690 ExecStart=/usr/sbin/foo-cleanup
1691
1692 [Install]
1693 WantedBy=multi-user.target</programlisting>
1694
1695 <para>Note that systemd will consider the unit to be in the
1696 state "starting" until the program has terminated, so ordered
1697 dependencies will wait for the program to finish before starting
1698 themselves. The unit will revert to the "inactive" state after
1699 the execution is done, never reaching the "active" state. That
1700 means another request to start the unit will perform the action
1701 again.</para>
1702
1703 <para><varname>Type=</varname><option>oneshot</option> are the
1704 only service units that may have more than one
1705 <varname>ExecStart=</varname> specified. For units with multiple
1706 commands (<varname index="false">Type=oneshot</varname>), all commands will be run again.</para>
1707 <para> For <varname index="false">Type=oneshot</varname>, <varname>Restart=</varname><option>always</option>
1708 and <varname>Restart=</varname><option>on-success</option> are <emphasis>not</emphasis> allowed.</para>
1709 </example>
1710
1711 <example>
1712 <title>Stoppable oneshot service</title>
1713
1714 <para>Similarly to the oneshot services, there are sometimes
1715 units that need to execute a program to set up something and
1716 then execute another to shut it down, but no process remains
1717 active while they are considered "started". Network
1718 configuration can sometimes fall into this category. Another use
1719 case is if a oneshot service shall not be executed each time
1720 when they are pulled in as a dependency, but only the first
1721 time.</para>
1722
1723 <para>For this, systemd knows the setting
1724 <varname>RemainAfterExit=</varname><option>yes</option>, which
1725 causes systemd to consider the unit to be active if the start
1726 action exited successfully. This directive can be used with all
1727 types, but is most useful with
1728 <varname>Type=</varname><option>oneshot</option> and
1729 <varname>Type=</varname><option>simple</option>. With
1730 <varname>Type=</varname><option>oneshot</option>, systemd waits
1731 until the start action has completed before it considers the
1732 unit to be active, so dependencies start only after the start
1733 action has succeeded. With
1734 <varname>Type=</varname><option>simple</option>, dependencies
1735 will start immediately after the start action has been
1736 dispatched. The following unit provides an example for a simple
1737 static firewall.</para>
1738
1739 <programlisting>[Unit]
1740 Description=Simple firewall
1741
1742 [Service]
1743 Type=oneshot
1744 RemainAfterExit=yes
1745 ExecStart=/usr/local/sbin/simple-firewall-start
1746 ExecStop=/usr/local/sbin/simple-firewall-stop
1747
1748 [Install]
1749 WantedBy=multi-user.target</programlisting>
1750
1751 <para>Since the unit is considered to be running after the start
1752 action has exited, invoking <command>systemctl start</command>
1753 on that unit again will cause no action to be taken.</para>
1754 </example>
1755
1756 <example>
1757 <title>Traditional forking services</title>
1758
1759 <para>Many traditional daemons/services background (i.e. fork,
1760 daemonize) themselves when starting. Set
1761 <varname>Type=</varname><option>forking</option> in the
1762 service's unit file to support this mode of operation. systemd
1763 will consider the service to be in the process of initialization
1764 while the original program is still running. Once it exits
1765 successfully and at least a process remains (and
1766 <varname>RemainAfterExit=</varname><option>no</option>), the
1767 service is considered started.</para>
1768
1769 <para>Often, a traditional daemon only consists of one process.
1770 Therefore, if only one process is left after the original
1771 process terminates, systemd will consider that process the main
1772 process of the service. In that case, the
1773 <varname>$MAINPID</varname> variable will be available in
1774 <varname>ExecReload=</varname>, <varname>ExecStop=</varname>,
1775 etc.</para>
1776
1777 <para>In case more than one process remains, systemd will be
1778 unable to determine the main process, so it will not assume
1779 there is one. In that case, <varname>$MAINPID</varname> will not
1780 expand to anything. However, if the process decides to write a
1781 traditional PID file, systemd will be able to read the main PID
1782 from there. Please set <varname>PIDFile=</varname> accordingly.
1783 Note that the daemon should write that file before finishing
1784 with its initialization. Otherwise, systemd might try to read the
1785 file before it exists.</para>
1786
1787 <para>The following example shows a simple daemon that forks and
1788 just starts one process in the background:</para>
1789
1790 <programlisting>[Unit]
1791 Description=My Simple Daemon
1792
1793 [Service]
1794 Type=forking
1795 ExecStart=/usr/sbin/my-simple-daemon -d
1796
1797 [Install]
1798 WantedBy=multi-user.target</programlisting>
1799
1800 <para>Please see
1801 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>
1802 for details on how you can influence the way systemd terminates
1803 the service.</para>
1804 </example>
1805
1806 <example>
1807 <title>DBus services</title>
1808
1809 <para>For services that acquire a name on the DBus system bus,
1810 use <varname>Type=</varname><option>dbus</option> and set
1811 <varname>BusName=</varname> accordingly. The service should not
1812 fork (daemonize). systemd will consider the service to be
1813 initialized once the name has been acquired on the system bus.
1814 The following example shows a typical DBus service:</para>
1815
1816 <programlisting>[Unit]
1817 Description=Simple DBus Service
1818
1819 [Service]
1820 Type=dbus
1821 BusName=org.example.simple-dbus-service
1822 ExecStart=/usr/sbin/simple-dbus-service
1823
1824 [Install]
1825 WantedBy=multi-user.target</programlisting>
1826
1827 <para>For <emphasis>bus-activatable</emphasis> services, do not
1828 include a [Install] section in the systemd
1829 service file, but use the <varname>SystemdService=</varname>
1830 option in the corresponding DBus service file, for example
1831 (<filename>/usr/share/dbus-1/system-services/org.example.simple-dbus-service.service</filename>):</para>
1832
1833 <programlisting>[D-BUS Service]
1834 Name=org.example.simple-dbus-service
1835 Exec=/usr/sbin/simple-dbus-service
1836 User=root
1837 SystemdService=simple-dbus-service.service</programlisting>
1838
1839 <para>Please see
1840 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>
1841 for details on how you can influence the way systemd terminates
1842 the service.</para>
1843 </example>
1844
1845 <example>
1846 <title>Services that notify systemd about their initialization</title>
1847
1848 <para><varname>Type=</varname><option>simple</option> services are really easy to write, but have the
1849 major disadvantage of systemd not being able to tell when initialization of the given service is
1850 complete. For this reason, systemd supports a simple notification protocol that allows daemons to make
1851 systemd aware that they are done initializing. Use <varname>Type=</varname><option>notify</option> or
1852 <varname>Type=</varname><option>notify-reload</option> for this. A typical service file for such a
1853 daemon would look like this:</para>
1854
1855 <programlisting>[Unit]
1856 Description=Simple Notifying Service
1857
1858 [Service]
1859 Type=notify-reload
1860 ExecStart=/usr/sbin/simple-notifying-service
1861
1862 [Install]
1863 WantedBy=multi-user.target</programlisting>
1864
1865 <para>Note that the daemon has to support systemd's notification
1866 protocol, else systemd will think the service has not started yet
1867 and kill it after a timeout. For an example of how to update
1868 daemons to support this protocol transparently, take a look at
1869 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
1870 systemd will consider the unit to be in the 'starting' state
1871 until a readiness notification has arrived.</para>
1872
1873 <para>Please see
1874 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>
1875 for details on how you can influence the way systemd terminates
1876 the service.</para>
1877
1878 <para>To avoid code duplication, it is preferable to use
1879 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>
1880 when possible, especially when other APIs provided by
1881 <citerefentry><refentrytitle>libsystemd</refentrytitle><manvolnum>3</manvolnum></citerefentry> are
1882 also used, but note that the notification protocol is very simple and guaranteed to be stable as per
1883 the <ulink url="https://systemd.io/PORTABILITY_AND_STABILITY/">Interface Portability and Stability
1884 Promise</ulink>, so it can be reimplemented by services with no external dependencies. For a
1885 self-contained example, see
1886 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
1887 </example>
1888 </refsect1>
1889
1890 <refsect1>
1891 <title>See Also</title>
1892 <para><simplelist type="inline">
1893 <member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
1894 <member><citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
1895 <member><citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
1896 <member><citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
1897 <member><citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
1898 <member><citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
1899 <member><citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
1900 <member><citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry></member>
1901 <member><citerefentry><refentrytitle>systemd-run</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
1902 </simplelist></para>
1903 </refsect1>
1904
1905 </refentry>