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