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