chiark / gitweb /
unit: trim cgroups when going down
[elogind.git] / man / systemd.unit.xml
1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3         "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4
5 <!--
6   This file is part of systemd.
7
8   Copyright 2010 Lennart Poettering
9
10   systemd is free software; you can redistribute it and/or modify it
11   under the terms of the GNU General Public License as published by
12   the Free Software Foundation; either version 2 of the License, or
13   (at your option) any later version.
14
15   systemd is distributed in the hope that it will be useful, but
16   WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18   General Public License for more details.
19
20   You should have received a copy of the GNU General Public License
21   along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 -->
23
24 <refentry id="systemd.unit">
25
26         <refentryinfo>
27                 <title>systemd.unit</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.unit</refentrytitle>
42                 <manvolnum>5</manvolnum>
43         </refmeta>
44
45         <refnamediv>
46                 <refname>systemd.unit</refname>
47                 <refpurpose>systemd unit configuration files</refpurpose>
48         </refnamediv>
49
50         <refsynopsisdiv>
51                 <para><filename>systemd.service</filename>,
52                 <filename>systemd.socket</filename>,
53                 <filename>systemd.device</filename>,
54                 <filename>systemd.mount</filename>,
55                 <filename>systemd.automount</filename>,
56                 <filename>systemd.swap</filename>,
57                 <filename>systemd.target</filename>,
58                 <filename>systemd.path</filename>,
59                 <filename>systemd.timer</filename>,
60                 <filename>systemd.snapshot</filename></para>
61         </refsynopsisdiv>
62
63         <refsect1>
64                 <title>Description</title>
65
66                 <para>A unit configuration file encodes information
67                 about a service, a socket, a device, a mount point, an
68                 automount point, a swap file or partition, a start-up
69                 target, a file system path or a timer controlled and
70                 supervised by
71                 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>. The
72                 syntax is inspired by <ulink
73                 url="http://standards.freedesktop.org/desktop-entry-spec/latest/">XDG
74                 Desktop Entry Specification</ulink> <filename>.desktop</filename> files, which are in turn
75                 inspired by Microsoft Windows
76                 <filename>.ini</filename> files.</para>
77
78                 <para>This man pages lists the common configuration
79                 options of all the unit types. These options need to
80                 be configured in the [Unit] resp. [Install]
81                 section of the unit files.</para>
82
83                 <para>In addition to the generic [Unit] and [Install]
84                 sections described here, each unit should have a
85                 type-specific section, e.g. [Service] for a service
86                 unit. See the respective man pages for more
87                 information.</para>
88
89                 <para>Unit files may contain additional options on top
90                 of those listed here. If systemd encounters an unknown
91                 option it will write a warning log message but
92                 continue loading the unit. If an option is prefixed
93                 with <option>X-</option> it is ignored completely by
94                 systemd. Applications may use this to include
95                 additional information in the unit files.</para>
96
97                 <para>Boolean arguments used in unit files can be
98                 written in various formats. For positive settings the
99                 strings <option>1</option>, <option>yes</option>,
100                 <option>true</option> and <option>on</option> are
101                 equivalent. For negative settings the strings
102                 <option>0</option>, <option>no</option>,
103                 <option>false</option> and <option>off</option> are
104                 equivalent.</para>
105
106                 <para>Time span values encoded in unit files can be
107                 written in various formats. A stand-alone number
108                 specifies a time in seconds. If suffixed with a time
109                 unit, the unit is honored. A concatenation of
110                 multiple values with units is supported, in which case
111                 the values are added up. Example: "50" refers to 50
112                 seconds; "2min 200ms" refers to 2 minutes plus 200
113                 milliseconds, i.e. 120200ms. The following time units
114                 are understood: s, min, h, d, w, ms, us.</para>
115
116                 <para>Empty lines and lines starting with # or ; are
117                 ignored. This may be used for commenting. Lines ending
118                 in a backslash are concatenated with the following
119                 line while reading and the backslash is replaced by a
120                 space character. This may be used to wrap long lines.</para>
121
122                 <para>If a line starts with <option>.include</option>
123                 followed by a file name, the specified file will be
124                 read as if its contents were listed in place of the
125                 <option>.include</option> directive.</para>
126
127                 <para>Along with a unit file
128                 <filename>foo.service</filename> a directory
129                 <filename>foo.service.wants/</filename> may exist. All
130                 units symlinked from such a directory are implicitly
131                 added as dependencies of type
132                 <varname>Wanted=</varname> to the unit. This is useful
133                 to hook units into the start-up of other units,
134                 without having to modify their unit configuration
135                 files. For details about the semantics of
136                 <varname>Wanted=</varname> see below. The preferred
137                 way to create symlinks in the
138                 <filename>.wants/</filename> directory of a service is
139                 with the
140                 <citerefentry><refentrytitle>systemd-install</refentrytitle><manvolnum>1</manvolnum></citerefentry>
141                 tool which reads information from the [Install]
142                 section of unit files. (See below.)</para>
143
144                 <para>Note that while systemd offers a flexible
145                 dependency system between units it is recommended to
146                 use this functionality only sparsely and instead rely
147                 on techniques such as bus-based or socket-based
148                 activation which makes dependencies implicit, which
149                 both results in a simpler and more flexible
150                 system.</para>
151
152                 <para>Some unit names reflect paths existing in the
153                 file system name space. Example: a device unit
154                 <filename>dev-sda.device</filename> refers to a device
155                 with the device node <filename>/dev/sda</filename> in
156                 the file system namespace. If this applies a special
157                 way to escape the path name is used, so that the
158                 result is usable as part of a file name. Basically,
159                 given a path, "/" is replaced by "-", and all
160                 unprintable characters and the "-" are replaced by
161                 C-style "\x20" escapes. The root directory "/" is
162                 encoded as single dash, while otherwise the initial
163                 and ending "/" is removed from all paths during
164                 transformation. This escaping is reversible.</para>
165
166                 <para>Optionally, units may be instantiated from a
167                 template file at runtime. This allows creation of
168                 multiple units from a single configuration file. If
169                 systemd looks for a unit configuration file it will
170                 first search for the literal unit name in the
171                 filesystem. If that yields no success and the unit
172                 name contains an @ character, systemd will look for a
173                 unit template that shares the same name but with the
174                 instance string (i.e. the part between the @ character
175                 and the suffix) removed. Example: if a service
176                 <filename>getty@tty3.service</filename> is requested
177                 and no file by that name is found, systemd will look
178                 for <filename>getty@.service</filename> and
179                 instantiate a service from that configuration file if
180                 it is found. To refer to the instance string from
181                 within the configuration file you may use the special
182                 <literal>%i</literal> specifier in many of the
183                 configuration options. Other specifiers that may be
184                 used are <literal>%n</literal>, <literal>%N</literal>,
185                 <literal>%p</literal>, <literal>%P</literal> and
186                 <literal>%I</literal>, for the full unit name, the
187                 unescaped unit name, the prefix name, the unescaped
188                 prefix name and the unescaped instance name,
189                 respectively. The prefix name here refers to the
190                 string before the @, i.e. "getty" in the example
191                 above, where "tty3" is the instance name.</para>
192         </refsect1>
193
194         <refsect1>
195                 <title>Options</title>
196
197                 <para>Unit file may include a [Unit] section, which
198                 carries generic information about the unit that is not
199                 dependent on the type of unit:</para>
200
201                 <variablelist>
202                         <varlistentry>
203                                 <term><varname>Names=</varname></term>
204
205                                 <listitem><para>Additional names for
206                                 this unit. The names listed here must
207                                 have the same suffix (i.e. type) as
208                                 the unit file name. This option may be
209                                 specified more than once, in which
210                                 case all listed names are used. Note
211                                 that this option is different from the
212                                 <varname>Alias=</varname> option from
213                                 the [Install] section mentioned
214                                 below. See below for details.</para>
215                                 </listitem>
216                         </varlistentry>
217
218                         <varlistentry>
219                                 <term><varname>Description=</varname></term>
220                                 <listitem><para>A free-form string
221                                 describing the unit. This is intended
222                                 for use in UIs to show descriptive
223                                 information along with the unit
224                                 name.</para></listitem>
225                         </varlistentry>
226
227                         <varlistentry>
228                                 <term><varname>Requires=</varname></term>
229
230                                 <listitem><para>Configures requirement
231                                 dependencies on other units. If this
232                                 unit gets activated, the units listed
233                                 here will be activated as well. If one
234                                 of the other units gets deactivated or
235                                 its activation fails, this unit will
236                                 be deactivated. This option may be
237                                 specified more than once, in which
238                                 case requirement dependencies for all
239                                 listed names are created. Note that
240                                 requirement dependencies do not
241                                 influence the order in which services
242                                 are started or stopped. This has to be
243                                 configured independently with the
244                                 <varname>After=</varname> or
245                                 <varname>Before=</varname> options. If
246                                 a unit
247                                 <filename>foo.service</filename>
248                                 requires a unit
249                                 <filename>bar.service</filename> as
250                                 configured with
251                                 <varname>Requires=</varname> and no
252                                 ordering is configured with
253                                 <varname>After=</varname> or
254                                 <varname>Before=</varname>, then both
255                                 units will be started simultaneously
256                                 and without any delay between them if
257                                 <filename>foo.service</filename> is
258                                 activated. Often it is a better choice
259                                 to use <varname>Wants=</varname>
260                                 instead of
261                                 <varname>Requires=</varname> in order
262                                 to achieve a system that is more
263                                 robust when dealing with failing
264                                 services.</para></listitem>
265                         </varlistentry>
266
267
268                         <varlistentry>
269                                 <term><varname>RequiresOverridable=</varname></term>
270
271                                 <listitem><para>Similar to
272                                 <varname>Requires=</varname>.
273                                 Dependencies listed in
274                                 <varname>RequiresOverridable=</varname>
275                                 which cannot be fulfilled or fail to
276                                 start are ignored if the startup was
277                                 explicitly requested by the user. If
278                                 the start-up was pulled in indirectly
279                                 by some dependency or automatic
280                                 start-up of units that is not
281                                 requested by the user this dependency
282                                 must be fulfilled and otherwise the
283                                 transaction fails. Hence, this option
284                                 may be used to configure dependencies
285                                 that are normally honored unless the
286                                 user explicitly starts up the unit, in
287                                 which case whether they failed or not
288                                 is irrelevant.</para></listitem>
289
290                         </varlistentry>
291                         <varlistentry>
292                                 <term><varname>Requisite=</varname></term>
293                                 <term><varname>RequisiteOverridable=</varname></term>
294
295                                 <listitem><para>Similar to
296                                 <varname>Requires=</varname>
297                                 resp. <varname>RequiresOverridable=</varname>. However,
298                                 if a unit listed here is not started
299                                 already it will not be started and the
300                                 transaction fails
301                                 immediately.</para></listitem>
302                         </varlistentry>
303
304                         <varlistentry>
305                                 <term><varname>Wants=</varname></term>
306
307                                 <listitem><para>A weaker version of
308                                 <varname>Requires=</varname>. A unit
309                                 listed in this option will be started
310                                 if the configuring unit is. However,
311                                 if the listed unit fails to start up
312                                 or cannot be added to the transaction
313                                 this has no impact on the validity of
314                                 the transaction as a whole. This is
315                                 the recommended way to hook start-up
316                                 of one unit to the start-up of another
317                                 unit. Note that dependencies of this
318                                 type may also be configured outside of
319                                 the unit configuration file by
320                                 adding a symlink to a
321                                 <filename>.wants/</filename> directory
322                                 accompanying the unit file. For
323                                 details see above.</para></listitem>
324                         </varlistentry>
325
326                         <varlistentry>
327                                 <term><varname>Conflicts=</varname></term>
328
329                                 <listitem><para>Configures negative
330                                 requirement dependencies. If a unit
331                                 has a
332                                 <varname>Conflicts=</varname> setting
333                                 on another unit, starting the former
334                                 will stop the latter and vice
335                                 versa. Note that this setting is
336                                 independent of and orthogonal to the
337                                 <varname>After=</varname> and
338                                 <varname>Before=</varname> ordering
339                                 dependencies.</para></listitem>
340                         </varlistentry>
341
342                         <varlistentry>
343                                 <term><varname>Before=</varname></term>
344                                 <term><varname>After=</varname></term>
345
346                                 <listitem><para>Configures ordering
347                                 dependencies between units. If a unit
348                                 <filename>foo.service</filename>
349                                 contains a setting
350                                 <option>Before=bar.service</option>
351                                 and both units are being started,
352                                 <filename>bar.service</filename>'s
353                                 start-up is delayed until
354                                 <filename>foo.service</filename> is
355                                 started up. Note that this setting is
356                                 independent of and orthogonal to the
357                                 requirement dependencies as configured
358                                 by <varname>Requires=</varname>. It is
359                                 a common pattern to include a unit
360                                 name in both the
361                                 <varname>After=</varname> and
362                                 <varname>Requires=</varname> option in
363                                 which case the unit listed will be
364                                 started before the unit that is
365                                 configured with these options. This
366                                 option may be specified more than
367                                 once, in which case ordering
368                                 dependencies for all listed names are
369                                 created. <varname>After=</varname> is
370                                 the inverse of
371                                 <varname>Before=</varname>, i.e. while
372                                 <varname>After=</varname> ensures that
373                                 the configured unit is started after
374                                 the listed unit finished starting up,
375                                 <varname>Before=</varname> ensures the
376                                 opposite, i.e.  that the configured
377                                 unit is fully started up before the
378                                 listed unit is started. Note that when
379                                 two units with an ordering dependency
380                                 between them are shut down, the
381                                 inverse of the start-up order is
382                                 applied. i.e. if a unit is configured
383                                 with <varname>After=</varname> on
384                                 another unit, the former is stopped
385                                 before the latter if both are shut
386                                 down. If one unit with an ordering
387                                 dependency on another unit is shut
388                                 down while the latter is started up,
389                                 the shut down is ordered before the
390                                 start-up regardless whether the
391                                 ordering dependency is actually of
392                                 type <varname>After=</varname> or
393                                 <varname>Before=</varname>. If two
394                                 units have no ordering dependencies
395                                 between them they are shut down
396                                 resp. started up simultaneously, and
397                                 no ordering takes
398                                 place. </para></listitem>
399                         </varlistentry>
400
401                         <varlistentry>
402                                 <term><varname>RecursiveStop=</varname></term>
403
404                                 <listitem><para>Takes a boolean
405                                 argument. If <option>true</option> and
406                                 the unit stops without being requested
407                                 by the user, all units
408                                 depending on it will be stopped as
409                                 well. (e.g. if a service exits or
410                                 crashes on its own behalf, units using
411                                 it will be stopped) Note that normally
412                                 if a unit stops without a user request,
413                                 units depending on it will not be
414                                 terminated. Only if the user requested
415                                 shutdown of a unit, all units depending
416                                 on that unit will be shut down as well
417                                 and at the same time. Defaults to
418                                 <option>false</option>.</para></listitem>
419                         </varlistentry>
420
421                         <varlistentry>
422                                 <term><varname>StopWhenUnneeded=</varname></term>
423
424                                 <listitem><para>Takes a boolean
425                                 argument. If <option>true</option>
426                                 this unit will be stopped when it is
427                                 no longer used. Note that in order to
428                                 minimize the work to be executed,
429                                 systemd will not stop units by default
430                                 unless they are conflicting with other
431                                 units, or the user explicitly
432                                 requested their shut down. If this
433                                 option is set, a unit will be
434                                 automatically cleaned up if no other
435                                 active unit requires it. Defaults to
436                                 <option>false</option>.</para></listitem>
437                         </varlistentry>
438
439                         <varlistentry>
440                                 <term><varname>OnlyByDependency=</varname></term>
441
442                                 <listitem><para>Takes a boolean
443                                 argument. If <option>true</option>
444                                 this unit can only be activated
445                                 indirectly. In this case explicit
446                                 start-up requested by the user is
447                                 denied, however if it is started as a
448                                 dependency of another unit, start-up
449                                 will succeed. This is mostly a safety
450                                 feature to ensure that the user does
451                                 not accidentally activate units that are
452                                 not intended to be activated
453                                 explicitly. This option defaults to
454                                 <option>false</option>.</para></listitem>
455                         </varlistentry>
456
457                         <varlistentry>
458                                 <term><varname>DefaultDependencies=</varname></term>
459
460                                 <listitem><para>Takes a boolean
461                                 argument. If <option>true</option>
462                                 (the default), a few default
463                                 dependencies will implicitly be
464                                 created for the unit. The actual
465                                 dependencies created depend on the
466                                 unit type. For example, for service
467                                 units, these dependencies ensure that
468                                 the service is started only after
469                                 basic system initialization is
470                                 completed and is properly terminated on
471                                 system shutdown. See the respective
472                                 man pages for details. Generally, only
473                                 services involved with early boot or
474                                 late shutdown should set this option
475                                 to <option>false</option>. It is
476                                 highly recommended to leave this
477                                 option enabled for the majority of
478                                 common units. If set to
479                                 <option>false</option> this option
480                                 does not disable all implicit
481                                 dependencies, just non-essential
482                                 ones.</para></listitem>
483                         </varlistentry>
484
485                 </variablelist>
486
487                 <para>Unit file may include a [Install] section, which
488                 carries installation information for the unit. This
489                 section is not interpreted by
490                 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>
491                 during runtime. It is used exclusively by the
492                 <citerefentry><refentrytitle>systemd-install</refentrytitle><manvolnum>1</manvolnum></citerefentry>
493                 tool during installation of a unit:</para>
494
495                 <variablelist>
496                         <varlistentry>
497                                 <term><varname>Alias=</varname></term>
498
499                                 <listitem><para>Additional names this
500                                 unit shall be installed under. The
501                                 names listed here must have the same
502                                 suffix (i.e. type) as the unit file
503                                 name. This option may be specified
504                                 more than once, in which case all
505                                 listed names are used. At installation
506                                 time,
507                                 <command>systemd-install</command>
508                                 will create symlinks from these names
509                                 to the unit file name. Note that this
510                                 is different from the
511                                 <varname>Names=</varname> option from
512                                 the [Unit] section mentioned above:
513                                 The names from
514                                 <varname>Names=</varname> apply
515                                 unconditionally if the unit is
516                                 loaded. The names from
517                                 <varname>Alias=</varname> apply only
518                                 if the unit has actually been
519                                 installed with the
520                                 <command>systemd-install</command>
521                                 tool.  Also, if systemd searches for a
522                                 unit, it will discover symlinked alias
523                                 names as configured with
524                                 <varname>Alias=</varname>, but not
525                                 names configured with
526                                 <varname>Names=</varname> only. It is
527                                 a common pattern to list a name in
528                                 both options. In this case, a unit
529                                 will be active under all names if
530                                 installed, but also if not installed
531                                 but requested explicitly under its
532                                 main name.</para></listitem>
533                         </varlistentry>
534
535                         <varlistentry>
536                                 <term><varname>WantedBy=</varname></term>
537
538                                 <listitem><para>Installs a symlink in
539                                 the <filename>.wants/</filename>
540                                 subdirectory for a unit. This has the
541                                 effect that when the listed unit name
542                                 is activated the unit listing it is
543                                 activated
544                                 too. <command>WantedBy=foo.service</command>
545                                 in a service
546                                 <filename>bar.service</filename> is
547                                 mostly equivalent to
548                                 <command>Alias=foo.service.wants/bar.service</command>
549                                 in the same file.</para></listitem>
550                         </varlistentry>
551
552                         <varlistentry>
553                                 <term><varname>Also=</varname></term>
554
555                                 <listitem><para>Additional units to
556                                 install when this unit is
557                                 installed. If the user requests
558                                 installation of a unit with this
559                                 option configured,
560                                 <command>systemd-install</command>
561                                 will automatically install units
562                                 listed in this option as
563                                 well.</para></listitem>
564                         </varlistentry>
565                 </variablelist>
566
567         </refsect1>
568
569         <refsect1>
570                 <title>See Also</title>
571                 <para>
572                         <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
573                         <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
574                         <citerefentry><refentrytitle>systemd-install</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
575                         <citerefentry><refentrytitle>systemd.special</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
576                         <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
577                         <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
578                         <citerefentry><refentrytitle>systemd.device</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
579                         <citerefentry><refentrytitle>systemd.mount</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
580                         <citerefentry><refentrytitle>systemd.automount</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
581                         <citerefentry><refentrytitle>systemd.swap</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
582                         <citerefentry><refentrytitle>systemd.target</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
583                         <citerefentry><refentrytitle>systemd.path</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
584                         <citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
585                         <citerefentry><refentrytitle>systemd.snapshot</refentrytitle><manvolnum>5</manvolnum></citerefentry>
586                 </para>
587         </refsect1>
588
589 </refentry>