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