]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/systemd.service.xml
man: document that we now accept more than one main process for Type=oneshot services
[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>ValidNoProcess=</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>ValidNoProcess=</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>PIDFile=</varname></term>
220
221 <listitem><para>Takes an absolute file
222 name pointing to the PID file of this
223 daemon. Use of this option is
224 recommended for services where
225 <varname>Type=</varname> is set to
226 <option>forking</option>.</para>
227 </listitem>
228 </varlistentry>
229
230 <varlistentry>
231 <term><varname>BusName=</varname></term>
232
233 <listitem><para>Takes a D-Bus bus
234 name, where this service is reachable
235 as. This option is mandatory for
236 services where
237 <varname>Type=</varname> is set to
238 <option>dbus</option>, but its use
239 is otherwise recommended as well if
240 the process takes a name on the D-Bus
241 bus.</para>
242 </listitem>
243 </varlistentry>
244
245 <varlistentry>
246 <term><varname>ExecStart=</varname></term>
247 <listitem><para>Takes a command line
248 that is executed when this service
249 shall be started up. The first token
250 of the command line must be an
251 absolute file name, then followed by
252 arguments for the process. It is
253 mandatory to set this option for all
254 services. This option may not be
255 specified more than once, except when
256 <varname>Type=oneshot</varname> is
257 used in which case more than one
258 <varname>ExecStart=</varname> line is
259 accepted which are then invoked one by
260 one, sequentially in the order they
261 appear in the unit file.</para>
262
263 <para>Optionally, if the absolute file
264 name is prefixed with
265 <literal>@</literal>, the second token
266 will be passed as
267 <literal>argv[0]</literal> to the
268 executed process, followed by the
269 further arguments specified. If the
270 first token is prefixed with
271 <literal>-</literal> an exit code of
272 the command normally considered a
273 failure (i.e. non-zero exit status or
274 abormal exit due to signal) is ignored
275 and considered success. If both
276 <literal>-</literal> and
277 <literal>@</literal> are used for the
278 same command the former must preceed
279 the latter. Unless
280 <varname>Type=forking</varname> is
281 set, the process started via this
282 command line will be considered the
283 main process of the daemon. The
284 command line accepts % specifiers as
285 described in
286 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>. On
287 top of that basic environment variable
288 substitution is supported, where
289 <literal>${FOO}</literal> is replaced
290 by the string value of the environment
291 variable of the same name. Also
292 <literal>$FOO</literal> may appear as
293 seperate word on the command line in
294 which case the variable is replaced by
295 its value split at
296 whitespaces.</para></listitem>
297 </varlistentry>
298
299 <varlistentry>
300 <term><varname>ExecStartPre=</varname></term>
301 <term><varname>ExecStartPost=</varname></term>
302 <listitem><para>Additional commands
303 that are executed before (resp. after)
304 the command in
305 <varname>ExecStart=</varname>. Multiple
306 command lines may be concatenated in a
307 single directive, by seperating them
308 by semicolons (these semicolons must
309 be passed as seperate words). In that
310 case, the commands are executed one
311 after the other,
312 serially. Alternatively, these
313 directives may be specified more than
314 once whith the same effect. However,
315 the latter syntax is not recommended
316 for compatibility with parsers
317 suitable for XDG
318 <filename>.desktop</filename> files.
319 Use of these settings is
320 optional. Specifier and environment
321 variable substitution is
322 supported.</para></listitem>
323 </varlistentry>
324
325 <varlistentry>
326 <term><varname>ExecReload=</varname></term>
327 <listitem><para>Commands to execute to
328 trigger a configuration reload in the
329 service. This argument takes multiple
330 command lines, following the same
331 scheme as pointed out for
332 <varname>ExecStartPre=</varname>
333 above. Use of this setting is
334 optional. Specifier and environment
335 variable substitution is supported
336 here following the same scheme as for
337 <varname>ExecStart=</varname>. One
338 special environment variable is set:
339 if known <literal>$MAINPID</literal> is
340 set to the main process of the
341 daemon, and may be used for command
342 lines like the following:
343 <command>/bin/kill -HUP
344 $(MAINPID)</command>.</para></listitem>
345 </varlistentry>
346
347 <varlistentry>
348 <term><varname>ExecStop=</varname></term>
349 <listitem><para>Commands to execute to
350 stop the service started via
351 <varname>ExecStart=</varname>. This
352 argument takes multiple command lines,
353 following the same scheme as pointed
354 out for
355 <varname>ExecStartPre=</varname>
356 above. Use of this setting is
357 optional. All processes remaining for
358 a service after the commands
359 configured in this option are run are
360 terminated according to the
361 <varname>KillMode=</varname> setting
362 (see below). If this option is not
363 specified the process is terminated
364 right-away when service stop is
365 requested. Specifier and environment
366 variable substitution is supported
367 (including
368 <literal>$(MAINPID)</literal>, see
369 above).</para></listitem>
370 </varlistentry>
371
372 <varlistentry>
373 <term><varname>ExecStopPost=</varname></term>
374 <listitem><para>Additional commands
375 that are executed after the service
376 was stopped using the commands
377 configured in
378 <varname>ExecStop=</varname>. This
379 argument takes multiple command lines,
380 following the same scheme as pointed
381 out for
382 <varname>ExecStartPre</varname>. Use
383 of these settings is
384 optional. Specifier and environment
385 variable substitution is
386 supported.</para></listitem>
387 </varlistentry>
388
389 <varlistentry>
390 <term><varname>RestartSec=</varname></term>
391 <listitem><para>Configures the time to
392 sleep before restarting a service (as
393 configured with
394 <varname>Restart=</varname>). Takes a
395 unit-less value in seconds, or a time
396 span value such as "5min
397 20s". Defaults to
398 100ms.</para></listitem>
399 </varlistentry>
400
401 <varlistentry>
402 <term><varname>TimeoutSec=</varname></term>
403 <listitem><para>Configures the time to
404 wait for start-up and stop. If a
405 daemon service does not signal
406 start-up completion within the
407 configured time the service will be
408 considered failed and be shut down
409 again. If a service is asked to stop
410 but does not terminate in the
411 specified time it will be terminated
412 forcibly via SIGTERM, and after
413 another delay of this time with
414 SIGKILL. (See
415 <varname>KillMode=</varname>
416 below.) Takes a unit-less value in seconds, or a
417 time span value such as "5min
418 20s". Pass 0 to disable the timeout
419 logic. Defaults to
420 60s.</para></listitem>
421 </varlistentry>
422
423 <varlistentry>
424 <term><varname>Restart=</varname></term>
425 <listitem><para>Configures whether the
426 main service process shall be restarted when
427 it exists. Takes one of
428 <option>once</option>,
429 <option>restart-on-success</option> or
430 <option>restart-always</option>. If
431 set to <option>once</option> (the
432 default) the service will not be
433 restarted when it exits. If set to
434 <option>restart-on-success</option> it
435 will be restarted only when it exited
436 cleanly, i.e. terminated with an exit
437 code of 0. If set to
438 <option>restart-always</option> the
439 service will be restarted regardless
440 whether it exited cleanly or not, or
441 got terminated abnormally by a
442 signal.</para></listitem>
443 </varlistentry>
444
445 <varlistentry>
446 <term><varname>PermissionsStartOnly=</varname></term>
447 <listitem><para>Takes a boolean
448 argument. If true, the permission
449 related execution options as
450 configured with
451 <varname>User=</varname> and similar
452 options (see
453 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
454 for more information) are only applied
455 to the process started with
456 <varname>ExecStart=</varname>, and not
457 to the various other
458 <varname>ExecStartPre=</varname>,
459 <varname>ExecStartPost=</varname>,
460 <varname>ExecReload=</varname>,
461 <varname>ExecStop=</varname>,
462 <varname>ExecStopPost=</varname>
463 commands. If false, the setting is
464 applied to all configured commands the
465 same way. Defaults to
466 false.</para></listitem>
467 </varlistentry>
468
469 <varlistentry>
470 <term><varname>RootDirectoryStartOnly=</varname></term>
471 <listitem><para>Takes a boolean
472 argument. If true, the root directory
473 as configured with the
474 <varname>RootDirectory=</varname>
475 option (see
476 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
477 for more information) is only applied
478 to the process started with
479 <varname>ExecStart=</varname>, and not
480 to the various other
481 <varname>ExecStartPre=</varname>,
482 <varname>ExecStartPost=</varname>,
483 <varname>ExecReload=</varname>,
484 <varname>ExecStop=</varname>,
485 <varname>ExecStopPost=</varname>
486 commands. If false, the setting is
487 applied to all configured commands the
488 same way. Defaults to
489 false.</para></listitem>
490 </varlistentry>
491
492 <varlistentry>
493 <term><varname>SysVStartPriority=</varname></term>
494 <listitem><para>Set the SysV start
495 priority to use to order this service
496 in relation to SysV services lacking
497 LSB headers. This option is only
498 necessary to fix ordering in relation
499 to legacy SysV services, that have no
500 ordering information encoded in the
501 script headers. As such it should only
502 be used as temporary compatibility
503 option, and not be used in new unit
504 files. Almost always it is a better
505 choice to add explicit ordering
506 directives via
507 <varname>After=</varname> or
508 <varname>Before=</varname>,
509 instead. For more details see
510 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>. If
511 used, pass an integer value in the
512 range 0-99.</para></listitem>
513 </varlistentry>
514
515 <varlistentry>
516 <term><varname>KillMode=</varname></term>
517 <listitem><para>Specifies how
518 processes of this service shall be
519 killed. One of
520 <option>control-group</option>,
521 <option>process-group</option>,
522 <option>process</option>,
523 <option>none</option>.</para>
524
525 <para>If set to
526 <option>control-group</option> all
527 remaining processes in the control
528 group of this service will be
529 terminated on service stop, after the
530 stop command (as configured with
531 <varname>ExecStop=</varname>) is
532 executed. If set to
533 <option>process-group</option> only
534 the members of the process group of
535 the main service process are
536 killed. If set to
537 <option>process</option> only the main
538 process itself is killed. If set to
539 <option>none</option> no process is
540 killed. In this case only the stop
541 command will be executed on service
542 stop, but no process be killed
543 otherwise. Processes remaining alive
544 after stop are left in their control
545 group and the control group continues
546 to exist after stop unless it is
547 empty. Defaults to
548 <option>control-croup</option>.</para>
549
550 <para>Processes will first be
551 terminated via SIGTERM. If then after
552 a delay (configured via the
553 <varname>TimeoutSec=</varname> option)
554 processes still remain, the
555 termination request is repeated with
556 the SIGKILL signal. See
557 <citerefentry><refentrytitle>kill</refentrytitle><manvolnum>2</manvolnum></citerefentry>
558 for more
559 information.</para></listitem>
560 </varlistentry>
561
562 <varlistentry>
563 <term><varname>NonBlocking=</varname></term>
564 <listitem><para>Set O_NONBLOCK flag
565 for all file descriptors passed via
566 socket-based activation. If true, all
567 file descriptors >= 3 (i.e. all except
568 STDIN/STDOUT/STDERR) will have
569 the O_NONBLOCK flag set and hence are in
570 non-blocking mode. This option is only
571 useful in conjunction with a socket
572 unit, as described in
573 <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>. Defaults
574 to false.</para></listitem>
575 </varlistentry>
576
577 <varlistentry>
578 <term><varname>NotifyAccess=</varname></term>
579 <listitem><para>Controls access to the
580 service status notification socket, as
581 accessible via the
582 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>
583 call. Takes one of
584 <option>none</option> (the default),
585 <option>main</option> or
586 <option>all</option>. If
587 <option>none</option> no daemon status
588 updates are accepted by the service
589 processes, all status update messages
590 are ignored. If <option>main</option>
591 only service updates sent from the
592 main process of the service are
593 accepted. If <option>all</option> all
594 services updates from all members of
595 the service's control group are
596 accepted. This option must be set to
597 open access to the notification socket
598 when using
599 <varname>Type=notify</varname> (see above).</para></listitem>
600 </varlistentry>
601
602 </variablelist>
603 </refsect1>
604
605 <refsect1>
606 <title>See Also</title>
607 <para>
608 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
609 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
610 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
611 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
612 </para>
613 </refsect1>
614
615 </refentry>