]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/systemd.service.xml
service: make main pid guessing optional, and reread pid file after reloads
[thirdparty/systemd.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 General Public License as published by
13 the Free Software Foundation; either version 2 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 General Public License for more details.
20
21 You should have received a copy of the GNU 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>systemd service configuration files</refpurpose>
48 </refnamediv>
49
50 <refsynopsisdiv>
51 <para><filename>systemd.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.</para>
76
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
90 option.</para>
91
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
98 SysV.</para>
99 </refsect1>
100
101 <refsect1>
102 <title>Options</title>
103
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>
113
114 <variablelist>
115 <varlistentry>
116 <term><varname>Type=</varname></term>
117
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>.</para>
125
126 <para>If set to
127 <option>simple</option> (the default
128 value) it is expected that the process
129 configured with
130 <varname>ExecStart=</varname> is the
131 main process of the service. In this
132 mode, if the process offers
133 functionality to other processes on
134 the system its communication channels
135 should be installed before the daemon
136 is started up (e.g. sockets set up by
137 systemd, via socket activation), as
138 systemd will immediately proceed
139 starting follow-up units.</para>
140
141 <para>If set to
142 <option>forking</option> it is
143 expected that the process configured
144 with <varname>ExecStart=</varname>
145 will call <function>fork()</function>
146 as part of its start-up. The parent process is
147 expected to exit when start-up is
148 complete and all communication
149 channels set up. The child continues
150 to run as the main daemon
151 process. This is the behaviour of
152 traditional UNIX daemons. If this
153 setting is used, it is recommended to
154 also use the
155 <varname>PIDFile=</varname> option, so
156 that systemd can identify the main
157 process of the daemon. systemd will
158 proceed starting follow-up units as
159 soon as the parent process
160 exits.</para>
161
162 <para>Behaviour of
163 <option>oneshot</option> is similar
164 to <option>simple</option>, however
165 it is expected that the process has to
166 exit before systemd starts follow-up
167 units. <varname>RemainAfterExit=</varname>
168 is particularly useful for this type
169 of service.</para>
170
171 <para>Behaviour of
172 <option>dbus</option> is similar to
173 <option>simple</option>, however it is
174 expected that the daemon acquires a
175 name on the D-Bus bus, as configured
176 by
177 <varname>BusName=</varname>. systemd
178 will proceed starting follow-up units
179 after the D-Bus bus name has been
180 acquired. Service units with this
181 option configured implicitly gain
182 dependencies on the
183 <filename>dbus.target</filename>
184 unit.</para>
185
186 <para>Behaviour of
187 <option>notify</option> is similar to
188 <option>simple</option>, however it is
189 expected that the daemon sends a
190 notification message via
191 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>
192 or an equivalent call when it finished
193 starting up. systemd will proceed
194 starting follow-up units after this
195 notification message has been sent. If
196 this option is used
197 <varname>NotifyAccess=</varname> (see
198 below) should be set to open access to
199 the notification socket provided by
200 systemd. If
201 <varname>NotifyAccess=</varname> is not
202 set, it will implicitly be set to
203 <option>main</option>.</para>
204 </listitem>
205 </varlistentry>
206
207 <varlistentry>
208 <term><varname>RemainAfterExit=</varname></term>
209
210 <listitem><para>Takes a boolean value
211 that specifies whether the service
212 shall be considered active even when
213 all its processes exited. Defaults to
214 <option>no</option>.</para>
215 </listitem>
216 </varlistentry>
217
218 <varlistentry>
219 <term><varname>GuessMainPID=</varname></term>
220
221 <listitem><para>Takes a boolean value
222 that specifies whether systemd should
223 try to guess the main PID of a service
224 should if it cannot be determined
225 reliably. This option is ignored
226 unless <option>Type=forking</option>
227 is set and <option>PIDFile=</option>
228 is unset because for the other types
229 or with an explicitly configured PID
230 file the main PID is always known. The
231 guessing algorithm might come to
232 incorrect conclusions if a daemon
233 consists of more than one process. If
234 the main PID cannot be determined
235 failure detection and automatic
236 restarting of a service will not work
237 reliably. Defaults to
238 <option>yes</option>.</para>
239 </listitem>
240 </varlistentry>
241
242 <varlistentry>
243 <term><varname>PIDFile=</varname></term>
244
245 <listitem><para>Takes an absolute file
246 name pointing to the PID file of this
247 daemon. Use of this option is
248 recommended for services where
249 <varname>Type=</varname> is set to
250 <option>forking</option>. systemd will
251 read the PID of the main process of
252 the daemon after start-up of the
253 service. systemd will not write to the
254 file configured here.</para>
255 </listitem>
256 </varlistentry>
257
258 <varlistentry>
259 <term><varname>BusName=</varname></term>
260
261 <listitem><para>Takes a D-Bus bus
262 name, where this service is reachable
263 as. This option is mandatory for
264 services where
265 <varname>Type=</varname> is set to
266 <option>dbus</option>, but its use
267 is otherwise recommended as well if
268 the process takes a name on the D-Bus
269 bus.</para>
270 </listitem>
271 </varlistentry>
272
273 <varlistentry>
274 <term><varname>ExecStart=</varname></term>
275 <listitem><para>Takes a command line
276 that is executed when this service
277 shall be started up. The first token
278 of the command line must be an
279 absolute file name, then followed by
280 arguments for the process. It is
281 mandatory to set this option for all
282 services. This option may not be
283 specified more than once, except when
284 <varname>Type=oneshot</varname> is
285 used in which case more than one
286 <varname>ExecStart=</varname> line is
287 accepted which are then invoked one by
288 one, sequentially in the order they
289 appear in the unit file.</para>
290
291 <para>Optionally, if the absolute file
292 name is prefixed with
293 <literal>@</literal>, the second token
294 will be passed as
295 <literal>argv[0]</literal> to the
296 executed process, followed by the
297 further arguments specified. If the
298 first token is prefixed with
299 <literal>-</literal> an exit code of
300 the command normally considered a
301 failure (i.e. non-zero exit status or
302 abnormal exit due to signal) is ignored
303 and considered success. If both
304 <literal>-</literal> and
305 <literal>@</literal> are used for the
306 same command the former must precede
307 the latter. Unless
308 <varname>Type=forking</varname> is
309 set, the process started via this
310 command line will be considered the
311 main process of the daemon. The
312 command line accepts % specifiers as
313 described in
314 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>. On
315 top of that basic environment variable
316 substitution is supported, where
317 <literal>${FOO}</literal> is replaced
318 by the string value of the environment
319 variable of the same name. Also
320 <literal>$FOO</literal> may appear as
321 separate word on the command line in
322 which case the variable is replaced by
323 its value split at whitespaces. Note
324 that the first argument (i.e. the
325 binary to execute) may not be a
326 variable, and must be a literal and
327 absolute path name.</para></listitem>
328 </varlistentry>
329
330 <varlistentry>
331 <term><varname>ExecStartPre=</varname></term>
332 <term><varname>ExecStartPost=</varname></term>
333 <listitem><para>Additional commands
334 that are executed before (resp. after)
335 the command in
336 <varname>ExecStart=</varname>. Multiple
337 command lines may be concatenated in a
338 single directive, by separating them
339 by semicolons (these semicolons must
340 be passed as separate words). In that
341 case, the commands are executed one
342 after the other,
343 serially. Alternatively, these
344 directives may be specified more than
345 once with the same effect. However,
346 the latter syntax is not recommended
347 for compatibility with parsers
348 suitable for XDG
349 <filename>.desktop</filename> files.
350 Use of these settings is
351 optional. Specifier and environment
352 variable substitution is
353 supported.</para></listitem>
354 </varlistentry>
355
356 <varlistentry>
357 <term><varname>ExecReload=</varname></term>
358 <listitem><para>Commands to execute to
359 trigger a configuration reload in the
360 service. This argument takes multiple
361 command lines, following the same
362 scheme as pointed out for
363 <varname>ExecStartPre=</varname>
364 above. Use of this setting is
365 optional. Specifier and environment
366 variable substitution is supported
367 here following the same scheme as for
368 <varname>ExecStart=</varname>. One
369 special environment variable is set:
370 if known <literal>$MAINPID</literal> is
371 set to the main process of the
372 daemon, and may be used for command
373 lines like the following:
374 <command>/bin/kill -HUP
375 $MAINPID</command>.</para></listitem>
376 </varlistentry>
377
378 <varlistentry>
379 <term><varname>ExecStop=</varname></term>
380 <listitem><para>Commands to execute to
381 stop the service started via
382 <varname>ExecStart=</varname>. This
383 argument takes multiple command lines,
384 following the same scheme as pointed
385 out for
386 <varname>ExecStartPre=</varname>
387 above. Use of this setting is
388 optional. All processes remaining for
389 a service after the commands
390 configured in this option are run are
391 terminated according to the
392 <varname>KillMode=</varname> setting
393 (see below). If this option is not
394 specified the process is terminated
395 right-away when service stop is
396 requested. Specifier and environment
397 variable substitution is supported
398 (including
399 <literal>$MAINPID</literal>, see
400 above).</para></listitem>
401 </varlistentry>
402
403 <varlistentry>
404 <term><varname>ExecStopPost=</varname></term>
405 <listitem><para>Additional commands
406 that are executed after the service
407 was stopped using the commands
408 configured in
409 <varname>ExecStop=</varname>. This
410 argument takes multiple command lines,
411 following the same scheme as pointed
412 out for
413 <varname>ExecStartPre</varname>. Use
414 of these settings is
415 optional. Specifier and environment
416 variable substitution is
417 supported.</para></listitem>
418 </varlistentry>
419
420 <varlistentry>
421 <term><varname>RestartSec=</varname></term>
422 <listitem><para>Configures the time to
423 sleep before restarting a service (as
424 configured with
425 <varname>Restart=</varname>). Takes a
426 unit-less value in seconds, or a time
427 span value such as "5min
428 20s". Defaults to
429 100ms.</para></listitem>
430 </varlistentry>
431
432 <varlistentry>
433 <term><varname>TimeoutSec=</varname></term>
434 <listitem><para>Configures the time to
435 wait for start-up and stop. If a
436 daemon service does not signal
437 start-up completion within the
438 configured time the service will be
439 considered failed and be shut down
440 again. If a service is asked to stop
441 but does not terminate in the
442 specified time it will be terminated
443 forcibly via SIGTERM, and after
444 another delay of this time with
445 SIGKILL. (See
446 <varname>KillMode=</varname>
447 below.) Takes a unit-less value in seconds, or a
448 time span value such as "5min
449 20s". Pass 0 to disable the timeout
450 logic. Defaults to
451 60s.</para></listitem>
452 </varlistentry>
453
454 <varlistentry>
455 <term><varname>Restart=</varname></term>
456 <listitem><para>Configures whether the
457 main service process shall be
458 restarted when it exits. Takes one of
459 <option>no</option>,
460 <option>on-success</option>,
461 <option>on-failure</option>,
462 <option>on-abort</option> or
463 <option>always</option>. If set to
464 <option>no</option> (the default) the
465 service will not be restarted when it
466 exits. If set to
467 <option>on-success</option> it will be
468 restarted only when it exited cleanly,
469 i.e. terminated with an exit code of
470 0. If set to
471 <option>on-failure</option> it will be
472 restarted only when it exited with an
473 exit code not equalling 0, or when
474 terminated by a signal. If set to
475 <option>on-abort</option> it will be
476 restarted only if it exits due to
477 reception of an uncaught signal. If
478 set to <option>always</option> the
479 service will be restarted regardless
480 whether it exited cleanly or not, or
481 got terminated abnormally by a
482 signal.</para></listitem>
483 </varlistentry>
484
485 <varlistentry>
486 <term><varname>PermissionsStartOnly=</varname></term>
487 <listitem><para>Takes a boolean
488 argument. If true, the permission
489 related execution options as
490 configured with
491 <varname>User=</varname> and similar
492 options (see
493 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
494 for more information) are only applied
495 to the process started with
496 <varname>ExecStart=</varname>, and not
497 to the various other
498 <varname>ExecStartPre=</varname>,
499 <varname>ExecStartPost=</varname>,
500 <varname>ExecReload=</varname>,
501 <varname>ExecStop=</varname>,
502 <varname>ExecStopPost=</varname>
503 commands. If false, the setting is
504 applied to all configured commands the
505 same way. Defaults to
506 false.</para></listitem>
507 </varlistentry>
508
509 <varlistentry>
510 <term><varname>RootDirectoryStartOnly=</varname></term>
511 <listitem><para>Takes a boolean
512 argument. If true, the root directory
513 as configured with the
514 <varname>RootDirectory=</varname>
515 option (see
516 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
517 for more information) is only applied
518 to the process started with
519 <varname>ExecStart=</varname>, and not
520 to the various other
521 <varname>ExecStartPre=</varname>,
522 <varname>ExecStartPost=</varname>,
523 <varname>ExecReload=</varname>,
524 <varname>ExecStop=</varname>,
525 <varname>ExecStopPost=</varname>
526 commands. If false, the setting is
527 applied to all configured commands the
528 same way. Defaults to
529 false.</para></listitem>
530 </varlistentry>
531
532 <varlistentry>
533 <term><varname>SysVStartPriority=</varname></term>
534 <listitem><para>Set the SysV start
535 priority to use to order this service
536 in relation to SysV services lacking
537 LSB headers. This option is only
538 necessary to fix ordering in relation
539 to legacy SysV services, that have no
540 ordering information encoded in the
541 script headers. As such it should only
542 be used as temporary compatibility
543 option, and not be used in new unit
544 files. Almost always it is a better
545 choice to add explicit ordering
546 directives via
547 <varname>After=</varname> or
548 <varname>Before=</varname>,
549 instead. For more details see
550 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>. If
551 used, pass an integer value in the
552 range 0-99.</para></listitem>
553 </varlistentry>
554
555 <varlistentry>
556 <term><varname>KillMode=</varname></term>
557 <listitem><para>Specifies how
558 processes of this service shall be
559 killed. One of
560 <option>control-group</option>,
561 <option>process-group</option>,
562 <option>process</option>,
563 <option>none</option>.</para>
564
565 <para>If set to
566 <option>control-group</option> all
567 remaining processes in the control
568 group of this service will be
569 terminated on service stop, after the
570 stop command (as configured with
571 <varname>ExecStop=</varname>) is
572 executed. If set to
573 <option>process-group</option> only
574 the members of the process group of
575 the main service process are
576 killed. If set to
577 <option>process</option> only the main
578 process itself is killed. If set to
579 <option>none</option> no process is
580 killed. In this case only the stop
581 command will be executed on service
582 stop, but no process be killed
583 otherwise. Processes remaining alive
584 after stop are left in their control
585 group and the control group continues
586 to exist after stop unless it is
587 empty. Defaults to
588 <option>control-group</option>.</para>
589
590 <para>Processes will first be
591 terminated via SIGTERM (unless the
592 signal to send is changed via
593 <varname>KillSignal=</varname>). If
594 then after a delay (configured via the
595 <varname>TimeoutSec=</varname> option)
596 processes still remain, the
597 termination request is repeated with
598 the SIGKILL signal (unless this is
599 disabled via the
600 <varname>SendSIGKILL=</varname>
601 option). See
602 <citerefentry><refentrytitle>kill</refentrytitle><manvolnum>2</manvolnum></citerefentry>
603 for more
604 information.</para></listitem>
605 </varlistentry>
606
607 <varlistentry>
608 <term><varname>KillSignal=</varname></term>
609 <listitem><para>Specifies which signal
610 to use when killing a
611 service. Defaults to SIGTERM.
612 </para></listitem>
613 </varlistentry>
614
615 <varlistentry>
616 <term><varname>SendSIGKILL=</varname></term>
617 <listitem><para>Specifies whether to
618 send SIGKILL to remaining processes
619 after a timeout, if the normal
620 shutdown procedure left processes of
621 the service around. Takes a boolean
622 value. Defaults to "yes".
623 </para></listitem>
624 </varlistentry>
625
626 <varlistentry>
627 <term><varname>NonBlocking=</varname></term>
628 <listitem><para>Set O_NONBLOCK flag
629 for all file descriptors passed via
630 socket-based activation. If true, all
631 file descriptors >= 3 (i.e. all except
632 STDIN/STDOUT/STDERR) will have
633 the O_NONBLOCK flag set and hence are in
634 non-blocking mode. This option is only
635 useful in conjunction with a socket
636 unit, as described in
637 <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>. Defaults
638 to false.</para></listitem>
639 </varlistentry>
640
641 <varlistentry>
642 <term><varname>NotifyAccess=</varname></term>
643 <listitem><para>Controls access to the
644 service status notification socket, as
645 accessible via the
646 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>
647 call. Takes one of
648 <option>none</option> (the default),
649 <option>main</option> or
650 <option>all</option>. If
651 <option>none</option> no daemon status
652 updates are accepted from the service
653 processes, all status update messages
654 are ignored. If <option>main</option>
655 only service updates sent from the
656 main process of the service are
657 accepted. If <option>all</option> all
658 services updates from all members of
659 the service's control group are
660 accepted. This option must be set to
661 open access to the notification socket
662 when using
663 <varname>Type=notify</varname> (see above).</para></listitem>
664 </varlistentry>
665
666 <varlistentry>
667 <term><varname>Sockets=</varname></term>
668 <listitem><para>Specifies the name of
669 the socket units this service shall
670 inherit the sockets from when the
671 service (ignoring the different suffix
672 of course) is started. Normally it
673 should not be necessary to use this
674 setting as all sockets whose unit
675 shares the same name as the service
676 are passed to the spawned
677 process.</para>
678
679 <para>Note that the same socket may be
680 passed to multiple processes at the
681 same time. Also note that a different
682 service may be activated on incoming
683 traffic than inherits the sockets. Or
684 in other words: The
685 <varname>Service=</varname> setting of
686 <filename>.socket</filename> units
687 doesn't have to match the inverse of the
688 <varname>Sockets=</varname> setting of
689 the <filename>.service</filename> it
690 refers to.</para></listitem>
691 </varlistentry>
692
693 <varlistentry>
694 <term><varname>FsckPassNo=</varname></term>
695 <listitem><para>Set the fsck passno
696 priority to use to order this service
697 in relation to other file system
698 checking services. This option is only
699 necessary to fix ordering in relation
700 to fsck jobs automatically created for
701 all <filename>/etc/fstab</filename>
702 entries with a value in the fs_passno
703 column > 0. As such it should only be
704 used as option for fsck
705 services. Almost always it is a better
706 choice to add explicit ordering
707 directives via
708 <varname>After=</varname> or
709 <varname>Before=</varname>,
710 instead. For more details see
711 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>. If
712 used, pass an integer value in the
713 same range as
714 <filename>/etc/fstab</filename>'s
715 fs_passno column. See
716 <citerefentry><refentrytitle>fstab</refentrytitle><manvolnum>5</manvolnum></citerefentry>
717 for details.</para></listitem>
718 </varlistentry>
719
720 </variablelist>
721 </refsect1>
722
723 <refsect1>
724 <title>See Also</title>
725 <para>
726 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
727 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
728 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
729 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
730 </para>
731 </refsect1>
732
733 </refentry>