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