1 <?xml version='
1.0'
?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*-->
2 <!DOCTYPE refentry PUBLIC
"-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
6 This file is part of systemd.
8 Copyright 2010 Lennart Poettering
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 <refentry id=
"systemd.service">
26 <title>systemd.service
</title>
27 <productname>systemd
</productname>
31 <contrib>Developer
</contrib>
32 <firstname>Lennart
</firstname>
33 <surname>Poettering
</surname>
34 <email>lennart@poettering.net
</email>
40 <refentrytitle>systemd.service
</refentrytitle>
41 <manvolnum>5</manvolnum>
45 <refname>systemd.service
</refname>
46 <refpurpose>Service unit configuration
</refpurpose>
50 <para><filename><replaceable>service
</replaceable>.service
</filename></para>
54 <title>Description
</title>
56 <para>A unit configuration file whose name ends in
57 <filename>.service
</filename> encodes information about a process
58 controlled and supervised by systemd.
</para>
60 <para>This man page lists the configuration options specific to
62 <citerefentry><refentrytitle>systemd.unit
</refentrytitle><manvolnum>5</manvolnum></citerefentry>
63 for the common options of all unit configuration files. The common
64 configuration items are configured in the generic
65 <literal>[Unit]
</literal> and
<literal>[Install]
</literal>
66 sections. The service specific configuration options are
67 configured in the
<literal>[Service]
</literal> section.
</para>
69 <para>Additional options are listed in
70 <citerefentry><refentrytitle>systemd.exec
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
71 which define the execution environment the commands are executed
73 <citerefentry><refentrytitle>systemd.kill
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
74 which define the way the processes of the service are terminated,
76 <citerefentry><refentrytitle>systemd.resource-control
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
77 which configure resource control settings for the processes of the
80 <para>If a service is requested under a certain name but no unit
81 configuration file is found, systemd looks for a SysV init script
82 by the same name (with the
<filename>.service
</filename> suffix
83 removed) and dynamically creates a service unit from that script.
84 This is useful for compatibility with SysV. Note that this
85 compatibility is quite comprehensive but not
100%. For details
86 about the incompatibilities, see the
<ulink
87 url=
"http://www.freedesktop.org/wiki/Software/systemd/Incompatibilities">Incompatibilities
88 with SysV
</ulink> document.
</para>
92 <title>Automatic Dependencies
</title>
94 <para>Services with
<varname>Type=dbus
</varname> set automatically
95 acquire dependencies of type
<varname>Requires=
</varname> and
96 <varname>After=
</varname> on
97 <filename>dbus.socket
</filename>.
</para>
99 <para>Socket activated service are automatically ordered after
100 their activated
<filename>.socket
</filename> units via an
101 automatic
<varname>After=
</varname> dependency.
</para>
103 <para>Unless
<varname>DefaultDependencies=
</varname> is set to
104 <option>false
</option>, service units will implicitly have
105 dependencies of type
<varname>Requires=
</varname> and
106 <varname>After=
</varname> on
<filename>sysinit.target
</filename>,
107 a dependency of type
<varname>After=
</varname> on
108 <filename>basic.target
</filename> as well as dependencies of
109 type
<varname>Conflicts=
</varname> and
<varname>Before=
</varname>
110 on
<filename>shutdown.target
</filename>. These ensure that normal
111 service units pull in basic system initialization, and are
112 terminated cleanly prior to system shutdown. Only services
113 involved with early boot or late system shutdown should disable
116 <para>Instanced service units (i.e. service units with an
<literal>@
</literal> in their name) are assigned by
117 default a per-template slice unit (see
118 <citerefentry><refentrytitle>systemd.slice
</refentrytitle><manvolnum>5</manvolnum></citerefentry>), named after the
119 template unit, containing all instances of the specific template. This slice is normally stopped at shutdown,
120 together with all template instances. If that is not desired, set
<varname>DefaultDependencies=no
</varname> in the
121 template unit, and either define your own per-template slice unit file that also sets
122 <varname>DefaultDependencies=no
</varname>, or set
<varname>Slice=system.slice
</varname> (or another suitable slice)
123 in the template unit. Also see
124 <citerefentry><refentrytitle>systemd.resource-control
</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
</para>
126 <para>Additional implicit dependencies may be added as result of
127 execution and resource control parameters as documented in
128 <citerefentry><refentrytitle>systemd.exec
</refentrytitle><manvolnum>5</manvolnum></citerefentry>
130 <citerefentry><refentrytitle>systemd.resource-control
</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
</para>
134 <title>Options
</title>
136 <para>Service files must include a
<literal>[Service]
</literal>
137 section, which carries information about the service and the
138 process it supervises. A number of options that may be used in
139 this section are shared with other unit types. These options are
141 <citerefentry><refentrytitle>systemd.exec
</refentrytitle><manvolnum>5</manvolnum></citerefentry>
143 <citerefentry><refentrytitle>systemd.kill
</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
144 The options specific to the
<literal>[Service]
</literal> section
145 of service units are the following:
</para>
147 <variablelist class='unit-directives'
>
149 <term><varname>Type=
</varname></term>
151 <listitem><para>Configures the process start-up type for this
153 <option>simple
</option>,
154 <option>forking
</option>,
155 <option>oneshot
</option>,
156 <option>dbus
</option>,
157 <option>notify
</option> or
158 <option>idle
</option>.
</para>
160 <para>If set to
<option>simple
</option> (the default if
161 neither
<varname>Type=
</varname> nor
162 <varname>BusName=
</varname>, but
<varname>ExecStart=
</varname>
163 are specified), it is expected that the process configured
164 with
<varname>ExecStart=
</varname> is the main process of the
165 service. In this mode, if the process offers functionality to
166 other processes on the system, its communication channels
167 should be installed before the daemon is started up (e.g.
168 sockets set up by systemd, via socket activation), as systemd
169 will immediately proceed starting follow-up units.
</para>
171 <para>If set to
<option>forking
</option>, it is expected that
172 the process configured with
<varname>ExecStart=
</varname> will
173 call
<function>fork()
</function> as part of its start-up. The
174 parent process is expected to exit when start-up is complete
175 and all communication channels are set up. The child continues
176 to run as the main daemon process. This is the behavior of
177 traditional UNIX daemons. If this setting is used, it is
178 recommended to also use the
<varname>PIDFile=
</varname>
179 option, so that systemd can identify the main process of the
180 daemon. systemd will proceed with starting follow-up units as
181 soon as the parent process exits.
</para>
183 <para>Behavior of
<option>oneshot
</option> is similar to
184 <option>simple
</option>; however, it is expected that the
185 process has to exit before systemd starts follow-up units.
186 <varname>RemainAfterExit=
</varname> is particularly useful for
187 this type of service. This is the implied default if neither
188 <varname>Type=
</varname> or
<varname>ExecStart=
</varname> are
191 <para>Behavior of
<option>dbus
</option> is similar to
192 <option>simple
</option>; however, it is expected that the
193 daemon acquires a name on the D-Bus bus, as configured by
194 <varname>BusName=
</varname>. systemd will proceed with
195 starting follow-up units after the D-Bus bus name has been
196 acquired. Service units with this option configured implicitly
197 gain dependencies on the
<filename>dbus.socket
</filename>
198 unit. This type is the default if
<varname>BusName=
</varname>
201 <para>Behavior of
<option>notify
</option> is similar to
202 <option>simple
</option>; however, it is expected that the
203 daemon sends a notification message via
204 <citerefentry><refentrytitle>sd_notify
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
205 or an equivalent call when it has finished starting up.
206 systemd will proceed with starting follow-up units after this
207 notification message has been sent. If this option is used,
208 <varname>NotifyAccess=
</varname> (see below) should be set to
209 open access to the notification socket provided by systemd. If
210 <varname>NotifyAccess=
</varname> is not set, it will be
211 implicitly set to
<option>main
</option>. Note that currently
212 <varname>Type=
</varname><option>notify
</option> will not work
213 if used in combination with
214 <varname>PrivateNetwork=
</varname><option>yes
</option>.
</para>
216 <para>Behavior of
<option>idle
</option> is very similar to
217 <option>simple
</option>; however, actual execution of the
218 service binary is delayed until all jobs are dispatched. This
219 may be used to avoid interleaving of output of shell services
220 with the status output on the console.
</para>
225 <term><varname>RemainAfterExit=
</varname></term>
227 <listitem><para>Takes a boolean value that specifies whether
228 the service shall be considered active even when all its
229 processes exited. Defaults to
<option>no
</option>.
</para>
234 <term><varname>GuessMainPID=
</varname></term>
236 <listitem><para>Takes a boolean value that specifies whether
237 systemd should try to guess the main PID of a service if it
238 cannot be determined reliably. This option is ignored unless
239 <option>Type=forking
</option> is set and
240 <option>PIDFile=
</option> is unset because for the other types
241 or with an explicitly configured PID file, the main PID is
242 always known. The guessing algorithm might come to incorrect
243 conclusions if a daemon consists of more than one process. If
244 the main PID cannot be determined, failure detection and
245 automatic restarting of a service will not work reliably.
246 Defaults to
<option>yes
</option>.
</para>
251 <term><varname>PIDFile=
</varname></term>
253 <listitem><para>Takes an absolute file name pointing to the
254 PID file of this daemon. Use of this option is recommended for
255 services where
<varname>Type=
</varname> is set to
256 <option>forking
</option>. systemd will read the PID of the
257 main process of the daemon after start-up of the service.
258 systemd will not write to the file configured here, although
259 it will remove the file after the service has shut down if it
266 <term><varname>BusName=
</varname></term>
268 <listitem><para>Takes a D-Bus bus name that this service is
269 reachable as. This option is mandatory for services where
270 <varname>Type=
</varname> is set to
271 <option>dbus
</option>.
</para>
276 <term><varname>BusPolicy=
</varname></term>
278 <listitem><para>If specified, a custom kdbus
279 endpoint will be created and installed as the default bus node
280 for the service. Such a custom endpoint can hold an own set of
281 policy rules that are enforced on top of the bus-wide ones.
282 The custom endpoint is named after the service it was created
283 for, and its node will be bind-mounted over the default bus
284 node location, so the service can only access the bus through
285 its own endpoint. Note that custom bus endpoints default to a
286 "deny all" policy. Hence, if at least one
287 <varname>BusPolicy=
</varname> directive is given, you have to
288 make sure to add explicit rules for everything the service
289 should be able to do.
</para>
290 <para>The value of this directive is comprised
291 of two parts; the bus name, and a verb to
292 specify to granted access, which is one of
293 <option>see
</option>,
294 <option>talk
</option>, or
295 <option>own
</option>.
296 <option>talk
</option> implies
297 <option>see
</option>, and
<option>own
</option>
298 implies both
<option>talk
</option> and
299 <option>see
</option>.
300 If multiple access levels are specified for the
301 same bus name, the most powerful one takes
304 <para>Examples:
</para>
305 <programlisting>BusPolicy=org.freedesktop.systemd1 talk
</programlisting>
306 <programlisting>BusPolicy=org.foo.bar see
</programlisting>
307 <para>This option is only available on kdbus enabled systems.
</para>
312 <term><varname>ExecStart=
</varname></term>
313 <listitem><para>Commands with their arguments that are
314 executed when this service is started. The value is split into
315 zero or more command lines according to the rules described
316 below (see section
"Command Lines" below).
319 <para>When
<varname>Type=
</varname> is not
320 <option>oneshot
</option>, only one command may and must be
321 given. When
<varname>Type=oneshot
</varname> is used, zero or
322 more commands may be specified. This can be specified by
323 providing multiple command lines in the same directive, or
324 alternatively, this directive may be specified more than once
325 with the same effect. If the empty string is assigned to this
326 option, the list of commands to start is reset, prior
327 assignments of this option will have no effect. If no
328 <varname>ExecStart=
</varname> is specified, then the service
329 must have
<varname>RemainAfterExit=yes
</varname> set.
</para>
331 <para>For each of the specified commands, the first argument
332 must be an absolute path to an executable. Optionally, if this
333 file name is prefixed with
<literal>@
</literal>, the second
334 token will be passed as
<literal>argv[
0]
</literal> to the
335 executed process, followed by the further arguments specified.
336 If the absolute filename is prefixed with
337 <literal>-
</literal>, an exit code of the command normally
338 considered a failure (i.e. non-zero exit status or abnormal
339 exit due to signal) is ignored and considered success. If both
340 <literal>-
</literal> and
<literal>@
</literal> are used, they
341 can appear in either order.
</para>
343 <para>If more than one command is specified, the commands are
344 invoked sequentially in the order they appear in the unit
345 file. If one of the commands fails (and is not prefixed with
346 <literal>-
</literal>), other lines are not executed, and the
347 unit is considered failed.
</para>
349 <para>Unless
<varname>Type=forking
</varname> is set, the
350 process started via this command line will be considered the
351 main process of the daemon.
</para>
356 <term><varname>ExecStartPre=
</varname></term>
357 <term><varname>ExecStartPost=
</varname></term>
358 <listitem><para>Additional commands that are executed before
359 or after the command in
<varname>ExecStart=
</varname>,
360 respectively. Syntax is the same as for
361 <varname>ExecStart=
</varname>, except that multiple command
362 lines are allowed and the commands are executed one after the
363 other, serially.
</para>
365 <para>If any of those commands (not prefixed with
366 <literal>-
</literal>) fail, the rest are not executed and the
367 unit is considered failed.
</para>
369 <para><varname>ExecStart=
</varname> commands are only run after
370 all
<varname>ExecStartPre=
</varname> commands that were not prefixed
371 with a
<literal>-
</literal> exit successfully.
</para>
373 <para><varname>ExecStartPost=
</varname> commands are only run after
374 the service has started successfully, as determined by
<varname>Type=
</varname>
375 (i.e. the process has been started for
<varname>Type=simple
</varname>
376 or
<varname>Type=idle
</varname>, the process exits successfully for
377 <varname>Type=oneshot
</varname>, the initial process exits successfully
378 for
<varname>Type=forking
</varname>,
<literal>READY=
1</literal> is sent
379 for
<varname>Type=notify
</varname>, or the
<varname>BusName=
</varname>
380 has been taken for
<varname>Type=dbus
</varname>).
</para>
382 <para>Note that
<varname>ExecStartPre=
</varname> may not be
383 used to start long-running processes. All processes forked
384 off by processes invoked via
<varname>ExecStartPre=
</varname> will
385 be killed before the next service process is run.
</para>
387 <para>Note that if any of the commands specified in
<varname>ExecStartPre=
</varname>,
388 <varname>ExecStart=
</varname>, or
<varname>ExecStartPost=
</varname> fail (and are not prefixed with
389 <literal>-
</literal>, see above) or time out before the service is fully up, execution continues with commands
390 specified in
<varname>ExecStopPost=
</varname>, the commands in
<varname>ExecStop=
</varname> are skipped.
</para>
395 <term><varname>ExecReload=
</varname></term>
396 <listitem><para>Commands to execute to trigger a configuration
397 reload in the service. This argument takes multiple command
398 lines, following the same scheme as described for
399 <varname>ExecStart=
</varname> above. Use of this setting is
400 optional. Specifier and environment variable substitution is
401 supported here following the same scheme as for
402 <varname>ExecStart=
</varname>.
</para>
404 <para>One additional, special environment variable is set: if
405 known,
<varname>$MAINPID
</varname> is set to the main process
406 of the daemon, and may be used for command lines like the
409 <programlisting>/bin/kill -HUP $MAINPID
</programlisting>
411 <para>Note however that reloading a daemon by sending a signal
412 (as with the example line above) is usually not a good choice,
413 because this is an asynchronous operation and hence not
414 suitable to order reloads of multiple services against each
415 other. It is strongly recommended to set
416 <varname>ExecReload=
</varname> to a command that not only
417 triggers a configuration reload of the daemon, but also
418 synchronously waits for it to complete.
</para>
423 <term><varname>ExecStop=
</varname></term>
424 <listitem><para>Commands to execute to stop the service
425 started via
<varname>ExecStart=
</varname>. This argument takes
426 multiple command lines, following the same scheme as described
427 for
<varname>ExecStart=
</varname> above. Use of this setting
428 is optional. After the commands configured in this option are
429 run, all processes remaining for a service are terminated
430 according to the
<varname>KillMode=
</varname> setting (see
431 <citerefentry><refentrytitle>systemd.kill
</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
432 If this option is not specified, the process is terminated by
433 sending the signal specified in
<varname>KillSignal=
</varname>
434 when service stop is requested. Specifier and environment
435 variable substitution is supported (including
436 <varname>$MAINPID
</varname>, see above).
</para>
438 <para>Note that it is usually not sufficient to specify a
439 command for this setting that only asks the service to
440 terminate (for example, by queuing some form of termination
441 signal for it), but does not wait for it to do so. Since the
442 remaining processes of the services are killed using
443 <constant>SIGKILL
</constant> immediately after the command
444 exited, this would not result in a clean stop. The specified
445 command should hence be a synchronous operation, not an
446 asynchronous one.
</para>
448 <para>Note that the commands specified in
<varname>ExecStop=
</varname> are only executed when the service
449 started successfuly first. They are not invoked if the service was never started at all, or in case its
450 start-up failed, for example because any of the commands specified in
<varname>ExecStart=
</varname>,
451 <varname>ExecStartPre=
</varname> or
<varname>ExecStartPost=
</varname> failed (and weren't prefixed with
452 <literal>-
</literal>, see above) or timed out. Use
<varname>ExecStopPost=
</varname> to invoke commands when a
453 service failed to start up correctly and is shut down again.
</para>
455 <para>It is recommended to use this setting for commands that communicate with the service requesting clean
456 termination. When the commands specified with this option are executed it should be assumed that the service is
457 still fully up and is able to react correctly to all commands. For post-mortem clean-up steps use
458 <varname>ExecStopPost=
</varname> instead.
</para></listitem>
462 <term><varname>ExecStopPost=
</varname></term>
463 <listitem><para>Additional commands that are executed after the service is stopped. This includes cases where
464 the commands configured in
<varname>ExecStop=
</varname> were used, where the service does not have any
465 <varname>ExecStop=
</varname> defined, or where the service exited unexpectedly. This argument takes multiple
466 command lines, following the same scheme as described for
<varname>ExecStart=
</varname>. Use of these settings
467 is optional. Specifier and environment variable substitution is supported. Note that – unlike
468 <varname>ExecStop=
</varname> – commands specified with this setting are invoked when a service failed to start
469 up correctly and is shut down again.
</para>
471 <para>It is recommended to use this setting for clean-up operations that shall be executed even when the
472 service failed to start up correctly. Commands configured with this setting need to be able to operate even if
473 the service failed starting up half-way and left incompletely initialized data around. As the service's
474 processes have been terminated already when the commands specified with this setting are executed they should
475 not attempt to communicate with them.
</para></listitem>
479 <term><varname>RestartSec=
</varname></term>
480 <listitem><para>Configures the time to sleep before restarting
481 a service (as configured with
<varname>Restart=
</varname>).
482 Takes a unit-less value in seconds, or a time span value such
483 as
"5min 20s". Defaults to
100ms.
</para></listitem>
487 <term><varname>TimeoutStartSec=
</varname></term>
488 <listitem><para>Configures the time to wait for start-up. If a
489 daemon service does not signal start-up completion within the
490 configured time, the service will be considered failed and
491 will be shut down again. Takes a unit-less value in seconds,
492 or a time span value such as
"5min 20s". Pass
493 <literal>infinity
</literal> to disable the timeout logic. Defaults to
494 <varname>DefaultTimeoutStartSec=
</varname> from the manager
495 configuration file, except when
496 <varname>Type=oneshot
</varname> is used, in which case the
497 timeout is disabled by default (see
498 <citerefentry><refentrytitle>systemd-system.conf
</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
503 <term><varname>TimeoutStopSec=
</varname></term>
504 <listitem><para>Configures the time to wait for stop. If a
505 service is asked to stop, but does not terminate in the
506 specified time, it will be terminated forcibly via
507 <constant>SIGTERM
</constant>, and after another timeout of
508 equal duration with
<constant>SIGKILL
</constant> (see
509 <varname>KillMode=
</varname> in
510 <citerefentry><refentrytitle>systemd.kill
</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
511 Takes a unit-less value in seconds, or a time span value such
512 as
"5min 20s". Pass
<literal>infinity
</literal> to disable the
513 timeout logic. Defaults to
514 <varname>DefaultTimeoutStopSec=
</varname> from the manager
515 configuration file (see
516 <citerefentry><refentrytitle>systemd-system.conf
</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
521 <term><varname>TimeoutSec=
</varname></term>
522 <listitem><para>A shorthand for configuring both
523 <varname>TimeoutStartSec=
</varname> and
524 <varname>TimeoutStopSec=
</varname> to the specified value.
529 <term><varname>RuntimeMaxSec=
</varname></term>
531 <listitem><para>Configures a maximum time for the service to run. If this is used and the service has been
532 active for longer than the specified time it is terminated and put into a failure state. Note that this setting
533 does not have any effect on
<varname>Type=oneshot
</varname> services, as they terminate immediately after
534 activation completed. Pass
<literal>infinity
</literal> (the default) to configure no runtime
535 limit.
</para></listitem>
539 <term><varname>WatchdogSec=
</varname></term>
540 <listitem><para>Configures the watchdog timeout for a service.
541 The watchdog is activated when the start-up is completed. The
543 <citerefentry><refentrytitle>sd_notify
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
544 regularly with
<literal>WATCHDOG=
1</literal> (i.e. the
545 "keep-alive ping"). If the time between two such calls is
546 larger than the configured time, then the service is placed in
547 a failed state and it will be terminated with
548 <constant>SIGABRT
</constant>. By setting
549 <varname>Restart=
</varname> to
<option>on-failure
</option>,
550 <option>on-watchdog
</option>,
<option>on-abnormal
</option> or
551 <option>always
</option>, the service will be automatically
552 restarted. The time configured here will be passed to the
553 executed service process in the
554 <varname>WATCHDOG_USEC=
</varname> environment variable. This
555 allows daemons to automatically enable the keep-alive pinging
556 logic if watchdog support is enabled for the service. If this
557 option is used,
<varname>NotifyAccess=
</varname> (see below)
558 should be set to open access to the notification socket
559 provided by systemd. If
<varname>NotifyAccess=
</varname> is
560 not set, it will be implicitly set to
<option>main
</option>.
561 Defaults to
0, which disables this feature. The service can
562 check whether the service manager expects watchdog keep-alive
564 <citerefentry><refentrytitle>sd_watchdog_enabled
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
566 <citerefentry><refentrytitle>sd_event_set_watchdog
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
567 may be used to enable automatic watchdog notification support.
572 <term><varname>Restart=
</varname></term>
573 <listitem><para>Configures whether the service shall be
574 restarted when the service process exits, is killed, or a
575 timeout is reached. The service process may be the main
576 service process, but it may also be one of the processes
577 specified with
<varname>ExecStartPre=
</varname>,
578 <varname>ExecStartPost=
</varname>,
579 <varname>ExecStop=
</varname>,
580 <varname>ExecStopPost=
</varname>, or
581 <varname>ExecReload=
</varname>. When the death of the process
582 is a result of systemd operation (e.g. service stop or
583 restart), the service will not be restarted. Timeouts include
584 missing the watchdog
"keep-alive ping" deadline and a service
585 start, reload, and stop operation timeouts.
</para>
589 <option>on-success
</option>,
590 <option>on-failure
</option>,
591 <option>on-abnormal
</option>,
592 <option>on-watchdog
</option>,
593 <option>on-abort
</option>, or
594 <option>always
</option>.
595 If set to
<option>no
</option> (the default), the service will
596 not be restarted. If set to
<option>on-success
</option>, it
597 will be restarted only when the service process exits cleanly.
598 In this context, a clean exit means an exit code of
0, or one
600 <constant>SIGHUP
</constant>,
601 <constant>SIGINT
</constant>,
602 <constant>SIGTERM
</constant> or
603 <constant>SIGPIPE
</constant>, and
604 additionally, exit statuses and signals specified in
605 <varname>SuccessExitStatus=
</varname>. If set to
606 <option>on-failure
</option>, the service will be restarted
607 when the process exits with a non-zero exit code, is
608 terminated by a signal (including on core dump, but excluding
609 the aforementioned four signals), when an operation (such as
610 service reload) times out, and when the configured watchdog
611 timeout is triggered. If set to
<option>on-abnormal
</option>,
612 the service will be restarted when the process is terminated
613 by a signal (including on core dump, excluding the
614 aforementioned four signals), when an operation times out, or
615 when the watchdog timeout is triggered. If set to
616 <option>on-abort
</option>, the service will be restarted only
617 if the service process exits due to an uncaught signal not
618 specified as a clean exit status. If set to
619 <option>on-watchdog
</option>, the service will be restarted
620 only if the watchdog timeout for the service expires. If set
621 to
<option>always
</option>, the service will be restarted
622 regardless of whether it exited cleanly or not, got terminated
623 abnormally by a signal, or hit a timeout.
</para>
626 <title>Exit causes and the effect of the
<varname>Restart=
</varname> settings on them
</title>
629 <colspec colname='path'
/>
630 <colspec colname='expl'
/>
633 <entry>Restart settings/Exit causes
</entry>
634 <entry><option>no
</option></entry>
635 <entry><option>always
</option></entry>
636 <entry><option>on-success
</option></entry>
637 <entry><option>on-failure
</option></entry>
638 <entry><option>on-abnormal
</option></entry>
639 <entry><option>on-abort
</option></entry>
640 <entry><option>on-watchdog
</option></entry>
645 <entry>Clean exit code or signal
</entry>
655 <entry>Unclean exit code
</entry>
665 <entry>Unclean signal
</entry>
675 <entry>Timeout
</entry>
685 <entry>Watchdog
</entry>
698 <para>As exceptions to the setting above, the service will not
699 be restarted if the exit code or signal is specified in
700 <varname>RestartPreventExitStatus=
</varname> (see below).
701 Also, the services will always be restarted if the exit code
702 or signal is specified in
703 <varname>RestartForceExitStatus=
</varname> (see below).
</para>
705 <para>Setting this to
<option>on-failure
</option> is the
706 recommended choice for long-running services, in order to
707 increase reliability by attempting automatic recovery from
708 errors. For services that shall be able to terminate on their
709 own choice (and avoid immediate restarting),
710 <option>on-abnormal
</option> is an alternative choice.
</para>
715 <term><varname>SuccessExitStatus=
</varname></term>
716 <listitem><para>Takes a list of exit status definitions that,
717 when returned by the main service process, will be considered
718 successful termination, in addition to the normal successful
719 exit code
0 and the signals
<constant>SIGHUP
</constant>,
720 <constant>SIGINT
</constant>,
<constant>SIGTERM
</constant>, and
721 <constant>SIGPIPE
</constant>. Exit status definitions can
722 either be numeric exit codes or termination signal names,
723 separated by spaces. For example:
725 <programlisting>SuccessExitStatus=
1 2 8 SIGKILL
</programlisting>
727 ensures that exit codes
1,
2,
8 and
728 the termination signal
<constant>SIGKILL
</constant> are
729 considered clean service terminations.
732 <para>Note that if a process has a signal handler installed
734 <citerefentry><refentrytitle>_exit
</refentrytitle><manvolnum>2</manvolnum></citerefentry>
735 in response to a signal, the information about the signal is
736 lost. Programs should instead perform cleanup and kill
737 themselves with the same signal instead. See
738 <ulink url=
"http://www.cons.org/cracauer/sigint.html">Proper
739 handling of SIGINT/SIGQUIT — How to be a proper
740 program
</ulink>.
</para>
742 <para>This option may appear more than once, in which case the
743 list of successful exit statuses is merged. If the empty
744 string is assigned to this option, the list is reset, all
745 prior assignments of this option will have no
746 effect.
</para></listitem>
750 <term><varname>RestartPreventExitStatus=
</varname></term>
751 <listitem><para>Takes a list of exit status definitions that,
752 when returned by the main service process, will prevent
753 automatic service restarts, regardless of the restart setting
754 configured with
<varname>Restart=
</varname>. Exit status
755 definitions can either be numeric exit codes or termination
756 signal names, and are separated by spaces. Defaults to the
757 empty list, so that, by default, no exit status is excluded
758 from the configured restart logic. For example:
760 <programlisting>RestartPreventExitStatus=
1 6 SIGABRT
</programlisting>
762 ensures that exit codes
1 and
6 and the termination signal
763 <constant>SIGABRT
</constant> will not result in automatic
764 service restarting. This option may appear more than once, in
765 which case the list of restart-preventing statuses is
766 merged. If the empty string is assigned to this option, the
767 list is reset and all prior assignments of this option will
768 have no effect.
</para></listitem>
772 <term><varname>RestartForceExitStatus=
</varname></term>
773 <listitem><para>Takes a list of exit status definitions that,
774 when returned by the main service process, will force automatic
775 service restarts, regardless of the restart setting configured
776 with
<varname>Restart=
</varname>. The argument format is
778 <varname>RestartPreventExitStatus=
</varname>.
</para></listitem>
782 <term><varname>PermissionsStartOnly=
</varname></term>
783 <listitem><para>Takes a boolean argument. If true, the
784 permission-related execution options, as configured with
785 <varname>User=
</varname> and similar options (see
786 <citerefentry><refentrytitle>systemd.exec
</refentrytitle><manvolnum>5</manvolnum></citerefentry>
787 for more information), are only applied to the process started
789 <varname>ExecStart=
</varname>, and not to the various other
790 <varname>ExecStartPre=
</varname>,
791 <varname>ExecStartPost=
</varname>,
792 <varname>ExecReload=
</varname>,
793 <varname>ExecStop=
</varname>, and
794 <varname>ExecStopPost=
</varname>
795 commands. If false, the setting is applied to all configured
796 commands the same way. Defaults to false.
</para></listitem>
800 <term><varname>RootDirectoryStartOnly=
</varname></term>
801 <listitem><para>Takes a boolean argument. If true, the root
802 directory, as configured with the
803 <varname>RootDirectory=
</varname> option (see
804 <citerefentry><refentrytitle>systemd.exec
</refentrytitle><manvolnum>5</manvolnum></citerefentry>
805 for more information), is only applied to the process started
806 with
<varname>ExecStart=
</varname>, and not to the various
807 other
<varname>ExecStartPre=
</varname>,
808 <varname>ExecStartPost=
</varname>,
809 <varname>ExecReload=
</varname>,
<varname>ExecStop=
</varname>,
810 and
<varname>ExecStopPost=
</varname> commands. If false, the
811 setting is applied to all configured commands the same way.
812 Defaults to false.
</para></listitem>
816 <term><varname>NonBlocking=
</varname></term>
817 <listitem><para>Set the
<constant>O_NONBLOCK
</constant> flag
818 for all file descriptors passed via socket-based activation.
819 If true, all file descriptors
>=
3 (i.e. all except stdin,
820 stdout, and stderr) will have the
821 <constant>O_NONBLOCK
</constant> flag set and hence are in
822 non-blocking mode. This option is only useful in conjunction
823 with a socket unit, as described in
824 <citerefentry><refentrytitle>systemd.socket
</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
825 Defaults to false.
</para></listitem>
829 <term><varname>NotifyAccess=
</varname></term>
830 <listitem><para>Controls access to the service status
831 notification socket, as accessible via the
832 <citerefentry><refentrytitle>sd_notify
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
833 call. Takes one of
<option>none
</option> (the default),
834 <option>main
</option> or
<option>all
</option>. If
835 <option>none
</option>, no daemon status updates are accepted
836 from the service processes, all status update messages are
837 ignored. If
<option>main
</option>, only service updates sent
838 from the main process of the service are accepted. If
839 <option>all
</option>, all services updates from all members of
840 the service's control group are accepted. This option should
841 be set to open access to the notification socket when using
842 <varname>Type=notify
</varname> or
843 <varname>WatchdogSec=
</varname> (see above). If those options
844 are used but
<varname>NotifyAccess=
</varname> is not
845 configured, it will be implicitly set to
846 <option>main
</option>.
</para></listitem>
850 <term><varname>Sockets=
</varname></term>
851 <listitem><para>Specifies the name of the socket units this
852 service shall inherit socket file descriptors from when the
853 service is started. Normally, it should not be necessary to use
854 this setting, as all socket file descriptors whose unit shares
855 the same name as the service (subject to the different unit
856 name suffix of course) are passed to the spawned
859 <para>Note that the same socket file descriptors may be passed
860 to multiple processes simultaneously. Also note that a
861 different service may be activated on incoming socket traffic
862 than the one which is ultimately configured to inherit the
863 socket file descriptors. Or, in other words: the
864 <varname>Service=
</varname> setting of
865 <filename>.socket
</filename> units does not have to match the
866 inverse of the
<varname>Sockets=
</varname> setting of the
867 <filename>.service
</filename> it refers to.
</para>
869 <para>This option may appear more than once, in which case the
870 list of socket units is merged. If the empty string is
871 assigned to this option, the list of sockets is reset, and all
872 prior uses of this setting will have no
873 effect.
</para></listitem>
877 <term><varname>FailureAction=
</varname></term>
878 <listitem><para>Configure the action to take when the service enters a failed state. Takes the same values as
879 the unit setting
<varname>StartLimitAction=
</varname> and executes the same actions (see
880 <citerefentry><refentrytitle>systemd.unit
</refentrytitle><manvolnum>5</manvolnum></citerefentry>). Defaults to
881 <option>none
</option>.
</para></listitem>
885 <term><varname>FileDescriptorStoreMax=
</varname></term>
886 <listitem><para>Configure how many file descriptors may be
887 stored in the service manager for the service using
888 <citerefentry><refentrytitle>sd_pid_notify_with_fds
</refentrytitle><manvolnum>3</manvolnum></citerefentry>'s
889 <literal>FDSTORE=
1</literal> messages. This is useful for
890 implementing service restart schemes where the state is
891 serialized to
<filename>/run
</filename> and the file
892 descriptors passed to the service manager, to allow restarts
893 without losing state. Defaults to
0, i.e. no file descriptors
894 may be stored in the service manager by default. All file
895 descriptors passed to the service manager from a specific
896 service are passed back to the service's main process on the
897 next service restart. Any file descriptors passed to the
898 service manager are automatically closed when POLLHUP or
899 POLLERR is seen on them, or when the service is fully stopped
900 and no job queued or being executed for it.
</para></listitem>
904 <term><varname>USBFunctionDescriptors=
</varname></term>
905 <listitem><para>Configure the location of a file containing
907 url=
"https://www.kernel.org/doc/Documentation/usb/functionfs.txt">USB
908 FunctionFS
</ulink> descriptors, for implementation of USB
909 gadget functions. This is used only in conjunction with a
910 socket unit with
<varname>ListenUSBFunction=
</varname>
911 configured. The contents of this file are written to the
912 <filename>ep0
</filename> file after it is
913 opened.
</para></listitem>
917 <term><varname>USBFunctionStrings=
</varname></term>
918 <listitem><para>Configure the location of a file containing
919 USB FunctionFS strings. Behavior is similar to
920 <varname>USBFunctionDescriptors=
</varname>
921 above.
</para></listitem>
927 <citerefentry><refentrytitle>systemd.exec
</refentrytitle><manvolnum>5</manvolnum></citerefentry>
929 <citerefentry><refentrytitle>systemd.kill
</refentrytitle><manvolnum>5</manvolnum></citerefentry>
930 for more settings.
</para>
935 <title>Command lines
</title>
937 <para>This section describes command line parsing and
938 variable and specifier substitutions for
939 <varname>ExecStart=
</varname>,
940 <varname>ExecStartPre=
</varname>,
941 <varname>ExecStartPost=
</varname>,
942 <varname>ExecReload=
</varname>,
943 <varname>ExecStop=
</varname>, and
944 <varname>ExecStopPost=
</varname> options.
</para>
946 <para>Multiple command lines may be concatenated in a single
947 directive by separating them with semicolons (these semicolons
948 must be passed as separate words). Lone semicolons may be escaped
949 as
<literal>\;
</literal>.
</para>
951 <para>Each command line is split on whitespace, with the first
952 item being the command to execute, and the subsequent items being
953 the arguments. Double quotes (
"...") and single quotes ('...') may
954 be used, in which case everything until the next matching quote
955 becomes part of the same argument. C-style escapes are also
956 supported. The table below contains the list of allowed escape
957 patterns. Only patterns which match the syntax in the table are
958 allowed; others will result in an error, and must be escaped by
959 doubling the backslash. Quotes themselves are removed after
960 parsing and escape sequences substituted. In addition, a trailing
961 backslash (
<literal>\
</literal>) may be used to merge lines.
964 <para>This syntax is intended to be very similar to shell syntax,
965 but only the meta-characters and expansions described in the
966 following paragraphs are understood. Specifically, redirection
968 <literal><</literal>,
969 <literal><<</literal>,
970 <literal>></literal>, and
971 <literal>>></literal>, pipes using
972 <literal>|
</literal>, running programs in the background using
973 <literal>&</literal>, and
<emphasis>other elements of shell
974 syntax are not supported
</emphasis>.
</para>
976 <para>The command to execute must be an absolute path name. It may
977 contain spaces, but control characters are not allowed.
</para>
979 <para>The command line accepts
<literal>%
</literal> specifiers as
981 <citerefentry><refentrytitle>systemd.unit
</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
982 Note that the first argument of the command line (i.e. the program
983 to execute) may not include specifiers.
</para>
985 <para>Basic environment variable substitution is supported. Use
986 <literal>${FOO}
</literal> as part of a word, or as a word of its
987 own, on the command line, in which case it will be replaced by the
988 value of the environment variable including all whitespace it
989 contains, resulting in a single argument. Use
990 <literal>$FOO
</literal> as a separate word on the command line, in
991 which case it will be replaced by the value of the environment
992 variable split at whitespace, resulting in zero or more arguments.
993 For this type of expansion, quotes are respected when splitting
994 into words, and afterwards removed.
</para>
996 <para>Example:
</para>
998 <programlisting>Environment=
"ONE=one" 'TWO=two two'
999 ExecStart=/bin/echo $ONE $TWO ${TWO}
</programlisting>
1001 <para>This will execute
<command>/bin/echo
</command> with four
1002 arguments:
<literal>one
</literal>,
<literal>two
</literal>,
1003 <literal>two
</literal>, and
<literal>two two
</literal>.
</para>
1005 <para>Example:
</para>
1006 <programlisting>Environment=ONE='one'
"TWO='two two' too" THREE=
1007 ExecStart=/bin/echo ${ONE} ${TWO} ${THREE}
1008 ExecStart=/bin/echo $ONE $TWO $THREE
</programlisting>
1009 <para>This results in
<filename>echo
</filename> being
1010 called twice, the first time with arguments
1011 <literal>'one'
</literal>,
1012 <literal>'two two' too
</literal>,
<literal></literal>,
1013 and the second time with arguments
1014 <literal>one
</literal>,
<literal>two two
</literal>,
1015 <literal>too
</literal>.
1018 <para>To pass a literal dollar sign, use
<literal>$$
</literal>.
1019 Variables whose value is not known at expansion time are treated
1020 as empty strings. Note that the first argument (i.e. the program
1021 to execute) may not be a variable.
</para>
1023 <para>Variables to be used in this fashion may be defined through
1024 <varname>Environment=
</varname> and
1025 <varname>EnvironmentFile=
</varname>. In addition, variables listed
1026 in the section
"Environment variables in spawned processes" in
1027 <citerefentry><refentrytitle>systemd.exec
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1028 which are considered
"static configuration", may be used (this
1029 includes e.g.
<varname>$USER
</varname>, but not
1030 <varname>$TERM
</varname>).
</para>
1032 <para>Note that shell command lines are not directly supported. If
1033 shell command lines are to be used, they need to be passed
1034 explicitly to a shell implementation of some kind. Example:
</para>
1035 <programlisting>ExecStart=/bin/sh -c 'dmesg | tac'
</programlisting>
1037 <para>Example:
</para>
1039 <programlisting>ExecStart=/bin/echo one ; /bin/echo
"two two"</programlisting>
1041 <para>This will execute
<command>/bin/echo
</command> two times,
1042 each time with one argument:
<literal>one
</literal> and
1043 <literal>two two
</literal>, respectively. Because two commands are
1044 specified,
<varname>Type=oneshot
</varname> must be used.
</para>
1046 <para>Example:
</para>
1048 <programlisting>ExecStart=/bin/echo /
>/dev/null
& \; \
1049 /bin/ls
</programlisting>
1051 <para>This will execute
<command>/bin/echo
</command>
1052 with five arguments:
<literal>/
</literal>,
1053 <literal>>/dev/null
</literal>,
1054 <literal>&</literal>,
<literal>;
</literal>, and
1055 <literal>/bin/ls
</literal>.
</para>
1058 <title>C escapes supported in command lines and environment variables
</title>
1060 <colspec colname='escape'
/>
1061 <colspec colname='meaning'
/>
1064 <entry>Literal
</entry>
1065 <entry>Actual value
</entry>
1070 <entry><literal>\a
</literal></entry>
1074 <entry><literal>\b
</literal></entry>
1075 <entry>backspace
</entry>
1078 <entry><literal>\f
</literal></entry>
1079 <entry>form feed
</entry>
1082 <entry><literal>\n
</literal></entry>
1083 <entry>newline
</entry>
1086 <entry><literal>\r
</literal></entry>
1087 <entry>carriage return
</entry>
1090 <entry><literal>\t
</literal></entry>
1094 <entry><literal>\v
</literal></entry>
1095 <entry>vertical tab
</entry>
1098 <entry><literal>\\
</literal></entry>
1099 <entry>backslash
</entry>
1102 <entry><literal>\
"</literal></entry>
1103 <entry>double quotation mark</entry>
1106 <entry><literal>\'</literal></entry>
1107 <entry>single quotation mark</entry>
1110 <entry><literal>\s</literal></entry>
1111 <entry>space</entry>
1114 <entry><literal>\x<replaceable>xx</replaceable></literal></entry>
1115 <entry>character number <replaceable>xx</replaceable> in hexadecimal encoding</entry>
1118 <entry><literal>\<replaceable>nnn</replaceable></literal></entry>
1119 <entry>character number <replaceable>nnn</replaceable> in octal encoding</entry>
1127 <title>Examples</title>
1130 <title>Simple service</title>
1132 <para>The following unit file creates a service that will
1133 execute <filename>/usr/sbin/foo-daemon</filename>. Since no
1134 <varname>Type=</varname> is specified, the default
1135 <varname>Type=</varname><option>simple</option> will be assumed.
1136 systemd will assume the unit to be started immediately after the
1137 program has begun executing.</para>
1139 <programlisting>[Unit]
1143 ExecStart=/usr/sbin/foo-daemon
1146 WantedBy=multi-user.target</programlisting>
1148 <para>Note that systemd assumes here that the process started by
1149 systemd will continue running until the service terminates. If
1150 the program daemonizes itself (i.e. forks), please use
1151 <varname>Type=</varname><option>forking</option> instead.</para>
1153 <para>Since no <varname>ExecStop=</varname> was specified,
1154 systemd will send SIGTERM to all processes started from this
1155 service, and after a timeout also SIGKILL. This behavior can be
1157 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>
1160 <para>Note that this unit type does not include any type of
1161 notification when a service has completed initialization. For
1162 this, you should use other unit types, such as
1163 <varname>Type=</varname><option>notify</option> if the service
1164 understands systemd's notification protocol,
1165 <varname>Type=</varname><option>forking</option> if the service
1166 can background itself or
1167 <varname>Type=</varname><option>dbus</option> if the unit
1168 acquires a DBus name once initialization is complete. See
1173 <title>Oneshot service</title>
1175 <para>Sometimes, units should just execute an action without
1176 keeping active processes, such as a filesystem check or a
1177 cleanup action on boot. For this,
1178 <varname>Type=</varname><option>oneshot</option> exists. Units
1179 of this type will wait until the process specified terminates
1180 and then fall back to being inactive. The following unit will
1181 perform a cleanup action:</para>
1183 <programlisting>[Unit]
1184 Description=Cleanup old Foo data
1188 ExecStart=/usr/sbin/foo-cleanup
1191 WantedBy=multi-user.target</programlisting>
1193 <para>Note that systemd will consider the unit to be in the
1194 state "starting
" until the program has terminated, so ordered
1195 dependencies will wait for the program to finish before starting
1196 themselves. The unit will revert to the "inactive
" state after
1197 the execution is done, never reaching the "active
" state. That
1198 means another request to start the unit will perform the action
1201 <para><varname>Type=</varname><option>oneshot</option> are the
1202 only service units that may have more than one
1203 <varname>ExecStart=</varname> specified. They will be executed
1204 in order until either they are all successful or one of them
1209 <title>Stoppable oneshot service</title>
1211 <para>Similarly to the oneshot services, there are sometimes
1212 units that need to execute a program to set up something and
1213 then execute another to shut it down, but no process remains
1214 active while they are considered "started
". Network
1215 configuration can sometimes fall into this category. Another use
1216 case is if a oneshot service shall not be executed each time
1217 when they are pulled in as a dependency, but only the first
1220 <para>For this, systemd knows the setting
1221 <varname>RemainAfterExit=</varname><option>yes</option>, which
1222 causes systemd to consider the unit to be active if the start
1223 action exited successfully. This directive can be used with all
1224 types, but is most useful with
1225 <varname>Type=</varname><option>oneshot</option> and
1226 <varname>Type=</varname><option>simple</option>. With
1227 <varname>Type=</varname><option>oneshot</option>, systemd waits
1228 until the start action has completed before it considers the
1229 unit to be active, so dependencies start only after the start
1230 action has succeeded. With
1231 <varname>Type=</varname><option>simple</option>, dependencies
1232 will start immediately after the start action has been
1233 dispatched. The following unit provides an example for a simple
1234 static firewall.</para>
1236 <programlisting>[Unit]
1237 Description=Simple firewall
1242 ExecStart=/usr/local/sbin/simple-firewall-start
1243 ExecStop=/usr/local/sbin/simple-firewall-stop
1246 WantedBy=multi-user.target</programlisting>
1248 <para>Since the unit is considered to be running after the start
1249 action has exited, invoking <command>systemctl start</command>
1250 on that unit again will cause no action to be taken.</para>
1254 <title>Traditional forking services</title>
1256 <para>Many traditional daemons/services background (i.e. fork,
1257 daemonize) themselves when starting. Set
1258 <varname>Type=</varname><option>forking</option> in the
1259 service's unit file to support this mode of operation. systemd
1260 will consider the service to be in the process of initialization
1261 while the original program is still running. Once it exits
1262 successfully and at least a process remains (and
1263 <varname>RemainAfterExit=</varname><option>no</option>), the
1264 service is considered started.</para>
1266 <para>Often, a traditional daemon only consists of one process.
1267 Therefore, if only one process is left after the original
1268 process terminates, systemd will consider that process the main
1269 process of the service. In that case, the
1270 <varname>$MAINPID</varname> variable will be available in
1271 <varname>ExecReload=</varname>, <varname>ExecStop=</varname>,
1274 <para>In case more than one process remains, systemd will be
1275 unable to determine the main process, so it will not assume
1276 there is one. In that case, <varname>$MAINPID</varname> will not
1277 expand to anything. However, if the process decides to write a
1278 traditional PID file, systemd will be able to read the main PID
1279 from there. Please set <varname>PIDFile=</varname> accordingly.
1280 Note that the daemon should write that file before finishing
1281 with its initialization. Otherwise, systemd might try to read the
1282 file before it exists.</para>
1284 <para>The following example shows a simple daemon that forks and
1285 just starts one process in the background:</para>
1287 <programlisting>[Unit]
1288 Description=Some simple daemon
1292 ExecStart=/usr/sbin/my-simple-daemon -d
1295 WantedBy=multi-user.target</programlisting>
1298 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>
1299 for details on how you can influence the way systemd terminates
1304 <title>DBus services</title>
1306 <para>For services that acquire a name on the DBus system bus,
1307 use <varname>Type=</varname><option>dbus</option> and set
1308 <varname>BusName=</varname> accordingly. The service should not
1309 fork (daemonize). systemd will consider the service to be
1310 initialized once the name has been acquired on the system bus.
1311 The following example shows a typical DBus service:</para>
1313 <programlisting>[Unit]
1314 Description=Simple DBus service
1318 BusName=org.example.simple-dbus-service
1319 ExecStart=/usr/sbin/simple-dbus-service
1322 WantedBy=multi-user.target</programlisting>
1324 <para>For <emphasis>bus-activatable</emphasis> services, do not
1325 include a <literal>[Install]</literal> section in the systemd
1326 service file, but use the <varname>SystemdService=</varname>
1327 option in the corresponding DBus service file, for example
1328 (<filename>/usr/share/dbus-1/system-services/org.example.simple-dbus-service.service</filename>):</para>
1330 <programlisting>[D-BUS Service]
1331 Name=org.example.simple-dbus-service
1332 Exec=/usr/sbin/simple-dbus-service
1334 SystemdService=simple-dbus-service.service</programlisting>
1337 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>
1338 for details on how you can influence the way systemd terminates
1343 <title>Services that notify systemd about their initialization</title>
1345 <para><varname>Type=</varname><option>simple</option> services
1346 are really easy to write, but have the major disadvantage of
1347 systemd not being able to tell when initialization of the given
1348 service is complete. For this reason, systemd supports a simple
1349 notification protocol that allows daemons to make systemd aware
1350 that they are done initializing. Use
1351 <varname>Type=</varname><option>notify</option> for this. A
1352 typical service file for such a daemon would look like
1355 <programlisting>[Unit]
1356 Description=Simple notifying service
1360 ExecStart=/usr/sbin/simple-notifying-service
1363 WantedBy=multi-user.target</programlisting>
1365 <para>Note that the daemon has to support systemd's notification
1366 protocol, else systemd will think the service has not started yet
1367 and kill it after a timeout. For an example of how to update
1368 daemons to support this protocol transparently, take a look at
1369 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
1370 systemd will consider the unit to be in the 'starting' state
1371 until a readiness notification has arrived.</para>
1374 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>
1375 for details on how you can influence the way systemd terminates
1381 <title>See Also</title>
1383 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
1384 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
1385 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1386 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1387 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1388 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1389 <citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry>