]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/systemd.service.xml
Fix DPI for Logitech M185, M510, and M705. (#9182)
[thirdparty/systemd.git] / man / systemd.service.xml
CommitLineData
c129bd5d 1<?xml version='1.0'?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*-->
d1ab0ca0 2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
12b42c76 3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
d1ab0ca0
LP
4
5<!--
572eb058
ZJS
6 SPDX-License-Identifier: LGPL-2.1+
7
d1ab0ca0
LP
8 This file is part of systemd.
9
10 Copyright 2010 Lennart Poettering
d1ab0ca0
LP
11-->
12
13<refentry id="systemd.service">
798d3a52
ZJS
14 <refentryinfo>
15 <title>systemd.service</title>
16 <productname>systemd</productname>
17
18 <authorgroup>
19 <author>
20 <contrib>Developer</contrib>
21 <firstname>Lennart</firstname>
22 <surname>Poettering</surname>
23 <email>lennart@poettering.net</email>
24 </author>
25 </authorgroup>
26 </refentryinfo>
27
28 <refmeta>
29 <refentrytitle>systemd.service</refentrytitle>
30 <manvolnum>5</manvolnum>
31 </refmeta>
32
33 <refnamediv>
34 <refname>systemd.service</refname>
35 <refpurpose>Service unit configuration</refpurpose>
36 </refnamediv>
37
38 <refsynopsisdiv>
39 <para><filename><replaceable>service</replaceable>.service</filename></para>
40 </refsynopsisdiv>
41
42 <refsect1>
43 <title>Description</title>
44
45 <para>A unit configuration file whose name ends in
ed10715a 46 <literal>.service</literal> encodes information about a process
798d3a52
ZJS
47 controlled and supervised by systemd.</para>
48
49 <para>This man page lists the configuration options specific to
50 this unit type. See
51 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
52 for the common options of all unit configuration files. The common
53 configuration items are configured in the generic
54 <literal>[Unit]</literal> and <literal>[Install]</literal>
55 sections. The service specific configuration options are
56 configured in the <literal>[Service]</literal> section.</para>
57
58 <para>Additional options are listed in
59 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
60 which define the execution environment the commands are executed
61 in, and in
62 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
63 which define the way the processes of the service are terminated,
64 and in
65 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
66 which configure resource control settings for the processes of the
67 service.</para>
68
798d3a52
ZJS
69 <para>If a service is requested under a certain name but no unit
70 configuration file is found, systemd looks for a SysV init script
71 by the same name (with the <filename>.service</filename> suffix
72 removed) and dynamically creates a service unit from that script.
73 This is useful for compatibility with SysV. Note that this
74 compatibility is quite comprehensive but not 100%. For details
75 about the incompatibilities, see the <ulink
28a0ad81 76 url="https://www.freedesktop.org/wiki/Software/systemd/Incompatibilities">Incompatibilities
c129bd5d
LP
77 with SysV</ulink> document.</para>
78 </refsect1>
79
80 <refsect1>
75695fb7
ZJS
81 <title>Service Templates</title>
82
83 <para>It is possible for <command>systemd</command> services to take a single argument via the
84 <literal><replaceable>service</replaceable>@<replaceable>argument</replaceable>.service</literal>
85 syntax. Such services are called "instantiated" services, while the unit definition without the
86 <replaceable>argument</replaceable> parameter is called a "template". An example could be a
87 <filename>dhcpcd@.service</filename> service template which takes a network interface as a
88 parameter to form an instantiated service. Within the service file, this parameter or "instance
89 name" can be accessed with %-specifiers. See
90 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
91 for details.</para>
798d3a52
ZJS
92 </refsect1>
93
45f09f93 94 <refsect1>
aed5cb03
ZJS
95 <title>Automatic Dependencies</title>
96
97 <refsect2>
98 <title>Implicit Dependencies</title>
99
100 <para>The following dependencies are implicitly added:</para>
101
102 <itemizedlist>
103 <listitem><para>Services with <varname>Type=dbus</varname> set automatically
104 acquire dependencies of type <varname>Requires=</varname> and
105 <varname>After=</varname> on
106 <filename>dbus.socket</filename>.</para></listitem>
107
108 <listitem><para>Socket activated services are automatically ordered after
109 their activating <filename>.socket</filename> units via an
110 automatic <varname>After=</varname> dependency.
111 Services also pull in all <filename>.socket</filename> units
112 listed in <varname>Sockets=</varname> via automatic
113 <varname>Wants=</varname> and <varname>After=</varname> dependencies.</para></listitem>
114 </itemizedlist>
115
116 <para>Additional implicit dependencies may be added as result of
117 execution and resource control parameters as documented in
118 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
119 and
120 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
121 </refsect2>
122
123 <refsect2>
124 <title>Default Dependencies</title>
125
126 <para>The following dependencies are added unless <varname>DefaultDependencies=no</varname> is set:</para>
127
128 <itemizedlist>
129 <listitem><para>Service units will have dependencies of type <varname>Requires=</varname> and
130 <varname>After=</varname> on <filename>sysinit.target</filename>, a dependency of type <varname>After=</varname> on
131 <filename>basic.target</filename> as well as dependencies of type <varname>Conflicts=</varname> and
132 <varname>Before=</varname> on <filename>shutdown.target</filename>. These ensure that normal service units pull in
133 basic system initialization, and are terminated cleanly prior to system shutdown. Only services involved with early
134 boot or late system shutdown should disable this option.</para></listitem>
135
136 <listitem><para>Instanced service units (i.e. service units with an <literal>@</literal> in their name) are assigned by
137 default a per-template slice unit (see
138 <citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry>), named after the
139 template unit, containing all instances of the specific template. This slice is normally stopped at shutdown,
140 together with all template instances. If that is not desired, set <varname>DefaultDependencies=no</varname> in the
141 template unit, and either define your own per-template slice unit file that also sets
142 <varname>DefaultDependencies=no</varname>, or set <varname>Slice=system.slice</varname> (or another suitable slice)
143 in the template unit. Also see
144 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
145 </para></listitem>
146 </itemizedlist>
147 </refsect2>
45f09f93
JL
148 </refsect1>
149
798d3a52
ZJS
150 <refsect1>
151 <title>Options</title>
152
153 <para>Service files must include a <literal>[Service]</literal>
154 section, which carries information about the service and the
155 process it supervises. A number of options that may be used in
156 this section are shared with other unit types. These options are
157 documented in
aa9f9e58
LW
158 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
159 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>
798d3a52 160 and
aa9f9e58 161 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
798d3a52
ZJS
162 The options specific to the <literal>[Service]</literal> section
163 of service units are the following:</para>
164
165 <variablelist class='unit-directives'>
166 <varlistentry>
167 <term><varname>Type=</varname></term>
168
169 <listitem><para>Configures the process start-up type for this
170 service unit. One of
171 <option>simple</option>,
172 <option>forking</option>,
173 <option>oneshot</option>,
174 <option>dbus</option>,
175 <option>notify</option> or
176 <option>idle</option>.</para>
177
178 <para>If set to <option>simple</option> (the default if
179 neither <varname>Type=</varname> nor
180 <varname>BusName=</varname>, but <varname>ExecStart=</varname>
181 are specified), it is expected that the process configured
182 with <varname>ExecStart=</varname> is the main process of the
183 service. In this mode, if the process offers functionality to
184 other processes on the system, its communication channels
185 should be installed before the daemon is started up (e.g.
186 sockets set up by systemd, via socket activation), as systemd
187 will immediately proceed starting follow-up units.</para>
188
189 <para>If set to <option>forking</option>, it is expected that
190 the process configured with <varname>ExecStart=</varname> will
191 call <function>fork()</function> as part of its start-up. The
192 parent process is expected to exit when start-up is complete
193 and all communication channels are set up. The child continues
194 to run as the main daemon process. This is the behavior of
195 traditional UNIX daemons. If this setting is used, it is
196 recommended to also use the <varname>PIDFile=</varname>
197 option, so that systemd can identify the main process of the
198 daemon. systemd will proceed with starting follow-up units as
199 soon as the parent process exits.</para>
200
201 <para>Behavior of <option>oneshot</option> is similar to
202 <option>simple</option>; however, it is expected that the
203 process has to exit before systemd starts follow-up units.
204 <varname>RemainAfterExit=</varname> is particularly useful for
205 this type of service. This is the implied default if neither
bda99fab 206 <varname>Type=</varname> nor <varname>ExecStart=</varname> are
798d3a52
ZJS
207 specified.</para>
208
209 <para>Behavior of <option>dbus</option> is similar to
210 <option>simple</option>; however, it is expected that the
211 daemon acquires a name on the D-Bus bus, as configured by
212 <varname>BusName=</varname>. systemd will proceed with
213 starting follow-up units after the D-Bus bus name has been
214 acquired. Service units with this option configured implicitly
215 gain dependencies on the <filename>dbus.socket</filename>
216 unit. This type is the default if <varname>BusName=</varname>
217 is specified.</para>
218
219 <para>Behavior of <option>notify</option> is similar to
220 <option>simple</option>; however, it is expected that the
221 daemon sends a notification message via
222 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>
223 or an equivalent call when it has finished starting up.
224 systemd will proceed with starting follow-up units after this
225 notification message has been sent. If this option is used,
226 <varname>NotifyAccess=</varname> (see below) should be set to
227 open access to the notification socket provided by systemd. If
aa4f6cf1
LB
228 <varname>NotifyAccess=</varname> is missing or set to
229 <option>none</option>, it will be forcibly set to
230 <option>main</option>. Note that currently
798d3a52
ZJS
231 <varname>Type=</varname><option>notify</option> will not work
232 if used in combination with
233 <varname>PrivateNetwork=</varname><option>yes</option>.</para>
234
6dcda09c 235 <para>Behavior of <option>idle</option> is very similar to <option>simple</option>; however, actual execution
3f2d1365 236 of the service program is delayed until all active jobs are dispatched. This may be used to avoid interleaving
6dcda09c
LP
237 of output of shell services with the status output on the console. Note that this type is useful only to
238 improve console output, it is not useful as a general unit ordering tool, and the effect of this service type
3f2d1365 239 is subject to a 5s time-out, after which the service program is invoked anyway.</para>
798d3a52
ZJS
240 </listitem>
241 </varlistentry>
242
243 <varlistentry>
244 <term><varname>RemainAfterExit=</varname></term>
245
246 <listitem><para>Takes a boolean value that specifies whether
247 the service shall be considered active even when all its
248 processes exited. Defaults to <option>no</option>.</para>
249 </listitem>
250 </varlistentry>
251
252 <varlistentry>
253 <term><varname>GuessMainPID=</varname></term>
254
255 <listitem><para>Takes a boolean value that specifies whether
256 systemd should try to guess the main PID of a service if it
257 cannot be determined reliably. This option is ignored unless
258 <option>Type=forking</option> is set and
259 <option>PIDFile=</option> is unset because for the other types
260 or with an explicitly configured PID file, the main PID is
261 always known. The guessing algorithm might come to incorrect
262 conclusions if a daemon consists of more than one process. If
263 the main PID cannot be determined, failure detection and
264 automatic restarting of a service will not work reliably.
265 Defaults to <option>yes</option>.</para>
266 </listitem>
267 </varlistentry>
268
269 <varlistentry>
270 <term><varname>PIDFile=</varname></term>
271
db256aab
LP
272 <listitem><para>Takes an absolute path referring to the PID file of the service. Usage of this option is
273 recommended for services where <varname>Type=</varname> is set to <option>forking</option>. The service manager
274 will read the PID of the main process of the service from this file after start-up of the service. The service
275 manager will not write to the file configured here, although it will remove the file after the service has shut
276 down if it still exists. The PID file does not need to be owned by a privileged user, but if it is owned by an
277 unprivileged user additional safety restrictions are enforced: the file may not be a symlink to a file owned by
278 a different user (neither directly nor indirectly), and the PID file must refer to a process already belonging
279 to the service.</para></listitem>
798d3a52
ZJS
280 </varlistentry>
281
282 <varlistentry>
283 <term><varname>BusName=</varname></term>
284
285 <listitem><para>Takes a D-Bus bus name that this service is
286 reachable as. This option is mandatory for services where
287 <varname>Type=</varname> is set to
288 <option>dbus</option>.</para>
289 </listitem>
290 </varlistentry>
291
798d3a52
ZJS
292 <varlistentry>
293 <term><varname>ExecStart=</varname></term>
294 <listitem><para>Commands with their arguments that are
295 executed when this service is started. The value is split into
a8eaaee7 296 zero or more command lines according to the rules described
798d3a52
ZJS
297 below (see section "Command Lines" below).
298 </para>
299
29df65f9
ZJS
300 <para>Unless <varname>Type=</varname> is <option>oneshot</option>, exactly one command must be given. When
301 <varname>Type=oneshot</varname> is used, zero or more commands may be specified. Commands may be specified by
302 providing multiple command lines in the same directive, or alternatively, this directive may be specified more
303 than once with the same effect. If the empty string is assigned to this option, the list of commands to start
304 is reset, prior assignments of this option will have no effect. If no <varname>ExecStart=</varname> is
e4b45b32
LP
305 specified, then the service must have <varname>RemainAfterExit=yes</varname> and at least one
306 <varname>ExecStop=</varname> line set. (Services lacking both <varname>ExecStart=</varname> and
307 <varname>ExecStop=</varname> are not valid.)</para>
798d3a52 308
5008da1e
ZJS
309 <para>For each of the specified commands, the first argument must be either an absolute path to an executable
310 or a simple file name without any slashes. Optionally, this filename may be prefixed with a number of special
311 characters:</para>
165a31c0
LP
312
313 <table>
314 <title>Special executable prefixes</title>
315
316 <tgroup cols='2'>
317 <colspec colname='prefix'/>
318 <colspec colname='meaning'/>
319
320 <thead>
321 <row>
322 <entry>Prefix</entry>
323 <entry>Effect</entry>
324 </row>
325 </thead>
326 <tbody>
327 <row>
328 <entry><literal>@</literal></entry>
329 <entry>If the executable path is prefixed with <literal>@</literal>, the second specified token will be passed as <literal>argv[0]</literal> to the executed process (instead of the actual filename), followed by the further arguments specified.</entry>
330 </row>
331
332 <row>
333 <entry><literal>-</literal></entry>
334 <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 ignored and considered success.</entry>
335 </row>
336
337 <row>
338 <entry><literal>+</literal></entry>
339 <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).</entry>
340 </row>
341
342 <row>
343 <entry><literal>!</literal></entry>
344
345 <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 the 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>
346 </row>
347
348 <row>
349 <entry><literal>!!</literal></entry>
350
132523e7 351 <entry>This prefix is very similar to <literal>!</literal>, however it only has an effect on systems lacking support for ambient process capabilities, i.e. without support for <varname>AmbientCapabilities=</varname>. It's intended to be used for unit files that take benefit of ambient capabilities to run processes with minimal privileges wherever possible while remaining compatible with systems that lack ambient capabilities support. Note that when <literal>!!</literal> is used, and a system lacking ambient capability support is detected any configured <varname>SystemCallFilter=</varname> and <varname>CapabilityBoundingSet=</varname> stanzas are implicitly modified, in order to permit spawned processes to drop credentials and capabilities themselves, even if this is configured to not be allowed. Moreover, if this prefix is used and a system lacking ambient capability support is detected <varname>AmbientCapabilities=</varname> will be skipped and not be applied. On systems supporting ambient capabilities, <literal>!!</literal> has no effect and is redundant.</entry>
165a31c0
LP
352 </row>
353 </tbody>
354 </tgroup>
355 </table>
356
357 <para><literal>@</literal>, <literal>-</literal>, and one of
358 <literal>+</literal>/<literal>!</literal>/<literal>!!</literal> may be used together and they can appear in any
ee905de0 359 order. However, only one of <literal>+</literal>, <literal>!</literal>, <literal>!!</literal> may be used at a
165a31c0 360 time. Note that these prefixes are also supported for the other command line settings,
78a263f4 361 i.e. <varname>ExecStartPre=</varname>, <varname>ExecStartPost=</varname>, <varname>ExecReload=</varname>,
165a31c0 362 <varname>ExecStop=</varname> and <varname>ExecStopPost=</varname>.</para>
798d3a52
ZJS
363
364 <para>If more than one command is specified, the commands are
365 invoked sequentially in the order they appear in the unit
366 file. If one of the commands fails (and is not prefixed with
367 <literal>-</literal>), other lines are not executed, and the
368 unit is considered failed.</para>
369
370 <para>Unless <varname>Type=forking</varname> is set, the
371 process started via this command line will be considered the
372 main process of the daemon.</para>
373 </listitem>
374 </varlistentry>
375
376 <varlistentry>
377 <term><varname>ExecStartPre=</varname></term>
378 <term><varname>ExecStartPost=</varname></term>
379 <listitem><para>Additional commands that are executed before
380 or after the command in <varname>ExecStart=</varname>,
381 respectively. Syntax is the same as for
382 <varname>ExecStart=</varname>, except that multiple command
383 lines are allowed and the commands are executed one after the
384 other, serially.</para>
385
386 <para>If any of those commands (not prefixed with
387 <literal>-</literal>) fail, the rest are not executed and the
388 unit is considered failed.</para>
b481de3b 389
12e2683d
RM
390 <para><varname>ExecStart=</varname> commands are only run after
391 all <varname>ExecStartPre=</varname> commands that were not prefixed
392 with a <literal>-</literal> exit successfully.</para>
393
80af263b
LP
394 <para><varname>ExecStartPost=</varname> commands are only run after the commands specified in
395 <varname>ExecStart=</varname> have been invoked successfully, as determined by <varname>Type=</varname>
396 (i.e. the process has been started for <varname>Type=simple</varname> or <varname>Type=idle</varname>, the last
397 <varname>ExecStart=</varname> process exited successfully for <varname>Type=oneshot</varname>, the initial
398 process exited successfully for <varname>Type=forking</varname>, <literal>READY=1</literal> is sent for
399 <varname>Type=notify</varname>, or the <varname>BusName=</varname> has been taken for
400 <varname>Type=dbus</varname>).</para>
12e2683d 401
b481de3b
LP
402 <para>Note that <varname>ExecStartPre=</varname> may not be
403 used to start long-running processes. All processes forked
404 off by processes invoked via <varname>ExecStartPre=</varname> will
405 be killed before the next service process is run.</para>
ce359e98
LP
406
407 <para>Note that if any of the commands specified in <varname>ExecStartPre=</varname>,
408 <varname>ExecStart=</varname>, or <varname>ExecStartPost=</varname> fail (and are not prefixed with
409 <literal>-</literal>, see above) or time out before the service is fully up, execution continues with commands
410 specified in <varname>ExecStopPost=</varname>, the commands in <varname>ExecStop=</varname> are skipped.</para>
798d3a52
ZJS
411 </listitem>
412 </varlistentry>
413
414 <varlistentry>
415 <term><varname>ExecReload=</varname></term>
416 <listitem><para>Commands to execute to trigger a configuration
417 reload in the service. This argument takes multiple command
418 lines, following the same scheme as described for
419 <varname>ExecStart=</varname> above. Use of this setting is
420 optional. Specifier and environment variable substitution is
421 supported here following the same scheme as for
422 <varname>ExecStart=</varname>.</para>
423
424 <para>One additional, special environment variable is set: if
425 known, <varname>$MAINPID</varname> is set to the main process
426 of the daemon, and may be used for command lines like the
427 following:</para>
428
429 <programlisting>/bin/kill -HUP $MAINPID</programlisting>
430
431 <para>Note however that reloading a daemon by sending a signal
432 (as with the example line above) is usually not a good choice,
433 because this is an asynchronous operation and hence not
434 suitable to order reloads of multiple services against each
435 other. It is strongly recommended to set
436 <varname>ExecReload=</varname> to a command that not only
437 triggers a configuration reload of the daemon, but also
438 synchronously waits for it to complete.</para>
439 </listitem>
440 </varlistentry>
441
442 <varlistentry>
443 <term><varname>ExecStop=</varname></term>
444 <listitem><para>Commands to execute to stop the service
445 started via <varname>ExecStart=</varname>. This argument takes
446 multiple command lines, following the same scheme as described
447 for <varname>ExecStart=</varname> above. Use of this setting
448 is optional. After the commands configured in this option are
23656d2b
AY
449 run, it is implied that the service is stopped, and any processes
450 remaining for it are terminated
798d3a52
ZJS
451 according to the <varname>KillMode=</varname> setting (see
452 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
cceb20c7
LP
453 If this option is not specified, the process is terminated by
454 sending the signal specified in <varname>KillSignal=</varname>
455 when service stop is requested. Specifier and environment
456 variable substitution is supported (including
457 <varname>$MAINPID</varname>, see above).</para>
458
99479986
FS
459 <para>Note that it is usually not sufficient to specify a command for this setting that only asks the service
460 to terminate (for example, by queuing some form of termination signal for it), but does not wait for it to do
461 so. Since the remaining processes of the services are killed according to <varname>KillMode=</varname> and
462 <varname>KillSignal=</varname> as described above immediately after the command exited, this may not result in
463 a clean stop. The specified command should hence be a synchronous operation, not an asynchronous one.</para>
ce359e98
LP
464
465 <para>Note that the commands specified in <varname>ExecStop=</varname> are only executed when the service
07ff561c 466 started successfully first. They are not invoked if the service was never started at all, or in case its
ce359e98
LP
467 start-up failed, for example because any of the commands specified in <varname>ExecStart=</varname>,
468 <varname>ExecStartPre=</varname> or <varname>ExecStartPost=</varname> failed (and weren't prefixed with
469 <literal>-</literal>, see above) or timed out. Use <varname>ExecStopPost=</varname> to invoke commands when a
8adf5358
LP
470 service failed to start up correctly and is shut down again. Also note that, service restart requests are
471 implemented as stop operations followed by start operations. This means that <varname>ExecStop=</varname> and
472 <varname>ExecStopPost=</varname> are executed during a service restart operation.</para>
ce359e98
LP
473
474 <para>It is recommended to use this setting for commands that communicate with the service requesting clean
475 termination. When the commands specified with this option are executed it should be assumed that the service is
476 still fully up and is able to react correctly to all commands. For post-mortem clean-up steps use
477 <varname>ExecStopPost=</varname> instead.</para></listitem>
798d3a52
ZJS
478 </varlistentry>
479
480 <varlistentry>
481 <term><varname>ExecStopPost=</varname></term>
ce359e98
LP
482 <listitem><para>Additional commands that are executed after the service is stopped. This includes cases where
483 the commands configured in <varname>ExecStop=</varname> were used, where the service does not have any
484 <varname>ExecStop=</varname> defined, or where the service exited unexpectedly. This argument takes multiple
485 command lines, following the same scheme as described for <varname>ExecStart=</varname>. Use of these settings
486 is optional. Specifier and environment variable substitution is supported. Note that – unlike
487 <varname>ExecStop=</varname> – commands specified with this setting are invoked when a service failed to start
488 up correctly and is shut down again.</para>
489
490 <para>It is recommended to use this setting for clean-up operations that shall be executed even when the
491 service failed to start up correctly. Commands configured with this setting need to be able to operate even if
492 the service failed starting up half-way and left incompletely initialized data around. As the service's
493 processes have been terminated already when the commands specified with this setting are executed they should
136dc4c4
LP
494 not attempt to communicate with them.</para>
495
496 <para>Note that all commands that are configured with this setting are invoked with the result code of the
497 service, as well as the main process' exit code and status, set in the <varname>$SERVICE_RESULT</varname>,
498 <varname>$EXIT_CODE</varname> and <varname>$EXIT_STATUS</varname> environment variables, see
499 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
500 details.</para></listitem>
798d3a52
ZJS
501 </varlistentry>
502
503 <varlistentry>
504 <term><varname>RestartSec=</varname></term>
505 <listitem><para>Configures the time to sleep before restarting
506 a service (as configured with <varname>Restart=</varname>).
507 Takes a unit-less value in seconds, or a time span value such
508 as "5min 20s". Defaults to 100ms.</para></listitem>
509 </varlistentry>
510
511 <varlistentry>
512 <term><varname>TimeoutStartSec=</varname></term>
513 <listitem><para>Configures the time to wait for start-up. If a
514 daemon service does not signal start-up completion within the
515 configured time, the service will be considered failed and
516 will be shut down again. Takes a unit-less value in seconds,
517 or a time span value such as "5min 20s". Pass
2c29d332 518 <literal>infinity</literal> to disable the timeout logic. Defaults to
798d3a52
ZJS
519 <varname>DefaultTimeoutStartSec=</varname> from the manager
520 configuration file, except when
521 <varname>Type=oneshot</varname> is used, in which case the
522 timeout is disabled by default (see
523 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
a327431b
DB
524 </para>
525
526 <para>If a service of <varname>Type=notify</varname> sends <literal>EXTEND_TIMEOUT_USEC=…</literal>, this may cause
527 the start time to be extended beyond <varname>TimeoutStartSec=</varname>. The first receipt of this message
528 must occur before <varname>TimeoutStartSec=</varname> is exceeded, and once the start time has exended beyond
529 <varname>TimeoutStartSec=</varname>, the service manager will allow the service to continue to start, provided
530 the service repeats <literal>EXTEND_TIMEOUT_USEC=…</literal> within the interval specified until the service
531 startup status is finished by <literal>READY=1</literal>. (see
532 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>).
798d3a52
ZJS
533 </para></listitem>
534 </varlistentry>
535
536 <varlistentry>
537 <term><varname>TimeoutStopSec=</varname></term>
538 <listitem><para>Configures the time to wait for stop. If a
539 service is asked to stop, but does not terminate in the
540 specified time, it will be terminated forcibly via
541 <constant>SIGTERM</constant>, and after another timeout of
542 equal duration with <constant>SIGKILL</constant> (see
543 <varname>KillMode=</varname> in
544 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
545 Takes a unit-less value in seconds, or a time span value such
2c29d332 546 as "5min 20s". Pass <literal>infinity</literal> to disable the
798d3a52
ZJS
547 timeout logic. Defaults to
548 <varname>DefaultTimeoutStopSec=</varname> from the manager
549 configuration file (see
550 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
a327431b
DB
551 </para>
552
553 <para>If a service of <varname>Type=notify</varname> sends <literal>EXTEND_TIMEOUT_USEC=…</literal>, this may cause
554 the stop time to be extended beyond <varname>TimeoutStopSec=</varname>. The first receipt of this message
555 must occur before <varname>TimeoutStopSec=</varname> is exceeded, and once the stop time has exended beyond
556 <varname>TimeoutStopSec=</varname>, the service manager will allow the service to continue to stop, provided
557 the service repeats <literal>EXTEND_TIMEOUT_USEC=…</literal> within the interval specified, or terminates itself
558 (see <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>).
798d3a52
ZJS
559 </para></listitem>
560 </varlistentry>
561
562 <varlistentry>
563 <term><varname>TimeoutSec=</varname></term>
564 <listitem><para>A shorthand for configuring both
565 <varname>TimeoutStartSec=</varname> and
566 <varname>TimeoutStopSec=</varname> to the specified value.
567 </para></listitem>
568 </varlistentry>
569
2c29d332
LP
570 <varlistentry>
571 <term><varname>RuntimeMaxSec=</varname></term>
572
573 <listitem><para>Configures a maximum time for the service to run. If this is used and the service has been
574 active for longer than the specified time it is terminated and put into a failure state. Note that this setting
575 does not have any effect on <varname>Type=oneshot</varname> services, as they terminate immediately after
576 activation completed. Pass <literal>infinity</literal> (the default) to configure no runtime
a327431b
DB
577 limit.</para>
578
579 <para>If a service of <varname>Type=notify</varname> sends <literal>EXTEND_TIMEOUT_USEC=…</literal>, this may cause
580 the runtime to be extended beyond <varname>RuntimeMaxSec=</varname>. The first receipt of this message
581 must occur before <varname>RuntimeMaxSec=</varname> is exceeded, and once the runtime has exended beyond
582 <varname>RuntimeMaxSec=</varname>, the service manager will allow the service to continue to run, provided
583 the service repeats <literal>EXTEND_TIMEOUT_USEC=…</literal> within the interval specified until the service
90bc77af 584 shutdown is achieved by <literal>STOPPING=1</literal> (or termination). (see
a327431b
DB
585 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>).
586 </para></listitem>
2c29d332
LP
587 </varlistentry>
588
798d3a52
ZJS
589 <varlistentry>
590 <term><varname>WatchdogSec=</varname></term>
591 <listitem><para>Configures the watchdog timeout for a service.
592 The watchdog is activated when the start-up is completed. The
593 service must call
594 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>
595 regularly with <literal>WATCHDOG=1</literal> (i.e. the
596 "keep-alive ping"). If the time between two such calls is
597 larger than the configured time, then the service is placed in
598 a failed state and it will be terminated with
22065311 599 <constant>SIGABRT</constant>. By setting
a0533c6d
EV
600 <varname>Restart=</varname> to <option>on-failure</option>,
601 <option>on-watchdog</option>, <option>on-abnormal</option> or
798d3a52
ZJS
602 <option>always</option>, the service will be automatically
603 restarted. The time configured here will be passed to the
604 executed service process in the
605 <varname>WATCHDOG_USEC=</varname> environment variable. This
606 allows daemons to automatically enable the keep-alive pinging
607 logic if watchdog support is enabled for the service. If this
608 option is used, <varname>NotifyAccess=</varname> (see below)
609 should be set to open access to the notification socket
610 provided by systemd. If <varname>NotifyAccess=</varname> is
611 not set, it will be implicitly set to <option>main</option>.
582f2fcb
EV
612 Defaults to 0, which disables this feature. The service can
613 check whether the service manager expects watchdog keep-alive
614 notifications. See
615 <citerefentry><refentrytitle>sd_watchdog_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>
a0533c6d
EV
616 for details.
617 <citerefentry><refentrytitle>sd_event_set_watchdog</refentrytitle><manvolnum>3</manvolnum></citerefentry>
618 may be used to enable automatic watchdog notification support.
582f2fcb 619 </para></listitem>
798d3a52
ZJS
620 </varlistentry>
621
622 <varlistentry>
623 <term><varname>Restart=</varname></term>
624 <listitem><para>Configures whether the service shall be
625 restarted when the service process exits, is killed, or a
626 timeout is reached. The service process may be the main
627 service process, but it may also be one of the processes
628 specified with <varname>ExecStartPre=</varname>,
629 <varname>ExecStartPost=</varname>,
630 <varname>ExecStop=</varname>,
631 <varname>ExecStopPost=</varname>, or
632 <varname>ExecReload=</varname>. When the death of the process
633 is a result of systemd operation (e.g. service stop or
634 restart), the service will not be restarted. Timeouts include
635 missing the watchdog "keep-alive ping" deadline and a service
636 start, reload, and stop operation timeouts.</para>
637
638 <para>Takes one of
639 <option>no</option>,
640 <option>on-success</option>,
641 <option>on-failure</option>,
642 <option>on-abnormal</option>,
643 <option>on-watchdog</option>,
644 <option>on-abort</option>, or
645 <option>always</option>.
646 If set to <option>no</option> (the default), the service will
647 not be restarted. If set to <option>on-success</option>, it
648 will be restarted only when the service process exits cleanly.
649 In this context, a clean exit means an exit code of 0, or one
650 of the signals
651 <constant>SIGHUP</constant>,
652 <constant>SIGINT</constant>,
653 <constant>SIGTERM</constant> or
654 <constant>SIGPIPE</constant>, and
655 additionally, exit statuses and signals specified in
656 <varname>SuccessExitStatus=</varname>. If set to
657 <option>on-failure</option>, the service will be restarted
658 when the process exits with a non-zero exit code, is
659 terminated by a signal (including on core dump, but excluding
ff9b60f3 660 the aforementioned four signals), when an operation (such as
798d3a52
ZJS
661 service reload) times out, and when the configured watchdog
662 timeout is triggered. If set to <option>on-abnormal</option>,
663 the service will be restarted when the process is terminated
664 by a signal (including on core dump, excluding the
665 aforementioned four signals), when an operation times out, or
666 when the watchdog timeout is triggered. If set to
667 <option>on-abort</option>, the service will be restarted only
668 if the service process exits due to an uncaught signal not
669 specified as a clean exit status. If set to
670 <option>on-watchdog</option>, the service will be restarted
671 only if the watchdog timeout for the service expires. If set
672 to <option>always</option>, the service will be restarted
673 regardless of whether it exited cleanly or not, got terminated
674 abnormally by a signal, or hit a timeout.</para>
675
676 <table>
677 <title>Exit causes and the effect of the <varname>Restart=</varname> settings on them</title>
678
679 <tgroup cols='2'>
680 <colspec colname='path' />
681 <colspec colname='expl' />
682 <thead>
683 <row>
684 <entry>Restart settings/Exit causes</entry>
685 <entry><option>no</option></entry>
686 <entry><option>always</option></entry>
687 <entry><option>on-success</option></entry>
688 <entry><option>on-failure</option></entry>
689 <entry><option>on-abnormal</option></entry>
690 <entry><option>on-abort</option></entry>
691 <entry><option>on-watchdog</option></entry>
692 </row>
693 </thead>
694 <tbody>
695 <row>
696 <entry>Clean exit code or signal</entry>
697 <entry/>
698 <entry>X</entry>
699 <entry>X</entry>
700 <entry/>
701 <entry/>
702 <entry/>
703 <entry/>
704 </row>
705 <row>
706 <entry>Unclean exit code</entry>
707 <entry/>
708 <entry>X</entry>
709 <entry/>
710 <entry>X</entry>
711 <entry/>
712 <entry/>
713 <entry/>
714 </row>
715 <row>
716 <entry>Unclean signal</entry>
717 <entry/>
718 <entry>X</entry>
719 <entry/>
720 <entry>X</entry>
721 <entry>X</entry>
722 <entry>X</entry>
723 <entry/>
724 </row>
725 <row>
726 <entry>Timeout</entry>
727 <entry/>
728 <entry>X</entry>
729 <entry/>
730 <entry>X</entry>
731 <entry>X</entry>
732 <entry/>
733 <entry/>
734 </row>
735 <row>
736 <entry>Watchdog</entry>
737 <entry/>
738 <entry>X</entry>
739 <entry/>
740 <entry>X</entry>
741 <entry>X</entry>
742 <entry/>
743 <entry>X</entry>
744 </row>
745 </tbody>
746 </tgroup>
747 </table>
748
b938cb90 749 <para>As exceptions to the setting above, the service will not
798d3a52 750 be restarted if the exit code or signal is specified in
09b69d68
TW
751 <varname>RestartPreventExitStatus=</varname> (see below) or
752 the service is stopped with <command>systemctl stop</command>
753 or an equivalent operation. Also, the services will always be
754 restarted if the exit code or signal is specified in
798d3a52
ZJS
755 <varname>RestartForceExitStatus=</varname> (see below).</para>
756
6d249476
LW
757 <para>Note that service restart is subject to unit start rate
758 limiting configured with <varname>StartLimitIntervalSec=</varname>
759 and <varname>StartLimitBurst=</varname>, see
760 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
bd2538b5
KBM
761 for details. A restarted service enters the failed state only
762 after the start limits are reached.</para>
6d249476 763
798d3a52
ZJS
764 <para>Setting this to <option>on-failure</option> is the
765 recommended choice for long-running services, in order to
766 increase reliability by attempting automatic recovery from
767 errors. For services that shall be able to terminate on their
768 own choice (and avoid immediate restarting),
769 <option>on-abnormal</option> is an alternative choice.</para>
770 </listitem>
771 </varlistentry>
772
773 <varlistentry>
774 <term><varname>SuccessExitStatus=</varname></term>
b938cb90
JE
775 <listitem><para>Takes a list of exit status definitions that,
776 when returned by the main service process, will be considered
798d3a52
ZJS
777 successful termination, in addition to the normal successful
778 exit code 0 and the signals <constant>SIGHUP</constant>,
779 <constant>SIGINT</constant>, <constant>SIGTERM</constant>, and
780 <constant>SIGPIPE</constant>. Exit status definitions can
781 either be numeric exit codes or termination signal names,
782 separated by spaces. For example:
dc83f27a
LP
783
784 <programlisting>SuccessExitStatus=1 2 8 SIGKILL</programlisting>
785
786 ensures that exit codes 1, 2, 8 and
798d3a52
ZJS
787 the termination signal <constant>SIGKILL</constant> are
788 considered clean service terminations.
789 </para>
790
798d3a52
ZJS
791 <para>This option may appear more than once, in which case the
792 list of successful exit statuses is merged. If the empty
793 string is assigned to this option, the list is reset, all
794 prior assignments of this option will have no
795 effect.</para></listitem>
796 </varlistentry>
797
798 <varlistentry>
799 <term><varname>RestartPreventExitStatus=</varname></term>
b938cb90
JE
800 <listitem><para>Takes a list of exit status definitions that,
801 when returned by the main service process, will prevent
798d3a52
ZJS
802 automatic service restarts, regardless of the restart setting
803 configured with <varname>Restart=</varname>. Exit status
804 definitions can either be numeric exit codes or termination
805 signal names, and are separated by spaces. Defaults to the
806 empty list, so that, by default, no exit status is excluded
807 from the configured restart logic. For example:
dc83f27a
LP
808
809 <programlisting>RestartPreventExitStatus=1 6 SIGABRT</programlisting>
810
811 ensures that exit codes 1 and 6 and the termination signal
812 <constant>SIGABRT</constant> will not result in automatic
813 service restarting. This option may appear more than once, in
814 which case the list of restart-preventing statuses is
815 merged. If the empty string is assigned to this option, the
816 list is reset and all prior assignments of this option will
817 have no effect.</para></listitem>
798d3a52
ZJS
818 </varlistentry>
819
820 <varlistentry>
821 <term><varname>RestartForceExitStatus=</varname></term>
b938cb90
JE
822 <listitem><para>Takes a list of exit status definitions that,
823 when returned by the main service process, will force automatic
798d3a52
ZJS
824 service restarts, regardless of the restart setting configured
825 with <varname>Restart=</varname>. The argument format is
826 similar to
827 <varname>RestartPreventExitStatus=</varname>.</para></listitem>
828 </varlistentry>
829
830 <varlistentry>
831 <term><varname>PermissionsStartOnly=</varname></term>
832 <listitem><para>Takes a boolean argument. If true, the
833 permission-related execution options, as configured with
834 <varname>User=</varname> and similar options (see
835 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
836 for more information), are only applied to the process started
837 with
838 <varname>ExecStart=</varname>, and not to the various other
839 <varname>ExecStartPre=</varname>,
840 <varname>ExecStartPost=</varname>,
841 <varname>ExecReload=</varname>,
842 <varname>ExecStop=</varname>, and
843 <varname>ExecStopPost=</varname>
844 commands. If false, the setting is applied to all configured
845 commands the same way. Defaults to false.</para></listitem>
846 </varlistentry>
847
848 <varlistentry>
849 <term><varname>RootDirectoryStartOnly=</varname></term>
850 <listitem><para>Takes a boolean argument. If true, the root
851 directory, as configured with the
852 <varname>RootDirectory=</varname> option (see
853 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
854 for more information), is only applied to the process started
855 with <varname>ExecStart=</varname>, and not to the various
856 other <varname>ExecStartPre=</varname>,
857 <varname>ExecStartPost=</varname>,
858 <varname>ExecReload=</varname>, <varname>ExecStop=</varname>,
859 and <varname>ExecStopPost=</varname> commands. If false, the
860 setting is applied to all configured commands the same way.
861 Defaults to false.</para></listitem>
862 </varlistentry>
863
864 <varlistentry>
865 <term><varname>NonBlocking=</varname></term>
9b141911
FB
866 <listitem><para>Set the <constant>O_NONBLOCK</constant> flag for all file descriptors passed via socket-based
867 activation. If true, all file descriptors >= 3 (i.e. all except stdin, stdout, stderr), excluding those passed
868 in via the file descriptor storage logic (see <varname>FileDescriptorStoreMax=</varname> for details), will
869 have the <constant>O_NONBLOCK</constant> flag set and hence are in non-blocking mode. This option is only
870 useful in conjunction with a socket unit, as described in
871 <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry> and has no
872 effect on file descriptors which were previously saved in the file-descriptor store for example. Defaults to
873 false.</para></listitem>
798d3a52
ZJS
874 </varlistentry>
875
876 <varlistentry>
877 <term><varname>NotifyAccess=</varname></term>
b3bb6476
LP
878 <listitem><para>Controls access to the service status notification socket, as accessible via the
879 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry> call. Takes one
880 of <option>none</option> (the default), <option>main</option>, <option>exec</option> or
881 <option>all</option>. If <option>none</option>, no daemon status updates are accepted from the service
882 processes, all status update messages are ignored. If <option>main</option>, only service updates sent from the
883 main process of the service are accepted. If <option>exec</option>, only service updates sent from any of the
884 main or control processes originating from one of the <varname>Exec*=</varname> commands are accepted. If
885 <option>all</option>, all services updates from all members of the service's control group are accepted. This
886 option should be set to open access to the notification socket when using <varname>Type=notify</varname> or
887 <varname>WatchdogSec=</varname> (see above). If those options are used but <varname>NotifyAccess=</varname> is
888 not configured, it will be implicitly set to <option>main</option>.</para>
889
890 <para>Note that <function>sd_notify()</function> notifications may be attributed to units correctly only if
891 either the sending process is still around at the time PID 1 processes the message, or if the sending process
892 is explicitly runtime-tracked by the service manager. The latter is the case if the service manager originally
893 forked off the process, i.e. on all processes that match <option>main</option> or
894 <option>exec</option>. Conversely, if an auxiliary process of the unit sends an
895 <function>sd_notify()</function> message and immediately exits, the service manager might not be able to
896 properly attribute the message to the unit, and thus will ignore it, even if
897 <varname>NotifyAccess=</varname><option>all</option> is set for it.</para></listitem>
798d3a52
ZJS
898 </varlistentry>
899
900 <varlistentry>
901 <term><varname>Sockets=</varname></term>
902 <listitem><para>Specifies the name of the socket units this
903 service shall inherit socket file descriptors from when the
b938cb90
JE
904 service is started. Normally, it should not be necessary to use
905 this setting, as all socket file descriptors whose unit shares
798d3a52
ZJS
906 the same name as the service (subject to the different unit
907 name suffix of course) are passed to the spawned
908 process.</para>
909
910 <para>Note that the same socket file descriptors may be passed
911 to multiple processes simultaneously. Also note that a
912 different service may be activated on incoming socket traffic
913 than the one which is ultimately configured to inherit the
b938cb90 914 socket file descriptors. Or, in other words: the
798d3a52
ZJS
915 <varname>Service=</varname> setting of
916 <filename>.socket</filename> units does not have to match the
917 inverse of the <varname>Sockets=</varname> setting of the
918 <filename>.service</filename> it refers to.</para>
919
920 <para>This option may appear more than once, in which case the
921 list of socket units is merged. If the empty string is
922 assigned to this option, the list of sockets is reset, and all
923 prior uses of this setting will have no
924 effect.</para></listitem>
925 </varlistentry>
926
798d3a52
ZJS
927 <varlistentry>
928 <term><varname>FileDescriptorStoreMax=</varname></term>
3ceb72e5 929 <listitem><para>Configure how many file descriptors may be stored in the service manager for the service using
798d3a52 930 <citerefentry><refentrytitle>sd_pid_notify_with_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>'s
3ceb72e5
LP
931 <literal>FDSTORE=1</literal> messages. This is useful for implementing services that can restart after an
932 explicit request or a crash without losing state. Any open sockets and other file descriptors which should not
933 be closed during the restart may be stored this way. Application state can either be serialized to a file in
934 <filename>/run</filename>, or better, stored in a
935 <citerefentry><refentrytitle>memfd_create</refentrytitle><manvolnum>2</manvolnum></citerefentry> memory file
936 descriptor. Defaults to 0, i.e. no file descriptors may be stored in the service manager. All file descriptors
937 passed to the service manager from a specific service are passed back to the service's main process on the next
938 service restart. Any file descriptors passed to the service manager are automatically closed when
939 <constant>POLLHUP</constant> or <constant>POLLERR</constant> is seen on them, or when the service is fully
4330dc03
AJ
940 stopped and no job is queued or being executed for it. If this option is used, <varname>NotifyAccess=</varname>
941 (see above) should be set to open access to the notification socket provided by systemd. If
942 <varname>NotifyAccess=</varname> is not set, it will be implicitly set to
943 <option>main</option>.</para></listitem>
798d3a52
ZJS
944 </varlistentry>
945
8c7c9839
PS
946 <varlistentry>
947 <term><varname>USBFunctionDescriptors=</varname></term>
3d314510
LP
948 <listitem><para>Configure the location of a file containing
949 <ulink
950 url="https://www.kernel.org/doc/Documentation/usb/functionfs.txt">USB
951 FunctionFS</ulink> descriptors, for implementation of USB
a8eaaee7 952 gadget functions. This is used only in conjunction with a
3d314510 953 socket unit with <varname>ListenUSBFunction=</varname>
a8eaaee7 954 configured. The contents of this file are written to the
3d314510
LP
955 <filename>ep0</filename> file after it is
956 opened.</para></listitem>
8c7c9839
PS
957 </varlistentry>
958
959 <varlistentry>
960 <term><varname>USBFunctionStrings=</varname></term>
3d314510
LP
961 <listitem><para>Configure the location of a file containing
962 USB FunctionFS strings. Behavior is similar to
963 <varname>USBFunctionDescriptors=</varname>
964 above.</para></listitem>
8c7c9839
PS
965 </varlistentry>
966
798d3a52
ZJS
967 </variablelist>
968
969 <para>Check
970 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
971 and
972 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>
973 for more settings.</para>
974
975 </refsect1>
976
977 <refsect1>
978 <title>Command lines</title>
979
980 <para>This section describes command line parsing and
ff9b60f3 981 variable and specifier substitutions for
798d3a52
ZJS
982 <varname>ExecStart=</varname>,
983 <varname>ExecStartPre=</varname>,
984 <varname>ExecStartPost=</varname>,
985 <varname>ExecReload=</varname>,
986 <varname>ExecStop=</varname>, and
987 <varname>ExecStopPost=</varname> options.</para>
988
989 <para>Multiple command lines may be concatenated in a single
990 directive by separating them with semicolons (these semicolons
991 must be passed as separate words). Lone semicolons may be escaped
992 as <literal>\;</literal>.</para>
993
330785f5 994 <para>Each command line is split on whitespace, with the first item being the command to
1eecafb8 995 execute, and the subsequent items being the arguments. Double quotes ("…") and single quotes
fa0c9e63
ZJS
996 ('…') may be used to wrap a whole item (the opening quote may appear only at the beginning or
997 after whitespace that is not quoted, and the closing quote must be followed by whitespace or the
998 end of line), in which case everything until the next matching quote becomes part of the same
999 argument. Quotes themselves are removed. C-style escapes are also supported. The table below
1000 contains the list of known escape patterns. Only escape patterns which match the syntax in the
1001 table are allowed; other patterns may be added in the future and unknown patterns will result in
1002 a warning. In particular, any backslashes should be doubled. Finally, a trailing backslash
1003 (<literal>\</literal>) may be used to merge lines.</para>
798d3a52 1004
0e3f51cf
ZJS
1005 <para>This syntax is inspired by shell syntax, but only the meta-characters and expansions
1006 described in the following paragraphs are understood, and the expansion of variables is
1007 different. Specifically, redirection using
798d3a52
ZJS
1008 <literal>&lt;</literal>,
1009 <literal>&lt;&lt;</literal>,
1010 <literal>&gt;</literal>, and
1011 <literal>&gt;&gt;</literal>, pipes using
1012 <literal>|</literal>, running programs in the background using
1013 <literal>&amp;</literal>, and <emphasis>other elements of shell
1014 syntax are not supported</emphasis>.</para>
1015
5008da1e 1016 <para>The command to execute may contain spaces, but control characters are not allowed.</para>
798d3a52 1017
5008da1e 1018 <para>The command line accepts <literal>%</literal> specifiers as described in
2d06ddb7 1019 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
798d3a52
ZJS
1020
1021 <para>Basic environment variable substitution is supported. Use
1022 <literal>${FOO}</literal> as part of a word, or as a word of its
1023 own, on the command line, in which case it will be replaced by the
1024 value of the environment variable including all whitespace it
1025 contains, resulting in a single argument. Use
1026 <literal>$FOO</literal> as a separate word on the command line, in
1027 which case it will be replaced by the value of the environment
b938cb90 1028 variable split at whitespace, resulting in zero or more arguments.
3faf145d 1029 For this type of expansion, quotes are respected when splitting
798d3a52
ZJS
1030 into words, and afterwards removed.</para>
1031
5008da1e
ZJS
1032 <para>If the command is not a full (absolute) path, it will be resolved to a full path using a
1033 fixed search path determinted at compilation time. Searched directories include
1034 <filename>/usr/local/bin/</filename>, <filename>/usr/bin/</filename>, <filename>/bin/</filename>
1035 on systems using split <filename>/usr/bin/</filename> and <filename>/bin/</filename>
1036 directories, and their <filename>sbin/</filename> counterparts on systems using split
1037 <filename>bin/</filename> and <filename>sbin/</filename>. It is thus safe to use just the
1038 executable name in case of executables located in any of the "standard" directories, and an
1039 absolute path must be used in other cases. Using an absolute path is recommended to avoid
e12d446b
ZJS
1040 ambiguity. Hint: this search path may be queried using
1041 <command>systemd-path search-binaries-default</command>.</para>
5008da1e 1042
798d3a52
ZJS
1043 <para>Example:</para>
1044
1045 <programlisting>Environment="ONE=one" 'TWO=two two'
5008da1e 1046ExecStart=echo $ONE $TWO ${TWO}</programlisting>
5d9a2698 1047
798d3a52
ZJS
1048 <para>This will execute <command>/bin/echo</command> with four
1049 arguments: <literal>one</literal>, <literal>two</literal>,
1050 <literal>two</literal>, and <literal>two two</literal>.</para>
5d9a2698 1051
798d3a52
ZJS
1052 <para>Example:</para>
1053 <programlisting>Environment=ONE='one' "TWO='two two' too" THREE=
5d9a2698
ZJS
1054ExecStart=/bin/echo ${ONE} ${TWO} ${THREE}
1055ExecStart=/bin/echo $ONE $TWO $THREE</programlisting>
5008da1e 1056 <para>This results in <filename>/bin/echo</filename> being
798d3a52
ZJS
1057 called twice, the first time with arguments
1058 <literal>'one'</literal>,
1059 <literal>'two two' too</literal>, <literal></literal>,
1060 and the second time with arguments
1061 <literal>one</literal>, <literal>two two</literal>,
1062 <literal>too</literal>.
1063 </para>
1064
1065 <para>To pass a literal dollar sign, use <literal>$$</literal>.
1066 Variables whose value is not known at expansion time are treated
1067 as empty strings. Note that the first argument (i.e. the program
1068 to execute) may not be a variable.</para>
1069
1070 <para>Variables to be used in this fashion may be defined through
1071 <varname>Environment=</varname> and
1072 <varname>EnvironmentFile=</varname>. In addition, variables listed
1073 in the section "Environment variables in spawned processes" in
1074 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1075 which are considered "static configuration", may be used (this
1076 includes e.g. <varname>$USER</varname>, but not
1077 <varname>$TERM</varname>).</para>
1078
1079 <para>Note that shell command lines are not directly supported. If
1080 shell command lines are to be used, they need to be passed
1081 explicitly to a shell implementation of some kind. Example:</para>
5008da1e 1082 <programlisting>ExecStart=sh -c 'dmesg | tac'</programlisting>
798d3a52
ZJS
1083
1084 <para>Example:</para>
1085
5008da1e 1086 <programlisting>ExecStart=echo one ; echo "two two"</programlisting>
798d3a52 1087
5008da1e 1088 <para>This will execute <command>echo</command> two times,
798d3a52
ZJS
1089 each time with one argument: <literal>one</literal> and
1090 <literal>two two</literal>, respectively. Because two commands are
1091 specified, <varname>Type=oneshot</varname> must be used.</para>
1092
1093 <para>Example:</para>
1094
5008da1e
ZJS
1095 <programlisting>ExecStart=echo / &gt;/dev/null &amp; \; \
1096ls</programlisting>
30d88d54 1097
5008da1e 1098 <para>This will execute <command>echo</command>
798d3a52
ZJS
1099 with five arguments: <literal>/</literal>,
1100 <literal>&gt;/dev/null</literal>,
1101 <literal>&amp;</literal>, <literal>;</literal>, and
5008da1e 1102 <literal>ls</literal>.</para>
798d3a52
ZJS
1103
1104 <table>
1105 <title>C escapes supported in command lines and environment variables</title>
1106 <tgroup cols='2'>
1107 <colspec colname='escape' />
1108 <colspec colname='meaning' />
1109 <thead>
1110 <row>
1111 <entry>Literal</entry>
1112 <entry>Actual value</entry>
1113 </row>
1114 </thead>
1115 <tbody>
1116 <row>
1117 <entry><literal>\a</literal></entry>
1118 <entry>bell</entry>
1119 </row>
1120 <row>
1121 <entry><literal>\b</literal></entry>
1122 <entry>backspace</entry>
1123 </row>
1124 <row>
1125 <entry><literal>\f</literal></entry>
1126 <entry>form feed</entry>
1127 </row>
1128 <row>
1129 <entry><literal>\n</literal></entry>
1130 <entry>newline</entry>
1131 </row>
1132 <row>
1133 <entry><literal>\r</literal></entry>
1134 <entry>carriage return</entry>
1135 </row>
1136 <row>
1137 <entry><literal>\t</literal></entry>
1138 <entry>tab</entry>
1139 </row>
1140 <row>
1141 <entry><literal>\v</literal></entry>
1142 <entry>vertical tab</entry>
1143 </row>
1144 <row>
1145 <entry><literal>\\</literal></entry>
1146 <entry>backslash</entry>
1147 </row>
1148 <row>
1149 <entry><literal>\"</literal></entry>
1150 <entry>double quotation mark</entry>
1151 </row>
1152 <row>
1153 <entry><literal>\'</literal></entry>
1154 <entry>single quotation mark</entry>
1155 </row>
1156 <row>
1157 <entry><literal>\s</literal></entry>
1158 <entry>space</entry>
1159 </row>
1160 <row>
1161 <entry><literal>\x<replaceable>xx</replaceable></literal></entry>
1162 <entry>character number <replaceable>xx</replaceable> in hexadecimal encoding</entry>
1163 </row>
1164 <row>
1165 <entry><literal>\<replaceable>nnn</replaceable></literal></entry>
1166 <entry>character number <replaceable>nnn</replaceable> in octal encoding</entry>
1167 </row>
1168 </tbody>
1169 </tgroup>
1170 </table>
1171 </refsect1>
1172
1173 <refsect1>
1174 <title>Examples</title>
1175
1176 <example>
1177 <title>Simple service</title>
1178
1179 <para>The following unit file creates a service that will
1180 execute <filename>/usr/sbin/foo-daemon</filename>. Since no
1181 <varname>Type=</varname> is specified, the default
1182 <varname>Type=</varname><option>simple</option> will be assumed.
1183 systemd will assume the unit to be started immediately after the
1184 program has begun executing.</para>
1185
1186 <programlisting>[Unit]
d44efb62
CS
1187Description=Foo
1188
1189[Service]
1190ExecStart=/usr/sbin/foo-daemon
1191
1192[Install]
1193WantedBy=multi-user.target</programlisting>
1194
798d3a52
ZJS
1195 <para>Note that systemd assumes here that the process started by
1196 systemd will continue running until the service terminates. If
1197 the program daemonizes itself (i.e. forks), please use
1198 <varname>Type=</varname><option>forking</option> instead.</para>
1199
1200 <para>Since no <varname>ExecStop=</varname> was specified,
1201 systemd will send SIGTERM to all processes started from this
1202 service, and after a timeout also SIGKILL. This behavior can be
1203 modified, see
1204 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>
1205 for details.</para>
1206
1207 <para>Note that this unit type does not include any type of
1208 notification when a service has completed initialization. For
1209 this, you should use other unit types, such as
1210 <varname>Type=</varname><option>notify</option> if the service
1211 understands systemd's notification protocol,
1212 <varname>Type=</varname><option>forking</option> if the service
1213 can background itself or
1214 <varname>Type=</varname><option>dbus</option> if the unit
1215 acquires a DBus name once initialization is complete. See
1216 below.</para>
1217 </example>
1218
1219 <example>
1220 <title>Oneshot service</title>
1221
b938cb90 1222 <para>Sometimes, units should just execute an action without
798d3a52
ZJS
1223 keeping active processes, such as a filesystem check or a
1224 cleanup action on boot. For this,
1225 <varname>Type=</varname><option>oneshot</option> exists. Units
1226 of this type will wait until the process specified terminates
1227 and then fall back to being inactive. The following unit will
ff9b60f3 1228 perform a cleanup action:</para>
798d3a52
ZJS
1229
1230 <programlisting>[Unit]
d44efb62
CS
1231Description=Cleanup old Foo data
1232
1233[Service]
1234Type=oneshot
1235ExecStart=/usr/sbin/foo-cleanup
1236
1237[Install]
1238WantedBy=multi-user.target</programlisting>
1239
798d3a52 1240 <para>Note that systemd will consider the unit to be in the
b938cb90 1241 state "starting" until the program has terminated, so ordered
798d3a52 1242 dependencies will wait for the program to finish before starting
b938cb90
JE
1243 themselves. The unit will revert to the "inactive" state after
1244 the execution is done, never reaching the "active" state. That
798d3a52
ZJS
1245 means another request to start the unit will perform the action
1246 again.</para>
1247
1248 <para><varname>Type=</varname><option>oneshot</option> are the
1249 only service units that may have more than one
1250 <varname>ExecStart=</varname> specified. They will be executed
1251 in order until either they are all successful or one of them
1252 fails.</para>
1253 </example>
1254
1255 <example>
1256 <title>Stoppable oneshot service</title>
1257
1258 <para>Similarly to the oneshot services, there are sometimes
1259 units that need to execute a program to set up something and
1260 then execute another to shut it down, but no process remains
b938cb90 1261 active while they are considered "started". Network
798d3a52 1262 configuration can sometimes fall into this category. Another use
a8eaaee7 1263 case is if a oneshot service shall not be executed each time
798d3a52
ZJS
1264 when they are pulled in as a dependency, but only the first
1265 time.</para>
1266
1267 <para>For this, systemd knows the setting
1268 <varname>RemainAfterExit=</varname><option>yes</option>, which
1269 causes systemd to consider the unit to be active if the start
1270 action exited successfully. This directive can be used with all
1271 types, but is most useful with
1272 <varname>Type=</varname><option>oneshot</option> and
1273 <varname>Type=</varname><option>simple</option>. With
b938cb90 1274 <varname>Type=</varname><option>oneshot</option>, systemd waits
798d3a52
ZJS
1275 until the start action has completed before it considers the
1276 unit to be active, so dependencies start only after the start
1277 action has succeeded. With
b938cb90 1278 <varname>Type=</varname><option>simple</option>, dependencies
798d3a52
ZJS
1279 will start immediately after the start action has been
1280 dispatched. The following unit provides an example for a simple
1281 static firewall.</para>
1282
1283 <programlisting>[Unit]
d44efb62
CS
1284Description=Simple firewall
1285
1286[Service]
1287Type=oneshot
1288RemainAfterExit=yes
1289ExecStart=/usr/local/sbin/simple-firewall-start
1290ExecStop=/usr/local/sbin/simple-firewall-stop
1291
1292[Install]
1293WantedBy=multi-user.target</programlisting>
1294
798d3a52
ZJS
1295 <para>Since the unit is considered to be running after the start
1296 action has exited, invoking <command>systemctl start</command>
1297 on that unit again will cause no action to be taken.</para>
1298 </example>
1299
1300 <example>
1301 <title>Traditional forking services</title>
1302
1303 <para>Many traditional daemons/services background (i.e. fork,
1304 daemonize) themselves when starting. Set
1305 <varname>Type=</varname><option>forking</option> in the
1306 service's unit file to support this mode of operation. systemd
1307 will consider the service to be in the process of initialization
1308 while the original program is still running. Once it exits
1309 successfully and at least a process remains (and
1310 <varname>RemainAfterExit=</varname><option>no</option>), the
1311 service is considered started.</para>
1312
b938cb90 1313 <para>Often, a traditional daemon only consists of one process.
798d3a52
ZJS
1314 Therefore, if only one process is left after the original
1315 process terminates, systemd will consider that process the main
1316 process of the service. In that case, the
1317 <varname>$MAINPID</varname> variable will be available in
1318 <varname>ExecReload=</varname>, <varname>ExecStop=</varname>,
1319 etc.</para>
1320
1321 <para>In case more than one process remains, systemd will be
1322 unable to determine the main process, so it will not assume
1323 there is one. In that case, <varname>$MAINPID</varname> will not
1324 expand to anything. However, if the process decides to write a
1325 traditional PID file, systemd will be able to read the main PID
1326 from there. Please set <varname>PIDFile=</varname> accordingly.
1327 Note that the daemon should write that file before finishing
b938cb90 1328 with its initialization. Otherwise, systemd might try to read the
798d3a52
ZJS
1329 file before it exists.</para>
1330
1331 <para>The following example shows a simple daemon that forks and
1332 just starts one process in the background:</para>
1333
1334 <programlisting>[Unit]
d44efb62
CS
1335Description=Some simple daemon
1336
1337[Service]
1338Type=forking
1339ExecStart=/usr/sbin/my-simple-daemon -d
1340
1341[Install]
1342WantedBy=multi-user.target</programlisting>
1343
798d3a52
ZJS
1344 <para>Please see
1345 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>
1346 for details on how you can influence the way systemd terminates
1347 the service.</para>
1348 </example>
1349
1350 <example>
1351 <title>DBus services</title>
1352
1353 <para>For services that acquire a name on the DBus system bus,
1354 use <varname>Type=</varname><option>dbus</option> and set
1355 <varname>BusName=</varname> accordingly. The service should not
1356 fork (daemonize). systemd will consider the service to be
1357 initialized once the name has been acquired on the system bus.
1358 The following example shows a typical DBus service:</para>
1359
1360 <programlisting>[Unit]
d44efb62
CS
1361Description=Simple DBus service
1362
1363[Service]
1364Type=dbus
1365BusName=org.example.simple-dbus-service
1366ExecStart=/usr/sbin/simple-dbus-service
1367
1368[Install]
1369WantedBy=multi-user.target</programlisting>
1370
7ca41557 1371 <para>For <emphasis>bus-activatable</emphasis> services, do not
798d3a52
ZJS
1372 include a <literal>[Install]</literal> section in the systemd
1373 service file, but use the <varname>SystemdService=</varname>
1374 option in the corresponding DBus service file, for example
1375 (<filename>/usr/share/dbus-1/system-services/org.example.simple-dbus-service.service</filename>):</para>
d44efb62 1376
798d3a52 1377 <programlisting>[D-BUS Service]
d44efb62
CS
1378Name=org.example.simple-dbus-service
1379Exec=/usr/sbin/simple-dbus-service
1380User=root
1381SystemdService=simple-dbus-service.service</programlisting>
1382
798d3a52
ZJS
1383 <para>Please see
1384 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>
1385 for details on how you can influence the way systemd terminates
1386 the service.</para>
1387 </example>
1388
1389 <example>
1390 <title>Services that notify systemd about their initialization</title>
1391
1392 <para><varname>Type=</varname><option>simple</option> services
1393 are really easy to write, but have the major disadvantage of
1394 systemd not being able to tell when initialization of the given
1395 service is complete. For this reason, systemd supports a simple
1396 notification protocol that allows daemons to make systemd aware
1397 that they are done initializing. Use
1398 <varname>Type=</varname><option>notify</option> for this. A
1399 typical service file for such a daemon would look like
1400 this:</para>
1401
1402 <programlisting>[Unit]
d44efb62
CS
1403Description=Simple notifying service
1404
1405[Service]
1406Type=notify
1407ExecStart=/usr/sbin/simple-notifying-service
1408
1409[Install]
1410WantedBy=multi-user.target</programlisting>
1411
798d3a52 1412 <para>Note that the daemon has to support systemd's notification
7ca41557 1413 protocol, else systemd will think the service has not started yet
798d3a52
ZJS
1414 and kill it after a timeout. For an example of how to update
1415 daemons to support this protocol transparently, take a look at
1416 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
1417 systemd will consider the unit to be in the 'starting' state
1418 until a readiness notification has arrived.</para>
1419
1420 <para>Please see
1421 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>
1422 for details on how you can influence the way systemd terminates
1423 the service.</para>
1424 </example>
1425 </refsect1>
1426
1427 <refsect1>
1428 <title>See Also</title>
1429 <para>
1430 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
1431 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
1432 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1433 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1434 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1435 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1436 <citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry>
1437 </para>
1438 </refsect1>
d1ab0ca0
LP
1439
1440</refentry>