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