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