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