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">
7 This file is part of systemd.
9 Copyright 2010 Lennart Poettering
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.
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.
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/>.
25 <refentry id="systemd.service">
27 <title>systemd.service</title>
28 <productname>systemd</productname>
32 <contrib>Developer</contrib>
33 <firstname>Lennart</firstname>
34 <surname>Poettering</surname>
35 <email>lennart@poettering.net</email>
41 <refentrytitle>systemd.service</refentrytitle>
42 <manvolnum>5</manvolnum>
46 <refname>systemd.service</refname>
47 <refpurpose>systemd service configuration files</refpurpose>
51 <para><filename>systemd.service</filename></para>
55 <title>Description</title>
57 <para>A unit configuration file whose name ends in
58 <filename>.service</filename> encodes information
59 about a process controlled and supervised by
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>
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.</para>
77 <para>Unless <varname>DefaultDependencies=</varname>
78 is set to <option>false</option>, service units will
79 implicitly have dependencies of type
80 <varname>Requires=</varname> and
81 <varname>After=</varname> on
82 <filename>basic.target</filename> as well as
83 dependencies of type <varname>Conflicts=</varname> and
84 <varname>Before=</varname> on
85 <filename>shutdown.target</filename>. These ensure
86 that normal service units pull in basic system
87 initialization, and are terminated cleanly prior to
88 system shutdown. Only services involved with early
89 boot or late system shutdown should disable this
92 <para>If a service is requested under a certain name
93 but no unit configuration file is found, systemd looks
94 for a SysV init script by the same name (with the
95 <filename>.service</filename> suffix removed) and
96 dynamically creates a service unit from that
97 script. This is useful for compatibility with
102 <title>Options</title>
104 <para>Service files must include a
105 <literal>[Service]</literal> section, which carries
106 information about the service and the process it
107 supervises. A number of options that may be used in
108 this section are shared with other unit types. These
109 options are documented in
110 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>. The
111 options specific to the <literal>[Service]</literal>
112 section of service units are the following:</para>
116 <term><varname>Type=</varname></term>
118 <listitem><para>Configures the process
119 start-up type for this service
120 unit. One of <option>simple</option>,
121 <option>forking</option>,
122 <option>oneshot</option>,
123 <option>dbus</option>,
124 <option>notify</option> or
125 <option>idle</option>.</para>
128 <option>simple</option> (the default
129 value) it is expected that the process
131 <varname>ExecStart=</varname> is the
132 main process of the service. In this
133 mode, if the process offers
134 functionality to other processes on
135 the system its communication channels
136 should be installed before the daemon
137 is started up (e.g. sockets set up by
138 systemd, via socket activation), as
139 systemd will immediately proceed
140 starting follow-up units.</para>
143 <option>forking</option> it is
144 expected that the process configured
145 with <varname>ExecStart=</varname>
146 will call <function>fork()</function>
147 as part of its start-up. The parent process is
148 expected to exit when start-up is
149 complete and all communication
150 channels set up. The child continues
151 to run as the main daemon
152 process. This is the behaviour of
153 traditional UNIX daemons. If this
154 setting is used, it is recommended to
156 <varname>PIDFile=</varname> option, so
157 that systemd can identify the main
158 process of the daemon. systemd will
159 proceed starting follow-up units as
160 soon as the parent process
164 <option>oneshot</option> is similar
165 to <option>simple</option>, however
166 it is expected that the process has to
167 exit before systemd starts follow-up
168 units. <varname>RemainAfterExit=</varname>
169 is particularly useful for this type
173 <option>dbus</option> is similar to
174 <option>simple</option>, however it is
175 expected that the daemon acquires a
176 name on the D-Bus bus, as configured
178 <varname>BusName=</varname>. systemd
179 will proceed starting follow-up units
180 after the D-Bus bus name has been
181 acquired. Service units with this
182 option configured implicitly gain
184 <filename>dbus.socket</filename>
188 <option>notify</option> is similar to
189 <option>simple</option>, however it is
190 expected that the daemon sends a
191 notification message via
192 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>
193 or an equivalent call when it finished
194 starting up. systemd will proceed
195 starting follow-up units after this
196 notification message has been sent. If
198 <varname>NotifyAccess=</varname> (see
199 below) should be set to open access to
200 the notification socket provided by
202 <varname>NotifyAccess=</varname> is
203 not set, it will be implicitly set to
204 <option>main</option>.</para>
207 <option>idle</option> is very similar
208 to <option>idle</option>, however
209 actual execution of a the service
210 binary is delayed until all jobs are
211 dispatched. This may be used to avoid
212 interleaving of output of shell
213 services with the status output on the
219 <term><varname>RemainAfterExit=</varname></term>
221 <listitem><para>Takes a boolean value
222 that specifies whether the service
223 shall be considered active even when
224 all its processes exited. Defaults to
225 <option>no</option>.</para>
230 <term><varname>GuessMainPID=</varname></term>
232 <listitem><para>Takes a boolean value
233 that specifies whether systemd should
234 try to guess the main PID of a service
235 should if it cannot be determined
236 reliably. This option is ignored
237 unless <option>Type=forking</option>
238 is set and <option>PIDFile=</option>
239 is unset because for the other types
240 or with an explicitly configured PID
241 file the main PID is always known. The
242 guessing algorithm might come to
243 incorrect conclusions if a daemon
244 consists of more than one process. If
245 the main PID cannot be determined
246 failure detection and automatic
247 restarting of a service will not work
248 reliably. Defaults to
249 <option>yes</option>.</para>
254 <term><varname>PIDFile=</varname></term>
256 <listitem><para>Takes an absolute file
257 name pointing to the PID file of this
258 daemon. Use of this option is
259 recommended for services where
260 <varname>Type=</varname> is set to
261 <option>forking</option>. systemd will
262 read the PID of the main process of
263 the daemon after start-up of the
264 service. systemd will not write to the
265 file configured here.</para>
270 <term><varname>BusName=</varname></term>
272 <listitem><para>Takes a D-Bus bus
273 name, where this service is reachable
274 as. This option is mandatory for
276 <varname>Type=</varname> is set to
277 <option>dbus</option>, but its use
278 is otherwise recommended as well if
279 the process takes a name on the D-Bus
285 <term><varname>ExecStart=</varname></term>
286 <listitem><para>Takes a command line
287 that is executed when this service
288 shall be started up. The first token
289 of the command line must be an
290 absolute file name, then followed by
291 arguments for the process. It is
292 mandatory to set this option for all
293 services. This option may not be
294 specified more than once, except when
295 <varname>Type=oneshot</varname> is
296 used in which case more than one
297 <varname>ExecStart=</varname> line is
298 accepted which are then invoked one by
299 one, sequentially in the order they
300 appear in the unit file.</para>
302 <para>Optionally, if the absolute file
303 name is prefixed with
304 <literal>@</literal>, the second token
306 <literal>argv[0]</literal> to the
307 executed process, followed by the
308 further arguments specified. If the
309 first token is prefixed with
310 <literal>-</literal> an exit code of
311 the command normally considered a
312 failure (i.e. non-zero exit status or
313 abnormal exit due to signal) is ignored
314 and considered success. If both
315 <literal>-</literal> and
316 <literal>@</literal> are used for the
317 same command the former must precede
319 <varname>Type=forking</varname> is
320 set, the process started via this
321 command line will be considered the
322 main process of the daemon. The
323 command line accepts % specifiers as
325 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
327 <para>On top of that basic environment
328 variable substitution is
330 <literal>${FOO}</literal> as part of a
331 word, or as word of its own on the
332 command line, in which case it will be
333 replaced by the value of the
334 environment variable including all
335 whitespace it contains, resulting in a
337 <literal>$FOO</literal> as a separate
338 word on the command line, in which
339 case it will be replaced by the value
340 of the environment variable split up
341 at whitespace, resulting in no or more
342 arguments. Note that the first
343 argument (i.e. the program to execute)
344 may not be a variable, and must be a
345 literal and absolute path
346 name.</para></listitem>
350 <term><varname>ExecStartPre=</varname></term>
351 <term><varname>ExecStartPost=</varname></term>
352 <listitem><para>Additional commands
353 that are executed before (resp. after)
355 <varname>ExecStart=</varname>. Multiple
356 command lines may be concatenated in a
357 single directive, by separating them
358 by semicolons (these semicolons must
359 be passed as separate words). In that
360 case, the commands are executed one
362 serially. Alternatively, these
363 directives may be specified more than
364 once with the same effect. However,
365 the latter syntax is not recommended
366 for compatibility with parsers
368 <filename>.desktop</filename> files.
369 Use of these settings is
370 optional. Specifier and environment
371 variable substitution is
372 supported.</para></listitem>
376 <term><varname>ExecReload=</varname></term>
377 <listitem><para>Commands to execute to
378 trigger a configuration reload in the
379 service. This argument takes multiple
380 command lines, following the same
381 scheme as pointed out for
382 <varname>ExecStartPre=</varname>
383 above. Use of this setting is
384 optional. Specifier and environment
385 variable substitution is supported
386 here following the same scheme as for
387 <varname>ExecStart=</varname>. One
388 special environment variable is set:
389 if known <literal>$MAINPID</literal> is
390 set to the main process of the
391 daemon, and may be used for command
392 lines like the following:
393 <command>/bin/kill -HUP
394 $MAINPID</command>.</para></listitem>
398 <term><varname>ExecStop=</varname></term>
399 <listitem><para>Commands to execute to
400 stop the service started via
401 <varname>ExecStart=</varname>. This
402 argument takes multiple command lines,
403 following the same scheme as pointed
405 <varname>ExecStartPre=</varname>
406 above. Use of this setting is
407 optional. All processes remaining for
408 a service after the commands
409 configured in this option are run are
410 terminated according to the
411 <varname>KillMode=</varname> setting
412 (see below). If this option is not
413 specified the process is terminated
414 right-away when service stop is
415 requested. Specifier and environment
416 variable substitution is supported
418 <literal>$MAINPID</literal>, see
419 above).</para></listitem>
423 <term><varname>ExecStopPost=</varname></term>
424 <listitem><para>Additional commands
425 that are executed after the service
426 was stopped using the commands
428 <varname>ExecStop=</varname>. This
429 argument takes multiple command lines,
430 following the same scheme as pointed
432 <varname>ExecStartPre</varname>. Use
434 optional. Specifier and environment
435 variable substitution is
436 supported.</para></listitem>
440 <term><varname>RestartSec=</varname></term>
441 <listitem><para>Configures the time to
442 sleep before restarting a service (as
444 <varname>Restart=</varname>). Takes a
445 unit-less value in seconds, or a time
446 span value such as "5min
448 100ms.</para></listitem>
452 <term><varname>TimeoutSec=</varname></term>
453 <listitem><para>Configures the time to
454 wait for start-up and stop. If a
455 daemon service does not signal
456 start-up completion within the
457 configured time the service will be
458 considered failed and be shut down
459 again. If a service is asked to stop
460 but does not terminate in the
461 specified time it will be terminated
462 forcibly via SIGTERM, and after
463 another delay of this time with
465 <varname>KillMode=</varname>
466 below.) Takes a unit-less value in seconds, or a
467 time span value such as "5min
468 20s". Pass 0 to disable the timeout
470 90s.</para></listitem>
474 <term><varname>WatchdogSec=</varname></term>
475 <listitem><para>Configures the
476 watchdog timeout for a service. This
477 is activated when the start-up is
478 completed. The service must call
479 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>
480 regularly with "WATCHDOG=1". If the
481 time between two such calls is larger
482 than the configured time then the
483 service is placed in a failure
485 <varname>Restart=</varname>
486 to <option>on-failure</option> or
487 <option>always</option> the service
488 will be automatically restarted. The
489 time configured here will be passed to
490 the executed service process in the
491 <varname>WATCHDOG_USEC=</varname>
492 environment variable. If
494 <varname>NotifyAccess=</varname> (see
495 below) should be set to open access to
496 the notification socket provided by
498 <varname>NotifyAccess=</varname> is not
499 set, it will be implicitly set to
500 <option>main</option>. Defaults to 0,
502 feature.</para></listitem>
506 <term><varname>Restart=</varname></term>
507 <listitem><para>Configures whether the
508 main service process shall be
509 restarted when it exits. Takes one of
511 <option>on-success</option>,
512 <option>on-failure</option>,
513 <option>on-abort</option> or
514 <option>always</option>. If set to
515 <option>no</option> (the default) the
516 service will not be restarted when it
518 <option>on-success</option> it will be
519 restarted only when it exited cleanly,
520 i.e. terminated with an exit code of
522 <option>on-failure</option> it will be
523 restarted only when it exited with an
524 exit code not equalling 0, when
525 terminated by a signal, when an
526 operation times out or when the
527 configured watchdog timeout is
529 <option>on-abort</option> it will be
530 restarted only if it exits due to
531 reception of an uncaught signal. If
532 set to <option>always</option> the
533 service will be restarted regardless
534 whether it exited cleanly or not,
535 got terminated abnormally by a
536 signal or hit a timeout.</para></listitem>
540 <term><varname>PermissionsStartOnly=</varname></term>
541 <listitem><para>Takes a boolean
542 argument. If true, the permission
543 related execution options as
545 <varname>User=</varname> and similar
547 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
548 for more information) are only applied
549 to the process started with
550 <varname>ExecStart=</varname>, and not
552 <varname>ExecStartPre=</varname>,
553 <varname>ExecStartPost=</varname>,
554 <varname>ExecReload=</varname>,
555 <varname>ExecStop=</varname>,
556 <varname>ExecStopPost=</varname>
557 commands. If false, the setting is
558 applied to all configured commands the
559 same way. Defaults to
560 false.</para></listitem>
564 <term><varname>RootDirectoryStartOnly=</varname></term>
565 <listitem><para>Takes a boolean
566 argument. If true, the root directory
567 as configured with the
568 <varname>RootDirectory=</varname>
570 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
571 for more information) is only applied
572 to the process started with
573 <varname>ExecStart=</varname>, and not
575 <varname>ExecStartPre=</varname>,
576 <varname>ExecStartPost=</varname>,
577 <varname>ExecReload=</varname>,
578 <varname>ExecStop=</varname>,
579 <varname>ExecStopPost=</varname>
580 commands. If false, the setting is
581 applied to all configured commands the
582 same way. Defaults to
583 false.</para></listitem>
587 <term><varname>SysVStartPriority=</varname></term>
588 <listitem><para>Set the SysV start
589 priority to use to order this service
590 in relation to SysV services lacking
591 LSB headers. This option is only
592 necessary to fix ordering in relation
593 to legacy SysV services, that have no
594 ordering information encoded in the
595 script headers. As such it should only
596 be used as temporary compatibility
597 option, and not be used in new unit
598 files. Almost always it is a better
599 choice to add explicit ordering
601 <varname>After=</varname> or
602 <varname>Before=</varname>,
603 instead. For more details see
604 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>. If
605 used, pass an integer value in the
606 range 0-99.</para></listitem>
610 <term><varname>KillMode=</varname></term>
611 <listitem><para>Specifies how
612 processes of this service shall be
614 <option>control-group</option>,
615 <option>process</option>,
616 <option>none</option>.</para>
619 <option>control-group</option> all
620 remaining processes in the control
621 group of this service will be
622 terminated on service stop, after the
623 stop command (as configured with
624 <varname>ExecStop=</varname>) is
626 <option>process</option> only the main
627 process itself is killed. If set to
628 <option>none</option> no process is
629 killed. In this case only the stop
630 command will be executed on service
631 stop, but no process be killed
632 otherwise. Processes remaining alive
633 after stop are left in their control
634 group and the control group continues
635 to exist after stop unless it is
637 <option>control-group</option>.</para>
639 <para>Processes will first be
640 terminated via SIGTERM (unless the
641 signal to send is changed via
642 <varname>KillSignal=</varname>). If
643 then after a delay (configured via the
644 <varname>TimeoutSec=</varname> option)
645 processes still remain, the
646 termination request is repeated with
647 the SIGKILL signal (unless this is
649 <varname>SendSIGKILL=</varname>
651 <citerefentry><refentrytitle>kill</refentrytitle><manvolnum>2</manvolnum></citerefentry>
653 information.</para></listitem>
657 <term><varname>KillSignal=</varname></term>
658 <listitem><para>Specifies which signal
659 to use when killing a
660 service. Defaults to SIGTERM.
665 <term><varname>SendSIGKILL=</varname></term>
666 <listitem><para>Specifies whether to
667 send SIGKILL to remaining processes
668 after a timeout, if the normal
669 shutdown procedure left processes of
670 the service around. Takes a boolean
671 value. Defaults to "yes".
676 <term><varname>NonBlocking=</varname></term>
677 <listitem><para>Set O_NONBLOCK flag
678 for all file descriptors passed via
679 socket-based activation. If true, all
680 file descriptors >= 3 (i.e. all except
681 STDIN/STDOUT/STDERR) will have
682 the O_NONBLOCK flag set and hence are in
683 non-blocking mode. This option is only
684 useful in conjunction with a socket
685 unit, as described in
686 <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>. Defaults
687 to false.</para></listitem>
691 <term><varname>NotifyAccess=</varname></term>
692 <listitem><para>Controls access to the
693 service status notification socket, as
695 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>
697 <option>none</option> (the default),
698 <option>main</option> or
699 <option>all</option>. If
700 <option>none</option> no daemon status
701 updates are accepted from the service
702 processes, all status update messages
703 are ignored. If <option>main</option>
704 only service updates sent from the
705 main process of the service are
706 accepted. If <option>all</option> all
707 services updates from all members of
708 the service's control group are
709 accepted. This option should be set to
710 open access to the notification socket
712 <varname>Type=notify</varname> or
713 <varname>WatchdogUsec=</varname> (see
714 above). If those options are used but
715 <varname>NotifyAccess=</varname> not
716 configured it will be implicitly set
718 <option>main</option>.</para></listitem>
722 <term><varname>Sockets=</varname></term>
723 <listitem><para>Specifies the name of
724 the socket units this service shall
725 inherit the sockets from when the
726 service is started. Normally it
727 should not be necessary to use this
728 setting as all sockets whose unit
729 shares the same name as the service
730 (ignoring the different suffix of course)
731 are passed to the spawned
734 <para>Note that the same socket may be
735 passed to multiple processes at the
736 same time. Also note that a different
737 service may be activated on incoming
738 traffic than inherits the sockets. Or
740 <varname>Service=</varname> setting of
741 <filename>.socket</filename> units
742 doesn't have to match the inverse of the
743 <varname>Sockets=</varname> setting of
744 the <filename>.service</filename> it
745 refers to.</para></listitem>
749 <term><varname>FsckPassNo=</varname></term>
750 <listitem><para>Set the fsck passno
751 priority to use to order this service
752 in relation to other file system
753 checking services. This option is only
754 necessary to fix ordering in relation
755 to fsck jobs automatically created for
756 all <filename>/etc/fstab</filename>
757 entries with a value in the fs_passno
758 column > 0. As such it should only be
759 used as option for fsck
760 services. Almost always it is a better
761 choice to add explicit ordering
763 <varname>After=</varname> or
764 <varname>Before=</varname>,
765 instead. For more details see
766 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>. If
767 used, pass an integer value in the
769 <filename>/etc/fstab</filename>'s
770 fs_passno column. See
771 <citerefentry><refentrytitle>fstab</refentrytitle><manvolnum>5</manvolnum></citerefentry>
772 for details.</para></listitem>
776 <term><varname>StartLimitInterval=</varname></term>
777 <term><varname>StartLimitBurst=</varname></term>
779 <listitem><para>Configure service
780 start rate limiting. By default
781 services which are started more often
782 than 5 times within 10s are not
783 permitted to start any more times
784 until the 10s interval ends. With
785 these two options this rate limiting
787 <varname>StartLimitInterval=</varname>
788 to configure the checking interval
789 (defaults to 10s, set to 0 to disable
790 any kind of rate limiting). Use
791 <varname>StartLimitBurst=</varname> to
792 configure how many starts per interval
793 are allowed (defaults to 5). These
794 configuration options are particularly
795 useful in conjunction with
796 <varname>Restart=</varname>.</para></listitem>
800 <term><varname>StartLimitAction=</varname></term>
802 <listitem><para>Configure the action
803 to take if the rate limit configured
805 <varname>StartLimitInterval=</varname>
807 <varname>StartLimitBurst=</varname> is
809 <option>none</option>,
810 <option>reboot</option>,
811 <option>reboot-force</option> or
812 <option>reboot-immediate</option>. If
813 <option>none</option> is set,
814 hitting the rate limit will trigger no
815 action besides that the start will not
817 permitted. <option>reboot</option>
818 causes a reboot following the normal
819 shutdown procedure (i.e. equivalent to
820 <command>systemctl reboot</command>),
821 <option>reboot-force</option> causes
822 an forced reboot which will terminate
823 all processes forcibly but should
824 cause no dirty file systems on reboot
825 (i.e. equivalent to <command>systemctl
826 reboot -f</command>) and
827 <option>reboot-immediate</option>
828 causes immediate execution of the
829 <citerefentry><refentrytitle>reboot</refentrytitle><manvolnum>2</manvolnum></citerefentry>
830 system call, which might result in
831 data loss. Defaults to
832 <option>none</option>.</para></listitem>
839 <title>See Also</title>
841 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
842 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
843 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
844 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>