]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/systemd.service.xml
load-fragment: fix segv on parse error
[thirdparty/systemd.git] / man / systemd.service.xml
CommitLineData
d1ab0ca0 1<?xml version='1.0'?> <!--*-nxml-*-->
d1ab0ca0 2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
12b42c76 3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
d1ab0ca0
LP
4
5<!--
6 This file is part of systemd.
7
8 Copyright 2010 Lennart Poettering
9
10 systemd is free software; you can redistribute it and/or modify it
5430f7f2
LP
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
d1ab0ca0
LP
13 (at your option) any later version.
14
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
5430f7f2 18 Lesser General Public License for more details.
d1ab0ca0 19
5430f7f2 20 You should have received a copy of the GNU Lesser General Public License
d1ab0ca0
LP
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22-->
23
24<refentry id="systemd.service">
798d3a52
ZJS
25 <refentryinfo>
26 <title>systemd.service</title>
27 <productname>systemd</productname>
28
29 <authorgroup>
30 <author>
31 <contrib>Developer</contrib>
32 <firstname>Lennart</firstname>
33 <surname>Poettering</surname>
34 <email>lennart@poettering.net</email>
35 </author>
36 </authorgroup>
37 </refentryinfo>
38
39 <refmeta>
40 <refentrytitle>systemd.service</refentrytitle>
41 <manvolnum>5</manvolnum>
42 </refmeta>
43
44 <refnamediv>
45 <refname>systemd.service</refname>
46 <refpurpose>Service unit configuration</refpurpose>
47 </refnamediv>
48
49 <refsynopsisdiv>
50 <para><filename><replaceable>service</replaceable>.service</filename></para>
51 </refsynopsisdiv>
52
53 <refsect1>
54 <title>Description</title>
55
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>
59
60 <para>This man page lists the configuration options specific to
61 this unit type. See
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>
68
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
72 in, and in
73 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
74 which define the way the processes of the service are terminated,
75 and in
76 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
77 which configure resource control settings for the processes of the
78 service.</para>
79
80 <para>Unless <varname>DefaultDependencies=</varname> is set to
81 <option>false</option>, service units will implicitly have
82 dependencies of type <varname>Requires=</varname> and
83 <varname>After=</varname> on <filename>basic.target</filename> as
84 well as dependencies of type <varname>Conflicts=</varname> and
85 <varname>Before=</varname> on
86 <filename>shutdown.target</filename>. These ensure that normal
87 service units pull in basic system initialization, and are
88 terminated cleanly prior to system shutdown. Only services
89 involved with early boot or late system shutdown should disable
90 this option.</para>
91
92 <para>If a service is requested under a certain name but no unit
93 configuration file is found, systemd looks for a SysV init script
94 by the same name (with the <filename>.service</filename> suffix
95 removed) and dynamically creates a service unit from that script.
96 This is useful for compatibility with SysV. Note that this
97 compatibility is quite comprehensive but not 100%. For details
98 about the incompatibilities, see the <ulink
99 url="http://www.freedesktop.org/wiki/Software/systemd/Incompatibilities">Incompatibilities
100 with SysV</ulink> document.
101 </para>
102 </refsect1>
103
104 <refsect1>
105 <title>Options</title>
106
107 <para>Service files must include a <literal>[Service]</literal>
108 section, which carries information about the service and the
109 process it supervises. A number of options that may be used in
110 this section are shared with other unit types. These options are
111 documented in
112 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
113 and
114 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
115 The options specific to the <literal>[Service]</literal> section
116 of service units are the following:</para>
117
118 <variablelist class='unit-directives'>
119 <varlistentry>
120 <term><varname>Type=</varname></term>
121
122 <listitem><para>Configures the process start-up type for this
123 service unit. One of
124 <option>simple</option>,
125 <option>forking</option>,
126 <option>oneshot</option>,
127 <option>dbus</option>,
128 <option>notify</option> or
129 <option>idle</option>.</para>
130
131 <para>If set to <option>simple</option> (the default if
132 neither <varname>Type=</varname> nor
133 <varname>BusName=</varname>, but <varname>ExecStart=</varname>
134 are specified), it is expected that the process configured
135 with <varname>ExecStart=</varname> is the main process of the
136 service. In this mode, if the process offers functionality to
137 other processes on the system, its communication channels
138 should be installed before the daemon is started up (e.g.
139 sockets set up by systemd, via socket activation), as systemd
140 will immediately proceed starting follow-up units.</para>
141
142 <para>If set to <option>forking</option>, it is expected that
143 the process configured with <varname>ExecStart=</varname> will
144 call <function>fork()</function> as part of its start-up. The
145 parent process is expected to exit when start-up is complete
146 and all communication channels are set up. The child continues
147 to run as the main daemon process. This is the behavior of
148 traditional UNIX daemons. If this setting is used, it is
149 recommended to also use the <varname>PIDFile=</varname>
150 option, so that systemd can identify the main process of the
151 daemon. systemd will proceed with starting follow-up units as
152 soon as the parent process exits.</para>
153
154 <para>Behavior of <option>oneshot</option> is similar to
155 <option>simple</option>; however, it is expected that the
156 process has to exit before systemd starts follow-up units.
157 <varname>RemainAfterExit=</varname> is particularly useful for
158 this type of service. This is the implied default if neither
159 <varname>Type=</varname> or <varname>ExecStart=</varname> are
160 specified.</para>
161
162 <para>Behavior of <option>dbus</option> is similar to
163 <option>simple</option>; however, it is expected that the
164 daemon acquires a name on the D-Bus bus, as configured by
165 <varname>BusName=</varname>. systemd will proceed with
166 starting follow-up units after the D-Bus bus name has been
167 acquired. Service units with this option configured implicitly
168 gain dependencies on the <filename>dbus.socket</filename>
169 unit. This type is the default if <varname>BusName=</varname>
170 is specified.</para>
171
172 <para>Behavior of <option>notify</option> is similar to
173 <option>simple</option>; however, it is expected that the
174 daemon sends a notification message via
175 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>
176 or an equivalent call when it has finished starting up.
177 systemd will proceed with starting follow-up units after this
178 notification message has been sent. If this option is used,
179 <varname>NotifyAccess=</varname> (see below) should be set to
180 open access to the notification socket provided by systemd. If
181 <varname>NotifyAccess=</varname> is not set, it will be
182 implicitly set to <option>main</option>. Note that currently
183 <varname>Type=</varname><option>notify</option> will not work
184 if used in combination with
185 <varname>PrivateNetwork=</varname><option>yes</option>.</para>
186
187 <para>Behavior of <option>idle</option> is very similar to
188 <option>simple</option>; however, actual execution of the
189 service binary is delayed until all jobs are dispatched. This
190 may be used to avoid interleaving of output of shell services
191 with the status output on the console.</para>
192 </listitem>
193 </varlistentry>
194
195 <varlistentry>
196 <term><varname>RemainAfterExit=</varname></term>
197
198 <listitem><para>Takes a boolean value that specifies whether
199 the service shall be considered active even when all its
200 processes exited. Defaults to <option>no</option>.</para>
201 </listitem>
202 </varlistentry>
203
204 <varlistentry>
205 <term><varname>GuessMainPID=</varname></term>
206
207 <listitem><para>Takes a boolean value that specifies whether
208 systemd should try to guess the main PID of a service if it
209 cannot be determined reliably. This option is ignored unless
210 <option>Type=forking</option> is set and
211 <option>PIDFile=</option> is unset because for the other types
212 or with an explicitly configured PID file, the main PID is
213 always known. The guessing algorithm might come to incorrect
214 conclusions if a daemon consists of more than one process. If
215 the main PID cannot be determined, failure detection and
216 automatic restarting of a service will not work reliably.
217 Defaults to <option>yes</option>.</para>
218 </listitem>
219 </varlistentry>
220
221 <varlistentry>
222 <term><varname>PIDFile=</varname></term>
223
224 <listitem><para>Takes an absolute file name pointing to the
225 PID file of this daemon. Use of this option is recommended for
226 services where <varname>Type=</varname> is set to
227 <option>forking</option>. systemd will read the PID of the
228 main process of the daemon after start-up of the service.
341db20b
FS
229 systemd will not write to the file configured here, although
230 it will remove the file after the service has shut down if it
231 still exists.
232 </para>
798d3a52
ZJS
233 </listitem>
234 </varlistentry>
235
236 <varlistentry>
237 <term><varname>BusName=</varname></term>
238
239 <listitem><para>Takes a D-Bus bus name that this service is
240 reachable as. This option is mandatory for services where
241 <varname>Type=</varname> is set to
242 <option>dbus</option>.</para>
243 </listitem>
244 </varlistentry>
245
246 <varlistentry>
247 <term><varname>BusPolicy=</varname></term>
248
b8332e7a 249 <listitem><para>If specified, a custom kdbus
798d3a52
ZJS
250 endpoint will be created and installed as the default bus node
251 for the service. Such a custom endpoint can hold an own set of
252 policy rules that are enforced on top of the bus-wide ones.
253 The custom endpoint is named after the service it was created
254 for, and its node will be bind-mounted over the default bus
255 node location, so the service can only access the bus through
256 its own endpoint. Note that custom bus endpoints default to a
257 'deny all' policy. Hence, if at least one
258 <varname>BusPolicy=</varname> directive is given, you have to
259 make sure to add explicit rules for everything the service
260 should be able to do.</para>
261 <para>The value of this directive is comprised
262 of two parts; the bus name, and a verb to
263 specify to granted access, which is one of
264 <option>see</option>,
265 <option>talk</option>, or
266 <option>own</option>.
267 <option>talk</option> implies
268 <option>see</option>, and <option>own</option>
269 implies both <option>talk</option> and
270 <option>see</option>.
271 If multiple access levels are specified for the
272 same bus name, the most powerful one takes
273 effect.
274 </para>
275 <para>Examples:</para>
276 <programlisting>BusPolicy=org.freedesktop.systemd1 talk</programlisting>
277 <programlisting>BusPolicy=org.foo.bar see</programlisting>
278 <para>This option is only available on kdbus enabled systems.</para>
279 </listitem>
280 </varlistentry>
281
282 <varlistentry>
283 <term><varname>ExecStart=</varname></term>
284 <listitem><para>Commands with their arguments that are
285 executed when this service is started. The value is split into
286 zero or more command lines is according to the rules described
287 below (see section "Command Lines" below).
288 </para>
289
290 <para>When <varname>Type</varname> is not
291 <option>oneshot</option>, only one command may and must be
292 given. When <varname>Type=oneshot</varname> is used, zero or
293 more commands may be specified. This can be specified by
294 providing multiple command lines in the same directive, or
295 alternatively, this directive may be specified more than once
296 with the same effect. If the empty string is assigned to this
297 option, the list of commands to start is reset, prior
298 assignments of this option will have no effect. If no
299 <varname>ExecStart=</varname> is specified, then the service
300 must have <varname>RemainAfterExit=yes</varname> set.</para>
301
302 <para>For each of the specified commands, the first argument
303 must be an absolute path to an executable. Optionally, if this
304 file name is prefixed with <literal>@</literal>, the second
305 token will be passed as <literal>argv[0]</literal> to the
306 executed process, followed by the further arguments specified.
307 If the absolute filename is prefixed with
308 <literal>-</literal>, an exit code of the command normally
309 considered a failure (i.e. non-zero exit status or abnormal
310 exit due to signal) is ignored and considered success. If both
311 <literal>-</literal> and <literal>@</literal> are used, they
312 can appear in either order.</para>
313
314 <para>If more than one command is specified, the commands are
315 invoked sequentially in the order they appear in the unit
316 file. If one of the commands fails (and is not prefixed with
317 <literal>-</literal>), other lines are not executed, and the
318 unit is considered failed.</para>
319
320 <para>Unless <varname>Type=forking</varname> is set, the
321 process started via this command line will be considered the
322 main process of the daemon.</para>
323 </listitem>
324 </varlistentry>
325
326 <varlistentry>
327 <term><varname>ExecStartPre=</varname></term>
328 <term><varname>ExecStartPost=</varname></term>
329 <listitem><para>Additional commands that are executed before
330 or after the command in <varname>ExecStart=</varname>,
331 respectively. Syntax is the same as for
332 <varname>ExecStart=</varname>, except that multiple command
333 lines are allowed and the commands are executed one after the
334 other, serially.</para>
335
336 <para>If any of those commands (not prefixed with
337 <literal>-</literal>) fail, the rest are not executed and the
338 unit is considered failed.</para>
b481de3b
LP
339
340 <para>Note that <varname>ExecStartPre=</varname> may not be
341 used to start long-running processes. All processes forked
342 off by processes invoked via <varname>ExecStartPre=</varname> will
343 be killed before the next service process is run.</para>
798d3a52
ZJS
344 </listitem>
345 </varlistentry>
346
347 <varlistentry>
348 <term><varname>ExecReload=</varname></term>
349 <listitem><para>Commands to execute to trigger a configuration
350 reload in the service. This argument takes multiple command
351 lines, following the same scheme as described for
352 <varname>ExecStart=</varname> above. Use of this setting is
353 optional. Specifier and environment variable substitution is
354 supported here following the same scheme as for
355 <varname>ExecStart=</varname>.</para>
356
357 <para>One additional, special environment variable is set: if
358 known, <varname>$MAINPID</varname> is set to the main process
359 of the daemon, and may be used for command lines like the
360 following:</para>
361
362 <programlisting>/bin/kill -HUP $MAINPID</programlisting>
363
364 <para>Note however that reloading a daemon by sending a signal
365 (as with the example line above) is usually not a good choice,
366 because this is an asynchronous operation and hence not
367 suitable to order reloads of multiple services against each
368 other. It is strongly recommended to set
369 <varname>ExecReload=</varname> to a command that not only
370 triggers a configuration reload of the daemon, but also
371 synchronously waits for it to complete.</para>
372 </listitem>
373 </varlistentry>
374
375 <varlistentry>
376 <term><varname>ExecStop=</varname></term>
377 <listitem><para>Commands to execute to stop the service
378 started via <varname>ExecStart=</varname>. This argument takes
379 multiple command lines, following the same scheme as described
380 for <varname>ExecStart=</varname> above. Use of this setting
381 is optional. After the commands configured in this option are
382 run, all processes remaining for a service are terminated
383 according to the <varname>KillMode=</varname> setting (see
384 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
cceb20c7
LP
385 If this option is not specified, the process is terminated by
386 sending the signal specified in <varname>KillSignal=</varname>
387 when service stop is requested. Specifier and environment
388 variable substitution is supported (including
389 <varname>$MAINPID</varname>, see above).</para>
390
391 <para>Note that it is usually not sufficient to specify a
392 command for this setting that only asks the service to
393 terminate (for example by queuing some form of termination
394 signal for it), but does not wait for it to do so. Since the
395 remaining processes of the services are killed using
396 <constant>SIGKILL</constant> immediately after the command
397 exited this would not result in a clean stop. The specified
398 command should hence be a synchronous operation, not an
399 asynchronous one.</para></listitem>
798d3a52
ZJS
400 </varlistentry>
401
402 <varlistentry>
403 <term><varname>ExecStopPost=</varname></term>
404 <listitem><para>Additional commands that are executed after
405 the service was stopped. This includes cases where the
406 commands configured in <varname>ExecStop=</varname> were used,
407 where the service does not have any
408 <varname>ExecStop=</varname> defined, or where the service
409 exited unexpectedly. This argument takes multiple command
410 lines, following the same scheme as described for
411 <varname>ExecStart</varname>. Use of these settings is
412 optional. Specifier and environment variable substitution is
413 supported.</para></listitem>
414 </varlistentry>
415
416 <varlistentry>
417 <term><varname>RestartSec=</varname></term>
418 <listitem><para>Configures the time to sleep before restarting
419 a service (as configured with <varname>Restart=</varname>).
420 Takes a unit-less value in seconds, or a time span value such
421 as "5min 20s". Defaults to 100ms.</para></listitem>
422 </varlistentry>
423
424 <varlistentry>
425 <term><varname>TimeoutStartSec=</varname></term>
426 <listitem><para>Configures the time to wait for start-up. If a
427 daemon service does not signal start-up completion within the
428 configured time, the service will be considered failed and
429 will be shut down again. Takes a unit-less value in seconds,
430 or a time span value such as "5min 20s". Pass
431 <literal>0</literal> to disable the timeout logic. Defaults to
432 <varname>DefaultTimeoutStartSec=</varname> from the manager
433 configuration file, except when
434 <varname>Type=oneshot</varname> is used, in which case the
435 timeout is disabled by default (see
436 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
437 </para></listitem>
438 </varlistentry>
439
440 <varlistentry>
441 <term><varname>TimeoutStopSec=</varname></term>
442 <listitem><para>Configures the time to wait for stop. If a
443 service is asked to stop, but does not terminate in the
444 specified time, it will be terminated forcibly via
445 <constant>SIGTERM</constant>, and after another timeout of
446 equal duration with <constant>SIGKILL</constant> (see
447 <varname>KillMode=</varname> in
448 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
449 Takes a unit-less value in seconds, or a time span value such
450 as "5min 20s". Pass <literal>0</literal> to disable the
451 timeout logic. Defaults to
452 <varname>DefaultTimeoutStopSec=</varname> from the manager
453 configuration file (see
454 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
455 </para></listitem>
456 </varlistentry>
457
458 <varlistentry>
459 <term><varname>TimeoutSec=</varname></term>
460 <listitem><para>A shorthand for configuring both
461 <varname>TimeoutStartSec=</varname> and
462 <varname>TimeoutStopSec=</varname> to the specified value.
463 </para></listitem>
464 </varlistentry>
465
466 <varlistentry>
467 <term><varname>WatchdogSec=</varname></term>
468 <listitem><para>Configures the watchdog timeout for a service.
469 The watchdog is activated when the start-up is completed. The
470 service must call
471 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>
472 regularly with <literal>WATCHDOG=1</literal> (i.e. the
473 "keep-alive ping"). If the time between two such calls is
474 larger than the configured time, then the service is placed in
475 a failed state and it will be terminated with
476 <varname>SIGABRT</varname>. By setting
477 <varname>Restart=</varname> to <option>on-failure</option> or
478 <option>always</option>, the service will be automatically
479 restarted. The time configured here will be passed to the
480 executed service process in the
481 <varname>WATCHDOG_USEC=</varname> environment variable. This
482 allows daemons to automatically enable the keep-alive pinging
483 logic if watchdog support is enabled for the service. If this
484 option is used, <varname>NotifyAccess=</varname> (see below)
485 should be set to open access to the notification socket
486 provided by systemd. If <varname>NotifyAccess=</varname> is
487 not set, it will be implicitly set to <option>main</option>.
488 Defaults to 0, which disables this feature.</para></listitem>
489 </varlistentry>
490
491 <varlistentry>
492 <term><varname>Restart=</varname></term>
493 <listitem><para>Configures whether the service shall be
494 restarted when the service process exits, is killed, or a
495 timeout is reached. The service process may be the main
496 service process, but it may also be one of the processes
497 specified with <varname>ExecStartPre=</varname>,
498 <varname>ExecStartPost=</varname>,
499 <varname>ExecStop=</varname>,
500 <varname>ExecStopPost=</varname>, or
501 <varname>ExecReload=</varname>. When the death of the process
502 is a result of systemd operation (e.g. service stop or
503 restart), the service will not be restarted. Timeouts include
504 missing the watchdog "keep-alive ping" deadline and a service
505 start, reload, and stop operation timeouts.</para>
506
507 <para>Takes one of
508 <option>no</option>,
509 <option>on-success</option>,
510 <option>on-failure</option>,
511 <option>on-abnormal</option>,
512 <option>on-watchdog</option>,
513 <option>on-abort</option>, or
514 <option>always</option>.
515 If set to <option>no</option> (the default), the service will
516 not be restarted. If set to <option>on-success</option>, it
517 will be restarted only when the service process exits cleanly.
518 In this context, a clean exit means an exit code of 0, or one
519 of the signals
520 <constant>SIGHUP</constant>,
521 <constant>SIGINT</constant>,
522 <constant>SIGTERM</constant> or
523 <constant>SIGPIPE</constant>, and
524 additionally, exit statuses and signals specified in
525 <varname>SuccessExitStatus=</varname>. If set to
526 <option>on-failure</option>, the service will be restarted
527 when the process exits with a non-zero exit code, is
528 terminated by a signal (including on core dump, but excluding
ff9b60f3 529 the aforementioned four signals), when an operation (such as
798d3a52
ZJS
530 service reload) times out, and when the configured watchdog
531 timeout is triggered. If set to <option>on-abnormal</option>,
532 the service will be restarted when the process is terminated
533 by a signal (including on core dump, excluding the
534 aforementioned four signals), when an operation times out, or
535 when the watchdog timeout is triggered. If set to
536 <option>on-abort</option>, the service will be restarted only
537 if the service process exits due to an uncaught signal not
538 specified as a clean exit status. If set to
539 <option>on-watchdog</option>, the service will be restarted
540 only if the watchdog timeout for the service expires. If set
541 to <option>always</option>, the service will be restarted
542 regardless of whether it exited cleanly or not, got terminated
543 abnormally by a signal, or hit a timeout.</para>
544
545 <table>
546 <title>Exit causes and the effect of the <varname>Restart=</varname> settings on them</title>
547
548 <tgroup cols='2'>
549 <colspec colname='path' />
550 <colspec colname='expl' />
551 <thead>
552 <row>
553 <entry>Restart settings/Exit causes</entry>
554 <entry><option>no</option></entry>
555 <entry><option>always</option></entry>
556 <entry><option>on-success</option></entry>
557 <entry><option>on-failure</option></entry>
558 <entry><option>on-abnormal</option></entry>
559 <entry><option>on-abort</option></entry>
560 <entry><option>on-watchdog</option></entry>
561 </row>
562 </thead>
563 <tbody>
564 <row>
565 <entry>Clean exit code or signal</entry>
566 <entry/>
567 <entry>X</entry>
568 <entry>X</entry>
569 <entry/>
570 <entry/>
571 <entry/>
572 <entry/>
573 </row>
574 <row>
575 <entry>Unclean exit code</entry>
576 <entry/>
577 <entry>X</entry>
578 <entry/>
579 <entry>X</entry>
580 <entry/>
581 <entry/>
582 <entry/>
583 </row>
584 <row>
585 <entry>Unclean signal</entry>
586 <entry/>
587 <entry>X</entry>
588 <entry/>
589 <entry>X</entry>
590 <entry>X</entry>
591 <entry>X</entry>
592 <entry/>
593 </row>
594 <row>
595 <entry>Timeout</entry>
596 <entry/>
597 <entry>X</entry>
598 <entry/>
599 <entry>X</entry>
600 <entry>X</entry>
601 <entry/>
602 <entry/>
603 </row>
604 <row>
605 <entry>Watchdog</entry>
606 <entry/>
607 <entry>X</entry>
608 <entry/>
609 <entry>X</entry>
610 <entry>X</entry>
611 <entry/>
612 <entry>X</entry>
613 </row>
614 </tbody>
615 </tgroup>
616 </table>
617
618 <para>As exceptions to the setting above the service will not
619 be restarted if the exit code or signal is specified in
620 <varname>RestartPreventExitStatus=</varname> (see below).
621 Also, the services will always be restarted if the exit code
622 or signal is specified in
623 <varname>RestartForceExitStatus=</varname> (see below).</para>
624
625 <para>Setting this to <option>on-failure</option> is the
626 recommended choice for long-running services, in order to
627 increase reliability by attempting automatic recovery from
628 errors. For services that shall be able to terminate on their
629 own choice (and avoid immediate restarting),
630 <option>on-abnormal</option> is an alternative choice.</para>
631 </listitem>
632 </varlistentry>
633
634 <varlistentry>
635 <term><varname>SuccessExitStatus=</varname></term>
636 <listitem><para>Takes a list of exit status definitions that
637 when returned by the main service process will be considered
638 successful termination, in addition to the normal successful
639 exit code 0 and the signals <constant>SIGHUP</constant>,
640 <constant>SIGINT</constant>, <constant>SIGTERM</constant>, and
641 <constant>SIGPIPE</constant>. Exit status definitions can
642 either be numeric exit codes or termination signal names,
643 separated by spaces. For example:
644 <programlisting>SuccessExitStatus=1 2 8
645 SIGKILL</programlisting> ensures that exit codes 1, 2, 8 and
646 the termination signal <constant>SIGKILL</constant> are
647 considered clean service terminations.
648 </para>
649
650 <para>Note that if a process has a signal handler installed
651 and exits by calling
652 <citerefentry><refentrytitle>_exit</refentrytitle><manvolnum>2</manvolnum></citerefentry>
653 in response to a signal, the information about the signal is
654 lost. Programs should instead perform cleanup and kill
655 themselves with the same signal instead. See
656 <ulink url="http://www.cons.org/cracauer/sigint.html">Proper
657 handling of SIGINT/SIGQUIT — How to be a proper
658 program</ulink>.</para>
659
660 <para>This option may appear more than once, in which case the
661 list of successful exit statuses is merged. If the empty
662 string is assigned to this option, the list is reset, all
663 prior assignments of this option will have no
664 effect.</para></listitem>
665 </varlistentry>
666
667 <varlistentry>
668 <term><varname>RestartPreventExitStatus=</varname></term>
669 <listitem><para>Takes a list of exit status definitions that
670 when returned by the main service process will prevent
671 automatic service restarts, regardless of the restart setting
672 configured with <varname>Restart=</varname>. Exit status
673 definitions can either be numeric exit codes or termination
674 signal names, and are separated by spaces. Defaults to the
675 empty list, so that, by default, no exit status is excluded
676 from the configured restart logic. For example:
677 <programlisting>RestartPreventExitStatus=1 6
678 SIGABRT</programlisting> ensures that exit codes 1 and 6 and
679 the termination signal <constant>SIGABRT</constant> will not
680 result in automatic service restarting. This option may appear
681 more than once, in which case the list of restart-preventing
682 statuses is merged. If the empty string is assigned to this
683 option, the list is reset and all prior assignments of this
684 option will have no effect.</para></listitem>
685 </varlistentry>
686
687 <varlistentry>
688 <term><varname>RestartForceExitStatus=</varname></term>
689 <listitem><para>Takes a list of exit status definitions that
690 when returned by the main service process will force automatic
691 service restarts, regardless of the restart setting configured
692 with <varname>Restart=</varname>. The argument format is
693 similar to
694 <varname>RestartPreventExitStatus=</varname>.</para></listitem>
695 </varlistentry>
696
697 <varlistentry>
698 <term><varname>PermissionsStartOnly=</varname></term>
699 <listitem><para>Takes a boolean argument. If true, the
700 permission-related execution options, as configured with
701 <varname>User=</varname> and similar options (see
702 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
703 for more information), are only applied to the process started
704 with
705 <varname>ExecStart=</varname>, and not to the various other
706 <varname>ExecStartPre=</varname>,
707 <varname>ExecStartPost=</varname>,
708 <varname>ExecReload=</varname>,
709 <varname>ExecStop=</varname>, and
710 <varname>ExecStopPost=</varname>
711 commands. If false, the setting is applied to all configured
712 commands the same way. Defaults to false.</para></listitem>
713 </varlistentry>
714
715 <varlistentry>
716 <term><varname>RootDirectoryStartOnly=</varname></term>
717 <listitem><para>Takes a boolean argument. If true, the root
718 directory, as configured with the
719 <varname>RootDirectory=</varname> option (see
720 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
721 for more information), is only applied to the process started
722 with <varname>ExecStart=</varname>, and not to the various
723 other <varname>ExecStartPre=</varname>,
724 <varname>ExecStartPost=</varname>,
725 <varname>ExecReload=</varname>, <varname>ExecStop=</varname>,
726 and <varname>ExecStopPost=</varname> commands. If false, the
727 setting is applied to all configured commands the same way.
728 Defaults to false.</para></listitem>
729 </varlistentry>
730
731 <varlistentry>
732 <term><varname>NonBlocking=</varname></term>
733 <listitem><para>Set the <constant>O_NONBLOCK</constant> flag
734 for all file descriptors passed via socket-based activation.
735 If true, all file descriptors >= 3 (i.e. all except stdin,
736 stdout, and stderr) will have the
737 <constant>O_NONBLOCK</constant> flag set and hence are in
738 non-blocking mode. This option is only useful in conjunction
739 with a socket unit, as described in
740 <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
741 Defaults to false.</para></listitem>
742 </varlistentry>
743
744 <varlistentry>
745 <term><varname>NotifyAccess=</varname></term>
746 <listitem><para>Controls access to the service status
747 notification socket, as accessible via the
748 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>
749 call. Takes one of <option>none</option> (the default),
750 <option>main</option> or <option>all</option>. If
751 <option>none</option>, no daemon status updates are accepted
752 from the service processes, all status update messages are
753 ignored. If <option>main</option>, only service updates sent
754 from the main process of the service are accepted. If
755 <option>all</option>, all services updates from all members of
756 the service's control group are accepted. This option should
757 be set to open access to the notification socket when using
758 <varname>Type=notify</varname> or
759 <varname>WatchdogSec=</varname> (see above). If those options
760 are used but <varname>NotifyAccess=</varname> is not
761 configured, it will be implicitly set to
762 <option>main</option>.</para></listitem>
763 </varlistentry>
764
765 <varlistentry>
766 <term><varname>Sockets=</varname></term>
767 <listitem><para>Specifies the name of the socket units this
768 service shall inherit socket file descriptors from when the
769 service is started. Normally it should not be necessary to use
770 this setting as all socket file descriptors whose unit shares
771 the same name as the service (subject to the different unit
772 name suffix of course) are passed to the spawned
773 process.</para>
774
775 <para>Note that the same socket file descriptors may be passed
776 to multiple processes simultaneously. Also note that a
777 different service may be activated on incoming socket traffic
778 than the one which is ultimately configured to inherit the
779 socket file descriptors. Or in other words: the
780 <varname>Service=</varname> setting of
781 <filename>.socket</filename> units does not have to match the
782 inverse of the <varname>Sockets=</varname> setting of the
783 <filename>.service</filename> it refers to.</para>
784
785 <para>This option may appear more than once, in which case the
786 list of socket units is merged. If the empty string is
787 assigned to this option, the list of sockets is reset, and all
788 prior uses of this setting will have no
789 effect.</para></listitem>
790 </varlistentry>
791
792 <varlistentry>
793 <term><varname>StartLimitInterval=</varname></term>
794 <term><varname>StartLimitBurst=</varname></term>
795
796 <listitem><para>Configure service start rate limiting. By
797 default, services which are started more than 5 times within
798 10 seconds are not permitted to start any more times until the
799 10 second interval ends. With these two options, this rate
800 limiting may be modified. Use
801 <varname>StartLimitInterval=</varname> to configure the
802 checking interval (defaults to
803 <varname>DefaultStartLimitInterval=</varname> in manager
804 configuration file, set to 0 to disable any kind of rate
805 limiting). Use <varname>StartLimitBurst=</varname> to
806 configure how many starts per interval are allowed (defaults
807 to <varname>DefaultStartLimitBurst=</varname> in manager
808 configuration file). These configuration options are
809 particularly useful in conjunction with
810 <varname>Restart=</varname>; however, they apply to all kinds
811 of starts (including manual), not just those triggered by the
812 <varname>Restart=</varname> logic. Note that units which are
813 configured for <varname>Restart=</varname> and which reach the
814 start limit are not attempted to be restarted anymore;
815 however, they may still be restarted manually at a later
816 point, from which point on, the restart logic is again
817 activated. Note that <command>systemctl reset-failed</command>
818 will cause the restart rate counter for a service to be
819 flushed, which is useful if the administrator wants to
820 manually start a service and the start limit interferes with
821 that.</para></listitem>
822 </varlistentry>
823
824 <varlistentry>
825 <term><varname>StartLimitAction=</varname></term>
826
827 <listitem><para>Configure the action to take if the rate limit
828 configured with <varname>StartLimitInterval=</varname> and
829 <varname>StartLimitBurst=</varname> is hit. Takes one of
830 <option>none</option>,
831 <option>reboot</option>,
832 <option>reboot-force</option>,
833 <option>reboot-immediate</option>,
834 <option>poweroff</option>,
835 <option>poweroff-force</option> or
836 <option>poweroff-immediate</option>. If
837 <option>none</option> is set, hitting the rate limit will
838 trigger no action besides that the start will not be
839 permitted. <option>reboot</option> causes a reboot following
840 the normal shutdown procedure (i.e. equivalent to
841 <command>systemctl reboot</command>).
842 <option>reboot-force</option> causes a forced reboot which
843 will terminate all processes forcibly but should cause no
844 dirty file systems on reboot (i.e. equivalent to
845 <command>systemctl reboot -f</command>) and
846 <option>reboot-immediate</option> causes immediate execution
847 of the
848 <citerefentry><refentrytitle>reboot</refentrytitle><manvolnum>2</manvolnum></citerefentry>
849 system call, which might result in data loss. Similar,
850 <option>poweroff</option>, <option>poweroff-force</option>,
851 <option>poweroff-immediate</option> have the effect of
852 powering down the system with similar semantics. Defaults to
853 <option>none</option>.</para></listitem>
854 </varlistentry>
855
856 <varlistentry>
857 <term><varname>FailureAction=</varname></term>
858 <listitem><para>Configure the action to take when the service
859 enters a failed state. Takes the same values as
860 <varname>StartLimitAction=</varname> and executes the same
861 actions. Defaults to <option>none</option>. </para></listitem>
862 </varlistentry>
863
864 <varlistentry>
865 <term><varname>RebootArgument=</varname></term>
866 <listitem><para>Configure the optional argument for the
867 <citerefentry><refentrytitle>reboot</refentrytitle><manvolnum>2</manvolnum></citerefentry>
868 system call if <varname>StartLimitAction=</varname> or
869 <varname>FailureAction=</varname> is a reboot action. This
870 works just like the optional argument to <command>systemctl
871 reboot</command> command.</para></listitem>
872 </varlistentry>
873
874 <varlistentry>
875 <term><varname>FileDescriptorStoreMax=</varname></term>
876 <listitem><para>Configure how many file descriptors may be
877 stored in the service manager for the service using
878 <citerefentry><refentrytitle>sd_pid_notify_with_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>'s
879 <literal>FDSTORE=1</literal> messages. This is useful for
880 implementing service restart schemes where the state is
881 serialized to <filename>/run</filename> and the file
882 descriptors passed to the service manager, to allow restarts
883 without losing state. Defaults to 0, i.e. no file descriptors
884 may be stored in the service manager by default. All file
885 descriptors passed to the service manager from a specific
886 service are passed back to the service's main process on the
887 next service restart. Any file descriptors passed to the
888 service manager are automatically closed when POLLHUP or
889 POLLERR is seen on them, or when the service is fully stopped
890 and no job queued or being executed for it.</para></listitem>
891 </varlistentry>
892
893 </variablelist>
894
895 <para>Check
896 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
897 and
898 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>
899 for more settings.</para>
900
901 </refsect1>
902
903 <refsect1>
904 <title>Command lines</title>
905
906 <para>This section describes command line parsing and
ff9b60f3 907 variable and specifier substitutions for
798d3a52
ZJS
908 <varname>ExecStart=</varname>,
909 <varname>ExecStartPre=</varname>,
910 <varname>ExecStartPost=</varname>,
911 <varname>ExecReload=</varname>,
912 <varname>ExecStop=</varname>, and
913 <varname>ExecStopPost=</varname> options.</para>
914
915 <para>Multiple command lines may be concatenated in a single
916 directive by separating them with semicolons (these semicolons
917 must be passed as separate words). Lone semicolons may be escaped
918 as <literal>\;</literal>.</para>
919
920 <para>Each command line is split on whitespace, with the first
921 item being the command to execute, and the subsequent items being
922 the arguments. Double quotes ("...") and single quotes ('...') may
923 be used, in which case everything until the next matching quote
924 becomes part of the same argument. C-style escapes are also
925 supported, see table below. Quotes themselves are removed after
926 parsing and escape sequences substituted. In addition, a trailing
927 backslash (<literal>\</literal>) may be used to merge lines.
928 </para>
929
930 <para>This syntax is intended to be very similar to shell syntax,
931 but only the meta-characters and expansions described in the
932 following paragraphs are understood. Specifically, redirection
933 using
934 <literal>&lt;</literal>,
935 <literal>&lt;&lt;</literal>,
936 <literal>&gt;</literal>, and
937 <literal>&gt;&gt;</literal>, pipes using
938 <literal>|</literal>, running programs in the background using
939 <literal>&amp;</literal>, and <emphasis>other elements of shell
940 syntax are not supported</emphasis>.</para>
941
942 <para>The command to execute must an absolute path name. It may
943 contain spaces, but control characters are not allowed.</para>
944
945 <para>The command line accepts <literal>%</literal> specifiers as
946 described in
947 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
948 Note that the first argument of the command line (i.e. the program
949 to execute) may not include specifiers.</para>
950
951 <para>Basic environment variable substitution is supported. Use
952 <literal>${FOO}</literal> as part of a word, or as a word of its
953 own, on the command line, in which case it will be replaced by the
954 value of the environment variable including all whitespace it
955 contains, resulting in a single argument. Use
956 <literal>$FOO</literal> as a separate word on the command line, in
957 which case it will be replaced by the value of the environment
958 variable split at whitespace resulting in zero or more arguments.
959 For this type of expansion, quotes and respected when splitting
960 into words, and afterwards removed.</para>
961
962 <para>Example:</para>
963
964 <programlisting>Environment="ONE=one" 'TWO=two two'
5d9a2698
ZJS
965ExecStart=/bin/echo $ONE $TWO ${TWO}</programlisting>
966
798d3a52
ZJS
967 <para>This will execute <command>/bin/echo</command> with four
968 arguments: <literal>one</literal>, <literal>two</literal>,
969 <literal>two</literal>, and <literal>two two</literal>.</para>
5d9a2698 970
798d3a52
ZJS
971 <para>Example:</para>
972 <programlisting>Environment=ONE='one' "TWO='two two' too" THREE=
5d9a2698
ZJS
973ExecStart=/bin/echo ${ONE} ${TWO} ${THREE}
974ExecStart=/bin/echo $ONE $TWO $THREE</programlisting>
798d3a52
ZJS
975 <para>This results in <filename>echo</filename> being
976 called twice, the first time with arguments
977 <literal>'one'</literal>,
978 <literal>'two two' too</literal>, <literal></literal>,
979 and the second time with arguments
980 <literal>one</literal>, <literal>two two</literal>,
981 <literal>too</literal>.
982 </para>
983
984 <para>To pass a literal dollar sign, use <literal>$$</literal>.
985 Variables whose value is not known at expansion time are treated
986 as empty strings. Note that the first argument (i.e. the program
987 to execute) may not be a variable.</para>
988
989 <para>Variables to be used in this fashion may be defined through
990 <varname>Environment=</varname> and
991 <varname>EnvironmentFile=</varname>. In addition, variables listed
992 in the section "Environment variables in spawned processes" in
993 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
994 which are considered "static configuration", may be used (this
995 includes e.g. <varname>$USER</varname>, but not
996 <varname>$TERM</varname>).</para>
997
998 <para>Note that shell command lines are not directly supported. If
999 shell command lines are to be used, they need to be passed
1000 explicitly to a shell implementation of some kind. Example:</para>
1001 <programlisting>ExecStart=/bin/sh -c 'dmesg | tac'</programlisting>
1002
1003 <para>Example:</para>
1004
1005 <programlisting>ExecStart=/bin/echo one ; /bin/echo "two two"</programlisting>
1006
1007 <para>This will execute <command>/bin/echo</command> two times,
1008 each time with one argument: <literal>one</literal> and
1009 <literal>two two</literal>, respectively. Because two commands are
1010 specified, <varname>Type=oneshot</varname> must be used.</para>
1011
1012 <para>Example:</para>
1013
1014 <programlisting>ExecStart=/bin/echo / &gt;/dev/null &amp; \; \
30d88d54
ZJS
1015/bin/ls</programlisting>
1016
798d3a52
ZJS
1017 <para>This will execute <command>/bin/echo</command>
1018 with five arguments: <literal>/</literal>,
1019 <literal>&gt;/dev/null</literal>,
1020 <literal>&amp;</literal>, <literal>;</literal>, and
1021 <literal>/bin/ls</literal>.</para>
1022
1023 <table>
1024 <title>C escapes supported in command lines and environment variables</title>
1025 <tgroup cols='2'>
1026 <colspec colname='escape' />
1027 <colspec colname='meaning' />
1028 <thead>
1029 <row>
1030 <entry>Literal</entry>
1031 <entry>Actual value</entry>
1032 </row>
1033 </thead>
1034 <tbody>
1035 <row>
1036 <entry><literal>\a</literal></entry>
1037 <entry>bell</entry>
1038 </row>
1039 <row>
1040 <entry><literal>\b</literal></entry>
1041 <entry>backspace</entry>
1042 </row>
1043 <row>
1044 <entry><literal>\f</literal></entry>
1045 <entry>form feed</entry>
1046 </row>
1047 <row>
1048 <entry><literal>\n</literal></entry>
1049 <entry>newline</entry>
1050 </row>
1051 <row>
1052 <entry><literal>\r</literal></entry>
1053 <entry>carriage return</entry>
1054 </row>
1055 <row>
1056 <entry><literal>\t</literal></entry>
1057 <entry>tab</entry>
1058 </row>
1059 <row>
1060 <entry><literal>\v</literal></entry>
1061 <entry>vertical tab</entry>
1062 </row>
1063 <row>
1064 <entry><literal>\\</literal></entry>
1065 <entry>backslash</entry>
1066 </row>
1067 <row>
1068 <entry><literal>\"</literal></entry>
1069 <entry>double quotation mark</entry>
1070 </row>
1071 <row>
1072 <entry><literal>\'</literal></entry>
1073 <entry>single quotation mark</entry>
1074 </row>
1075 <row>
1076 <entry><literal>\s</literal></entry>
1077 <entry>space</entry>
1078 </row>
1079 <row>
1080 <entry><literal>\x<replaceable>xx</replaceable></literal></entry>
1081 <entry>character number <replaceable>xx</replaceable> in hexadecimal encoding</entry>
1082 </row>
1083 <row>
1084 <entry><literal>\<replaceable>nnn</replaceable></literal></entry>
1085 <entry>character number <replaceable>nnn</replaceable> in octal encoding</entry>
1086 </row>
1087 </tbody>
1088 </tgroup>
1089 </table>
1090 </refsect1>
1091
1092 <refsect1>
1093 <title>Examples</title>
1094
1095 <example>
1096 <title>Simple service</title>
1097
1098 <para>The following unit file creates a service that will
1099 execute <filename>/usr/sbin/foo-daemon</filename>. Since no
1100 <varname>Type=</varname> is specified, the default
1101 <varname>Type=</varname><option>simple</option> will be assumed.
1102 systemd will assume the unit to be started immediately after the
1103 program has begun executing.</para>
1104
1105 <programlisting>[Unit]
d44efb62
CS
1106Description=Foo
1107
1108[Service]
1109ExecStart=/usr/sbin/foo-daemon
1110
1111[Install]
1112WantedBy=multi-user.target</programlisting>
1113
798d3a52
ZJS
1114 <para>Note that systemd assumes here that the process started by
1115 systemd will continue running until the service terminates. If
1116 the program daemonizes itself (i.e. forks), please use
1117 <varname>Type=</varname><option>forking</option> instead.</para>
1118
1119 <para>Since no <varname>ExecStop=</varname> was specified,
1120 systemd will send SIGTERM to all processes started from this
1121 service, and after a timeout also SIGKILL. This behavior can be
1122 modified, see
1123 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>
1124 for details.</para>
1125
1126 <para>Note that this unit type does not include any type of
1127 notification when a service has completed initialization. For
1128 this, you should use other unit types, such as
1129 <varname>Type=</varname><option>notify</option> if the service
1130 understands systemd's notification protocol,
1131 <varname>Type=</varname><option>forking</option> if the service
1132 can background itself or
1133 <varname>Type=</varname><option>dbus</option> if the unit
1134 acquires a DBus name once initialization is complete. See
1135 below.</para>
1136 </example>
1137
1138 <example>
1139 <title>Oneshot service</title>
1140
1141 <para>Sometimes units should just execute an action without
1142 keeping active processes, such as a filesystem check or a
1143 cleanup action on boot. For this,
1144 <varname>Type=</varname><option>oneshot</option> exists. Units
1145 of this type will wait until the process specified terminates
1146 and then fall back to being inactive. The following unit will
ff9b60f3 1147 perform a cleanup action:</para>
798d3a52
ZJS
1148
1149 <programlisting>[Unit]
d44efb62
CS
1150Description=Cleanup old Foo data
1151
1152[Service]
1153Type=oneshot
1154ExecStart=/usr/sbin/foo-cleanup
1155
1156[Install]
1157WantedBy=multi-user.target</programlisting>
1158
798d3a52
ZJS
1159 <para>Note that systemd will consider the unit to be in the
1160 state 'starting' until the program has terminated, so ordered
1161 dependencies will wait for the program to finish before starting
1162 themselves. The unit will revert to the 'inactive' state after
1163 the execution is done, never reaching the 'active' state. That
1164 means another request to start the unit will perform the action
1165 again.</para>
1166
1167 <para><varname>Type=</varname><option>oneshot</option> are the
1168 only service units that may have more than one
1169 <varname>ExecStart=</varname> specified. They will be executed
1170 in order until either they are all successful or one of them
1171 fails.</para>
1172 </example>
1173
1174 <example>
1175 <title>Stoppable oneshot service</title>
1176
1177 <para>Similarly to the oneshot services, there are sometimes
1178 units that need to execute a program to set up something and
1179 then execute another to shut it down, but no process remains
1180 active while they are considered 'started'. Network
1181 configuration can sometimes fall into this category. Another use
1182 case is if a oneshot service shall not be executed a each time
1183 when they are pulled in as a dependency, but only the first
1184 time.</para>
1185
1186 <para>For this, systemd knows the setting
1187 <varname>RemainAfterExit=</varname><option>yes</option>, which
1188 causes systemd to consider the unit to be active if the start
1189 action exited successfully. This directive can be used with all
1190 types, but is most useful with
1191 <varname>Type=</varname><option>oneshot</option> and
1192 <varname>Type=</varname><option>simple</option>. With
1193 <varname>Type=</varname><option>oneshot</option> systemd waits
1194 until the start action has completed before it considers the
1195 unit to be active, so dependencies start only after the start
1196 action has succeeded. With
1197 <varname>Type=</varname><option>simple</option> dependencies
1198 will start immediately after the start action has been
1199 dispatched. The following unit provides an example for a simple
1200 static firewall.</para>
1201
1202 <programlisting>[Unit]
d44efb62
CS
1203Description=Simple firewall
1204
1205[Service]
1206Type=oneshot
1207RemainAfterExit=yes
1208ExecStart=/usr/local/sbin/simple-firewall-start
1209ExecStop=/usr/local/sbin/simple-firewall-stop
1210
1211[Install]
1212WantedBy=multi-user.target</programlisting>
1213
798d3a52
ZJS
1214 <para>Since the unit is considered to be running after the start
1215 action has exited, invoking <command>systemctl start</command>
1216 on that unit again will cause no action to be taken.</para>
1217 </example>
1218
1219 <example>
1220 <title>Traditional forking services</title>
1221
1222 <para>Many traditional daemons/services background (i.e. fork,
1223 daemonize) themselves when starting. Set
1224 <varname>Type=</varname><option>forking</option> in the
1225 service's unit file to support this mode of operation. systemd
1226 will consider the service to be in the process of initialization
1227 while the original program is still running. Once it exits
1228 successfully and at least a process remains (and
1229 <varname>RemainAfterExit=</varname><option>no</option>), the
1230 service is considered started.</para>
1231
1232 <para>Often a traditional daemon only consists of one process.
1233 Therefore, if only one process is left after the original
1234 process terminates, systemd will consider that process the main
1235 process of the service. In that case, the
1236 <varname>$MAINPID</varname> variable will be available in
1237 <varname>ExecReload=</varname>, <varname>ExecStop=</varname>,
1238 etc.</para>
1239
1240 <para>In case more than one process remains, systemd will be
1241 unable to determine the main process, so it will not assume
1242 there is one. In that case, <varname>$MAINPID</varname> will not
1243 expand to anything. However, if the process decides to write a
1244 traditional PID file, systemd will be able to read the main PID
1245 from there. Please set <varname>PIDFile=</varname> accordingly.
1246 Note that the daemon should write that file before finishing
1247 with its initialization, otherwise systemd might try to read the
1248 file before it exists.</para>
1249
1250 <para>The following example shows a simple daemon that forks and
1251 just starts one process in the background:</para>
1252
1253 <programlisting>[Unit]
d44efb62
CS
1254Description=Some simple daemon
1255
1256[Service]
1257Type=forking
1258ExecStart=/usr/sbin/my-simple-daemon -d
1259
1260[Install]
1261WantedBy=multi-user.target</programlisting>
1262
798d3a52
ZJS
1263 <para>Please see
1264 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>
1265 for details on how you can influence the way systemd terminates
1266 the service.</para>
1267 </example>
1268
1269 <example>
1270 <title>DBus services</title>
1271
1272 <para>For services that acquire a name on the DBus system bus,
1273 use <varname>Type=</varname><option>dbus</option> and set
1274 <varname>BusName=</varname> accordingly. The service should not
1275 fork (daemonize). systemd will consider the service to be
1276 initialized once the name has been acquired on the system bus.
1277 The following example shows a typical DBus service:</para>
1278
1279 <programlisting>[Unit]
d44efb62
CS
1280Description=Simple DBus service
1281
1282[Service]
1283Type=dbus
1284BusName=org.example.simple-dbus-service
1285ExecStart=/usr/sbin/simple-dbus-service
1286
1287[Install]
1288WantedBy=multi-user.target</programlisting>
1289
798d3a52
ZJS
1290 <para>For <emphasis>bus-activatable</emphasis> services, don't
1291 include a <literal>[Install]</literal> section in the systemd
1292 service file, but use the <varname>SystemdService=</varname>
1293 option in the corresponding DBus service file, for example
1294 (<filename>/usr/share/dbus-1/system-services/org.example.simple-dbus-service.service</filename>):</para>
d44efb62 1295
798d3a52 1296 <programlisting>[D-BUS Service]
d44efb62
CS
1297Name=org.example.simple-dbus-service
1298Exec=/usr/sbin/simple-dbus-service
1299User=root
1300SystemdService=simple-dbus-service.service</programlisting>
1301
798d3a52
ZJS
1302 <para>Please see
1303 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>
1304 for details on how you can influence the way systemd terminates
1305 the service.</para>
1306 </example>
1307
1308 <example>
1309 <title>Services that notify systemd about their initialization</title>
1310
1311 <para><varname>Type=</varname><option>simple</option> services
1312 are really easy to write, but have the major disadvantage of
1313 systemd not being able to tell when initialization of the given
1314 service is complete. For this reason, systemd supports a simple
1315 notification protocol that allows daemons to make systemd aware
1316 that they are done initializing. Use
1317 <varname>Type=</varname><option>notify</option> for this. A
1318 typical service file for such a daemon would look like
1319 this:</para>
1320
1321 <programlisting>[Unit]
d44efb62
CS
1322Description=Simple notifying service
1323
1324[Service]
1325Type=notify
1326ExecStart=/usr/sbin/simple-notifying-service
1327
1328[Install]
1329WantedBy=multi-user.target</programlisting>
1330
798d3a52
ZJS
1331 <para>Note that the daemon has to support systemd's notification
1332 protocol, else systemd will think the service hasn't started yet
1333 and kill it after a timeout. For an example of how to update
1334 daemons to support this protocol transparently, take a look at
1335 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
1336 systemd will consider the unit to be in the 'starting' state
1337 until a readiness notification has arrived.</para>
1338
1339 <para>Please see
1340 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>
1341 for details on how you can influence the way systemd terminates
1342 the service.</para>
1343 </example>
1344 </refsect1>
1345
1346 <refsect1>
1347 <title>See Also</title>
1348 <para>
1349 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
1350 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
1351 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1352 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1353 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1354 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1355 <citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry>
1356 </para>
1357 </refsect1>
d1ab0ca0
LP
1358
1359</refentry>