]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/systemd.service.xml
91d6d094099ab99f0c37d365fc79e8c0888cd7c7
[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 </refsect1>
92
93 <refsect1>
94 <title>Options</title>
95
96 <para>Service files must include a
97 <literal>[Service]</literal> section, which carries
98 information about the service and the process it
99 supervises. A number of options that may be used in
100 this section are shared with other unit types. These
101 options are documented in
102 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>. The
103 options specific to the <literal>[Service]</literal>
104 section of service units are the following:</para>
105
106 <variablelist>
107 <varlistentry>
108 <term><varname>Type=</varname></term>
109
110 <listitem><para>Configures the process
111 start-up type for this service
112 unit. One of <option>simple</option>,
113 <option>forking</option>,
114 <option>finish</option>,
115 <option>dbus</option>,
116 <option>notify</option>.</para>
117
118 <para>If set to
119 <option>simple</option> (the default
120 value) it is expected that the process
121 configured with
122 <varname>ExecStart=</varname> is the
123 main process of the service. In this
124 mode, communication channels must be
125 installed before the daemon is started
126 up (e.g. sockets set up by systemd,
127 via socket activation), as systemd
128 will immediately proceed starting
129 follow-up units.</para>
130
131 <para>If set to
132 <option>forking</option> it is
133 expected that the process configured
134 with <varname>ExecStart=</varname>
135 will start up and call
136 <function>fork()</function>. The
137 parent process is expected to finish
138 when start-up is complete and all
139 communication channels set up. The
140 child continues to run as the main
141 daemon process. This is the behaviour
142 of traditional UNIX daemons. If this
143 setting is used, it is recommended to
144 also use the
145 <varname>PIDFile=</varname> option, so
146 that systemd can identify the main
147 process of the daemon. systemd will
148 proceed starting follow-up units as
149 soon as the parent process
150 exits.</para>
151
152 <para>Behaviour of
153 <option>finish</option> is similar
154 to <option>simple</option>, however
155 it is expected that the process has to
156 exit before systemd starts follow-up
157 units. <varname>ValidNoProcess=</varname>
158 is particularly useful for this type
159 of service.</para>
160
161 <para>Behaviour of
162 <option>dbus</option> is similar to
163 <option>simple</option>, however it is
164 expected that the daemon acquires a
165 name on the D-Bus bus, as configured
166 by
167 <varname>BusName=</varname>. systemd
168 will proceed starting follow-up units
169 after the D-Bus bus name has been
170 acquired. Service units with this
171 option configured implicitly have
172 dependencies on the
173 <filename>dbus.target</filename>
174 unit.</para>
175
176 <para>Behaviour of
177 <option>notify</option> is similar to
178 <option>simple</option>, however it is
179 expected that the daemon sends a
180 notification message via
181 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>
182 or an equivalent call when it finished
183 starting up. systemd will proceed
184 starting follow-up units after this
185 notification message has been sent. If
186 this option is used
187 <varname>NotifyAccess=</varname> (see
188 below) must be set to open access to
189 the notification socket provided by
190 systemd. If
191 <varname>NotifyAccess=</varname> is not
192 set, it will be implicitly set to
193 <option>main</option>.</para>
194 </listitem>
195 </varlistentry>
196
197 <varlistentry>
198 <term><varname>ValidNoProcess=</varname></term>
199
200 <listitem><para>Takes a boolean value
201 that specifies whether the service
202 shall be considered active even when
203 all its processes exited. Defaults to
204 <option>no</option>.</para>
205 </listitem>
206 </varlistentry>
207
208 <varlistentry>
209 <term><varname>PIDFile=</varname></term>
210
211 <listitem><para>Takes an absolute file
212 name pointing to the PID file of this
213 daemon. Use of this option is
214 recommended for services where
215 <varname>Type=</varname> is set to
216 <option>forking</option>.</para>
217 </listitem>
218 </varlistentry>
219
220 <varlistentry>
221 <term><varname>BusName=</varname></term>
222
223 <listitem><para>Takes a D-Bus bus
224 name, where this service is reachable
225 as. This option is mandatory for
226 services where
227 <varname>Type=</varname> is set to
228 <option>dbus</option>, but its use
229 is otherwise recommended as well if
230 the process takes a name on the D-Bus
231 bus.</para>
232 </listitem>
233 </varlistentry>
234
235 <varlistentry>
236 <term><varname>ExecStart=</varname></term>
237 <listitem><para>Takes a command line
238 that is executed when this service
239 shall be started up. The first token
240 of the command line must be an
241 absolute file name, then followed by
242 arguments for the process. It is
243 mandatory to set this option for all
244 services. This option may not be
245 specified more than once. Optionally,
246 if the absolute file name is prefixed
247 with <literal>@</literal>, the second
248 token will be passed as
249 <literal>argv[0]</literal> to the
250 executed process, followed by the
251 further arguments specified. Unless
252 <varname>Type=forking</varname> is set,
253 the process started via this command
254 line will be considered the main
255 process of the
256 daemon.</para></listitem>
257 </varlistentry>
258
259 <varlistentry>
260 <term><varname>ExecStartPre=</varname></term>
261 <term><varname>ExecStartPost=</varname></term>
262 <listitem><para>Additional commands
263 that are executed before (resp. after)
264 the command in
265 <varname>ExecStart=</varname>. If
266 specified more than once, all commands
267 are executed one after the other,
268 serially. Use of these settings is
269 optional.</para></listitem>
270 </varlistentry>
271
272 <varlistentry>
273 <term><varname>ExecReload=</varname></term>
274 <listitem><para>Commands to execute to
275 trigger a configuration reload in the
276 service. If used more than once, all
277 commands are executed one after the
278 other, serially. Use of this setting is optional.
279 </para></listitem>
280 </varlistentry>
281
282 <varlistentry>
283 <term><varname>ExecStop=</varname></term>
284 <listitem><para>Commands to execute to
285 stop the service started via
286 <varname>ExecStart=</varname>. If used
287 more than once, all commands are
288 executed one after the other,
289 serially. Use of this setting is
290 optional. All processes remaining for
291 a service after the commands
292 configured in this option are run are
293 terminated according to the
294 <varname>KillMode=</varname> setting
295 (see below). If this option is not
296 specified the process is terminated
297 right-away when service stop is
298 requested.</para></listitem>
299 </varlistentry>
300
301 <varlistentry>
302 <term><varname>ExecStopPost=</varname></term>
303 <listitem><para>Additional commands
304 that are executed after the service
305 was stopped using the commands
306 configured in
307 <varname>ExecStop=</varname>. If
308 specified more than once, all commands
309 are executed one after the other,
310 serially. Use of these settings is
311 optional.</para></listitem>
312 </varlistentry>
313
314 <varlistentry>
315 <term><varname>RestartSec=</varname></term>
316 <listitem><para>Configures the time to
317 sleep before restarting a service (as
318 configured with
319 <varname>Restart=</varname>). Takes a
320 unit-less value in seconds, or a time
321 span value such as "5min
322 20s". Defaults to
323 100ms.</para></listitem>
324 </varlistentry>
325
326 <varlistentry>
327 <term><varname>TimeoutSec=</varname></term>
328 <listitem><para>Configures the time to
329 wait for start-up and stop. If a
330 daemon service does not signal
331 start-up completion within the
332 configured time the service will be
333 considered failed and be shut down
334 again. If a service is asked to stop
335 but does not terminate in the
336 specified time it will be terminated
337 forcibly via SIGTERM, and after
338 another delay of this time with
339 SIGKILL. (See
340 <varname>KillMode=</varname>
341 below.) Takes a unit-less value in seconds, or a
342 time span value such as "5min
343 20s". Pass 0 to disable the timeout
344 logic. Defaults to
345 60s.</para></listitem>
346 </varlistentry>
347
348 <varlistentry>
349 <term><varname>Restart=</varname></term>
350 <listitem><para>Configures whether the
351 main service process shall be restarted when
352 it exists. Takes one of
353 <option>once</option>,
354 <option>restart-on-success</option> or
355 <option>restart-always</option>. If
356 set to <option>once</option> (the
357 default) the service will not be
358 restarted when it exits. If set to
359 <option>restart-on-success</option> it
360 will be restarted only when it exited
361 cleanly, i.e. terminated with an exit
362 code of 0. If set to
363 <option>restart-always</option> the
364 service will be restarted regardless
365 whether it exited cleanly or not, or
366 got terminated abnormally by a
367 signal.</para></listitem>
368 </varlistentry>
369
370 <varlistentry>
371 <term><varname>PermissionsStartOnly=</varname></term>
372 <listitem><para>Takes a boolean
373 argument. If true, the permission
374 related execution options as
375 configured with
376 <varname>User=</varname> and similar
377 options (see
378 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
379 for more information) are only applied
380 to the process started with
381 <varname>ExecStart=</varname>, and not
382 to the various other
383 <varname>ExecStartPre=</varname>,
384 <varname>ExecStartPost=</varname>,
385 <varname>ExecReload=</varname>,
386 <varname>ExecStop=</varname>,
387 <varname>ExecStopPost=</varname>
388 commands. If false, the setting is
389 applied to all configured commands the
390 same way. Defaults to
391 false.</para></listitem>
392 </varlistentry>
393
394 <varlistentry>
395 <term><varname>RootDirectoryStartOnly=</varname></term>
396 <listitem><para>Takes a boolean
397 argument. If true, the root directory
398 as configured with the
399 <varname>RootDirectory=</varname>
400 option (see
401 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
402 for more information) is only applied
403 to the process started with
404 <varname>ExecStart=</varname>, and not
405 to the various other
406 <varname>ExecStartPre=</varname>,
407 <varname>ExecStartPost=</varname>,
408 <varname>ExecReload=</varname>,
409 <varname>ExecStop=</varname>,
410 <varname>ExecStopPost=</varname>
411 commands. If false, the setting is
412 applied to all configured commands the
413 same way. Defaults to
414 false.</para></listitem>
415 </varlistentry>
416
417 <varlistentry>
418 <term><varname>SysVStartPriority=</varname></term>
419 <listitem><para>Set the SysV start
420 priority to use to order this service
421 in relation to SysV services lacking
422 LSB headers. This option is only
423 necessary to fix ordering in relation
424 to legacy SysV services, that have no
425 ordering information encoded in the
426 script headers. As such it should only
427 be used as temporary compatibility
428 option, and not be used in new unit
429 files. Almost always it is a better
430 choice to add explicit ordering
431 directives via
432 <varname>After=</varname> or
433 <varname>Before=</varname>,
434 instead. For more details see
435 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>. If
436 used, pass an integer value in the
437 range 0-99.</para></listitem>
438 </varlistentry>
439
440 <varlistentry>
441 <term><varname>KillMode=</varname></term>
442 <listitem><para>Specifies how
443 processes of this service shall be
444 killed. One of
445 <option>control-group</option>,
446 <option>process-group</option>,
447 <option>process</option>,
448 <option>none</option>.</para>
449
450 <para>If set to
451 <option>control-group</option> all
452 remaining processes in the control
453 group of this service will be
454 terminated on service stop, after the
455 stop command (as configured with
456 <varname>ExecStop=</varname>) is
457 executed. If set to
458 <option>process-group</option> only
459 the members of the process group of
460 the main service process are
461 killed. If set to
462 <option>process</option> only the main
463 process itself is killed. If set to
464 <option>none</option> no process is
465 killed. In this case only the stop
466 command will be executed on service
467 stop, but no process be killed
468 otherwise. Processes remaining alive
469 after stop are left in their control
470 group and the control group continues
471 to exist after stop unless it is
472 empty. Defaults to
473 <option>control-croup</option>.</para>
474
475 <para>Processes will first be
476 terminated via SIGTERM. If then after
477 a delay (configured via the
478 <varname>TimeoutSec=</varname> option)
479 processes still remain, the
480 termination request is repeated with
481 the SIGKILL signal. See
482 <citerefentry><refentrytitle>kill</refentrytitle><manvolnum>2</manvolnum></citerefentry>
483 for more
484 information.</para></listitem>
485 </varlistentry>
486
487 <varlistentry>
488 <term><varname>NonBlocking=</varname></term>
489 <listitem><para>Set O_NONBLOCK flag
490 for all file descriptors passed via
491 socket-based activation. If true, all
492 file descriptors >= 3 (i.e. all except
493 STDIN/STDOUT/STDERR) will have
494 the O_NONBLOCK flag set and hence are in
495 non-blocking mode. This option is only
496 useful in conjunction with a socket
497 unit, as described in
498 <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>. Defaults
499 to false.</para></listitem>
500 </varlistentry>
501
502 <varlistentry>
503 <term><varname>NotifyAccess=</varname></term>
504 <listitem><para>Controls access to the
505 service status notification socket, as
506 accessible via the
507 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>
508 call. Takes one of
509 <option>none</option> (the default),
510 <option>main</option> or
511 <option>all</option>. If
512 <option>none</option> no daemon status
513 updates are accepted by the service
514 processes, all status update messages
515 are ignored. If <option>main</option>
516 only service updates sent from the
517 main process of the service are
518 accepted. If <option>all</option> all
519 services updates from all members of
520 the service's control group are
521 accepted. This option must be set to
522 open access to the notification socket
523 when using
524 <varname>Type=notify</varname> (see above).</para></listitem>
525 </varlistentry>
526
527 </variablelist>
528 </refsect1>
529
530 <refsect1>
531 <title>See Also</title>
532 <para>
533 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
534 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
535 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
536 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
537 </para>
538 </refsect1>
539
540 </refentry>