1SYSTEMD.UNIT(5) systemd.unit SYSTEMD.UNIT(5)
2
3
4
6 systemd.unit - Unit configuration
7
9 service.service, socket.socket, device.device, mount.mount,
10 automount.automount, swap.swap, target.target, path.path, timer.timer,
11 snapshot.snapshot, slice.slice, scope.scope
12
13 /etc/systemd/system/*
14 /run/systemd/system/*
15 /usr/lib/systemd/system/*
16 ...
17
18
19 $XDG_CONFIG_HOME/systemd/user/*
20 $HOME/.config/systemd/user/*
21 /etc/systemd/user/*
22 $XDG_RUNTIME_DIR/systemd/user/*
23 /run/systemd/user/*
24 $XDG_DATA_HOME/systemd/user/*
25 $HOME/.local/share/systemd/user/*
26 /usr/lib/systemd/user/*
27 ...
28
29
31 A unit configuration file encodes information about a service, a
32 socket, a device, a mount point, an automount point, a swap file or
33 partition, a start-up target, a watched file system path, a timer
34 controlled and supervised by systemd(1), a temporary system state
35 snapshot, a resource management slice or a group of externally created
36 processes. The syntax is inspired by XDG Desktop Entry
37 Specification[1].desktop files, which are in turn inspired by Microsoft
38 Windows .ini files.
39
40 This man page lists the common configuration options of all the unit
41 types. These options need to be configured in the [Unit] or [Install]
42 sections of the unit files.
43
44 In addition to the generic [Unit] and [Install] sections described
45 here, each unit may have a type-specific section, e.g. [Service] for a
46 service unit. See the respective man pages for more information:
47 systemd.service(5), systemd.socket(5), systemd.device(5),
48 systemd.mount(5), systemd.automount(5), systemd.swap(5),
49 systemd.target(5), systemd.path(5), systemd.timer(5),
50 systemd.snapshot(5). systemd.slice(5). systemd.scope(5).
51
52 Various settings are allowed to be specified more than once, in which
53 case the interpretation depends on the setting. Often, multiple
54 settings form a list, and setting to an empty value "resets", which
55 means that previous assignments are ignored. When this is allowed, it
56 is mentioned in the description of the setting. Note that using
57 multiple assignments to the same value makes the unit file incompatible
58 with parsers for the XDG .desktop file format.
59
60 Unit files are loaded from a set of paths determined during
61 compilation, described in the next section.
62
63 Unit files may contain additional options on top of those listed here.
64 If systemd encounters an unknown option, it will write a warning log
65 message but continue loading the unit. If an option or section name is
66 prefixed with X-, it is ignored completely by systemd. Options within
67 an ignored section do not need the prefix. Applications may use this to
68 include additional information in the unit files.
69
70 Boolean arguments used in unit files can be written in various formats.
71 For positive settings the strings 1, yes, true and on are equivalent.
72 For negative settings, the strings 0, no, false and off are equivalent.
73
74 Time span values encoded in unit files can be written in various
75 formats. A stand-alone number specifies a time in seconds. If suffixed
76 with a time unit, the unit is honored. A concatenation of multiple
77 values with units is supported, in which case the values are added up.
78 Example: "50" refers to 50 seconds; "2min 200ms" refers to 2 minutes
79 plus 200 milliseconds, i.e. 120200ms. The following time units are
80 understood: s, min, h, d, w, ms, us. For details see systemd.time(7).
81
82 Empty lines and lines starting with # or ; are ignored. This may be
83 used for commenting. Lines ending in a backslash are concatenated with
84 the following line while reading and the backslash is replaced by a
85 space character. This may be used to wrap long lines.
86
87 Along with a unit file foo.service, the directory foo.service.wants/
88 may exist. All unit files symlinked from such a directory are
89 implicitly added as dependencies of type Wants= to the unit. This is
90 useful to hook units into the start-up of other units, without having
91 to modify their unit files. For details about the semantics of Wants=,
92 see below. The preferred way to create symlinks in the .wants/
93 directory of a unit file is with the enable command of the systemctl(1)
94 tool which reads information from the [Install] section of unit files
95 (see below). A similar functionality exists for Requires= type
96 dependencies as well, the directory suffix is .requires/ in this case.
97
98 Along with a unit file foo.service, a directory foo.service.d/ may
99 exist. All files with the suffix ".conf" from this directory will be
100 parsed after the file itself is parsed. This is useful to alter or add
101 configuration settings to a unit, without having to modify their unit
102 files. Make sure that the file that is included has the appropriate
103 section headers before any directive. Note that for instanced units
104 this logic will first look for the instance ".d/" subdirectory and read
105 its ".conf" files, followed by the template ".d/" subdirectory and
106 reads its ".conf" files.
107
108 Note that while systemd offers a flexible dependency system between
109 units it is recommended to use this functionality only sparingly and
110 instead rely on techniques such as bus-based or socket-based activation
111 which make dependencies implicit, resulting in a both simpler and more
112 flexible system.
113
114 Some unit names reflect paths existing in the file system namespace.
115 Example: a device unit dev-sda.device refers to a device with the
116 device node /dev/sda in the file system namespace. If this applies, a
117 special way to escape the path name is used, so that the result is
118 usable as part of a filename. Basically, given a path, "/" is replaced
119 by "-" and all other characters which are not ASCII alphanumerics are
120 replaced by C-style "\x2d" escapes (except that "_" is never replaced
121 and "." is only replaced when it would be the first character in the
122 escaped path). The root directory "/" is encoded as single dash, while
123 otherwise the initial and ending "/" are removed from all paths during
124 transformation. This escaping is reversible. Properly escaped paths can
125 be generated using the systemd-escape(1) command.
126
127 Optionally, units may be instantiated from a template file at runtime.
128 This allows creation of multiple units from a single configuration
129 file. If systemd looks for a unit configuration file, it will first
130 search for the literal unit name in the file system. If that yields no
131 success and the unit name contains an "@" character, systemd will look
132 for a unit template that shares the same name but with the instance
133 string (i.e. the part between the "@" character and the suffix)
134 removed. Example: if a service getty@tty3.service is requested and no
135 file by that name is found, systemd will look for getty@.service and
136 instantiate a service from that configuration file if it is found.
137
138 To refer to the instance string from within the configuration file you
139 may use the special "%i" specifier in many of the configuration
140 options. See below for details.
141
142 If a unit file is empty (i.e. has the file size 0) or is symlinked to
143 /dev/null, its configuration will not be loaded and it appears with a
144 load state of "masked", and cannot be activated. Use this as an
145 effective way to fully disable a unit, making it impossible to start it
146 even manually.
147
148 The unit file format is covered by the Interface Stability Promise[2].
149
151 Unit files are loaded from a set of paths determined during
152 compilation, described in the two tables below. Unit files found in
153 directories listed earlier override files with the same name in
154 directories lower in the list.
155
156 Table 1. Load path when running in system mode (--system).
157 ┌────────────────────────┬─────────────────────┐
158 │Path │ Description │
159 ├────────────────────────┼─────────────────────┤
160 │/etc/systemd/system │ Local configuration │
161 ├────────────────────────┼─────────────────────┤
162 │/run/systemd/system │ Runtime units │
163 ├────────────────────────┼─────────────────────┤
164 │/usr/lib/systemd/system │ Units of installed │
165 │ │ packages │
166 └────────────────────────┴─────────────────────┘
167
168 Additional units might be loaded into systemd ("linked") from
169 directories not on the unit load path. See the link command for
170 systemctl(1). Also, some units are dynamically created via a
171 systemd.generator(7).
172
174 Unit file may include a [Unit] section, which carries generic
175 information about the unit that is not dependent on the type of unit:
176
177 Description=
178 A free-form string describing the unit. This is intended for use in
179 UIs to show descriptive information along with the unit name. The
180 description should contain a name that means something to the end
181 user. "Apache2 Web Server" is a good example. Bad examples are
182 "high-performance light-weight HTTP server" (too generic) or
183 "Apache2" (too specific and meaningless for people who do not know
184 Apache).
185
186 Documentation=
187 A space-separated list of URIs referencing documentation for this
188 unit or its configuration. Accepted are only URIs of the types
189 "http://", "https://", "file:", "info:", "man:". For more
190 information about the syntax of these URIs, see uri(7). The URIs
191 should be listed in order of relevance, starting with the most
192 relevant. It is a good idea to first reference documentation that
193 explains what the unit's purpose is, followed by how it is
194 configured, followed by any other related documentation. This
195 option may be specified more than once, in which case the specified
196 list of URIs is merged. If the empty string is assigned to this
197 option, the list is reset and all prior assignments will have no
198 effect.
199
200 Requires=
201 Configures requirement dependencies on other units. If this unit
202 gets activated, the units listed here will be activated as well. If
203 one of the other units gets deactivated or its activation fails,
204 this unit will be deactivated. This option may be specified more
205 than once or multiple space-separated units may be specified in one
206 option in which case requirement dependencies for all listed names
207 will be created. Note that requirement dependencies do not
208 influence the order in which services are started or stopped. This
209 has to be configured independently with the After= or Before=
210 options. If a unit foo.service requires a unit bar.service as
211 configured with Requires= and no ordering is configured with After=
212 or Before=, then both units will be started simultaneously and
213 without any delay between them if foo.service is activated. Often
214 it is a better choice to use Wants= instead of Requires= in order
215 to achieve a system that is more robust when dealing with failing
216 services.
217
218 Note that dependencies of this type may also be configured outside
219 of the unit configuration file by adding a symlink to a .requires/
220 directory accompanying the unit file. For details see above.
221
222 RequiresOverridable=
223 Similar to Requires=. Dependencies listed in RequiresOverridable=
224 which cannot be fulfilled or fail to start are ignored if the
225 startup was explicitly requested by the user. If the start-up was
226 pulled in indirectly by some dependency or automatic start-up of
227 units that is not requested by the user, this dependency must be
228 fulfilled and otherwise the transaction fails. Hence, this option
229 may be used to configure dependencies that are normally honored
230 unless the user explicitly starts up the unit, in which case
231 whether they failed or not is irrelevant.
232
233 Requisite=, RequisiteOverridable=
234 Similar to Requires= and RequiresOverridable=, respectively.
235 However, if the units listed here are not started already, they
236 will not be started and the transaction will fail immediately.
237
238 Wants=
239 A weaker version of Requires=. Units listed in this option will be
240 started if the configuring unit is. However, if the listed units
241 fail to start or cannot be added to the transaction, this has no
242 impact on the validity of the transaction as a whole. This is the
243 recommended way to hook start-up of one unit to the start-up of
244 another unit.
245
246 Note that dependencies of this type may also be configured outside
247 of the unit configuration file by adding symlinks to a .wants/
248 directory accompanying the unit file. For details, see above.
249
250 BindsTo=
251 Configures requirement dependencies, very similar in style to
252 Requires=, however in addition to this behavior, it also declares
253 that this unit is stopped when any of the units listed suddenly
254 disappears. Units can suddenly, unexpectedly disappear if a service
255 terminates on its own choice, a device is unplugged or a mount
256 point unmounted without involvement of systemd.
257
258 PartOf=
259 Configures dependencies similar to Requires=, but limited to
260 stopping and restarting of units. When systemd stops or restarts
261 the units listed here, the action is propagated to this unit. Note
262 that this is a one-way dependency — changes to this unit do not
263 affect the listed units.
264
265 Conflicts=
266 A space-separated list of unit names. Configures negative
267 requirement dependencies. If a unit has a Conflicts= setting on
268 another unit, starting the former will stop the latter and vice
269 versa. Note that this setting is independent of and orthogonal to
270 the After= and Before= ordering dependencies.
271
272 If a unit A that conflicts with a unit B is scheduled to be started
273 at the same time as B, the transaction will either fail (in case
274 both are required part of the transaction) or be modified to be
275 fixed (in case one or both jobs are not a required part of the
276 transaction). In the latter case, the job that is not the required
277 will be removed, or in case both are not required, the unit that
278 conflicts will be started and the unit that is conflicted is
279 stopped.
280
281 Before=, After=
282 A space-separated list of unit names. Configures ordering
283 dependencies between units. If a unit foo.service contains a
284 setting Before=bar.service and both units are being started,
285 bar.service's start-up is delayed until foo.service is started up.
286 Note that this setting is independent of and orthogonal to the
287 requirement dependencies as configured by Requires=. It is a common
288 pattern to include a unit name in both the After= and Requires=
289 option, in which case the unit listed will be started before the
290 unit that is configured with these options. This option may be
291 specified more than once, in which case ordering dependencies for
292 all listed names are created. After= is the inverse of Before=,
293 i.e. while After= ensures that the configured unit is started after
294 the listed unit finished starting up, Before= ensures the opposite,
295 i.e. that the configured unit is fully started up before the listed
296 unit is started. Note that when two units with an ordering
297 dependency between them are shut down, the inverse of the start-up
298 order is applied. i.e. if a unit is configured with After= on
299 another unit, the former is stopped before the latter if both are
300 shut down. If one unit with an ordering dependency on another unit
301 is shut down while the latter is started up, the shut down is
302 ordered before the start-up regardless of whether the ordering
303 dependency is actually of type After= or Before=. If two units have
304 no ordering dependencies between them, they are shut down or
305 started up simultaneously, and no ordering takes place.
306
307 OnFailure=
308 A space-separated list of one or more units that are activated when
309 this unit enters the "failed" state.
310
311 PropagatesReloadTo=, ReloadPropagatedFrom=
312 A space-separated list of one or more units where reload requests
313 on this unit will be propagated to, or reload requests on the other
314 unit will be propagated to this unit, respectively. Issuing a
315 reload request on a unit will automatically also enqueue a reload
316 request on all units that the reload request shall be propagated to
317 via these two settings.
318
319 JoinsNamespaceOf=
320 For units that start processes (such as service units), lists one
321 or more other units whose network and/or temporary file namespace
322 to join. This only applies to unit types which support the
323 PrivateNetwork= and PrivateTmp= directives (see systemd.exec(5) for
324 details). If a unit that has this setting set is started, its
325 processes will see the same /tmp, /tmp/var and network namespace as
326 one listed unit that is started. If multiple listed units are
327 already started, it is not defined which namespace is joined. Note
328 that this setting only has an effect if PrivateNetwork= and/or
329 PrivateTmp= is enabled for both the unit that joins the namespace
330 and the unit whose namespace is joined.
331
332 RequiresMountsFor=
333 Takes a space-separated list of absolute paths. Automatically adds
334 dependencies of type Requires= and After= for all mount units
335 required to access the specified path.
336
337 Mount points marked with noauto are not mounted automatically and
338 will be ignored for the purposes of this option. If such a mount
339 should be a requirement for this unit, direct dependencies on the
340 mount units may be added (Requires= and After= or some other
341 combination).
342
343 OnFailureJobMode=
344 Takes a value of "fail", "replace", "replace-irreversibly",
345 "isolate", "flush", "ignore-dependencies" or "ignore-requirements".
346 Defaults to "replace". Specifies how the units listed in OnFailure=
347 will be enqueued. See systemctl(1)'s --job-mode= option for details
348 on the possible values. If this is set to "isolate", only a single
349 unit may be listed in OnFailure=..
350
351 IgnoreOnIsolate=
352 Takes a boolean argument. If true, this unit will not be stopped
353 when isolating another unit. Defaults to false.
354
355 IgnoreOnSnapshot=
356 Takes a boolean argument. If true, this unit will not be included
357 in snapshots. Defaults to true for device and snapshot units, false
358 for the others.
359
360 StopWhenUnneeded=
361 Takes a boolean argument. If true, this unit will be stopped when
362 it is no longer used. Note that in order to minimize the work to be
363 executed, systemd will not stop units by default unless they are
364 conflicting with other units, or the user explicitly requested
365 their shut down. If this option is set, a unit will be
366 automatically cleaned up if no other active unit requires it.
367 Defaults to false.
368
369 RefuseManualStart=, RefuseManualStop=
370 Takes a boolean argument. If true, this unit can only be activated
371 or deactivated indirectly. In this case, explicit start-up or
372 termination requested by the user is denied, however if it is
373 started or stopped as a dependency of another unit, start-up or
374 termination will succeed. This is mostly a safety feature to ensure
375 that the user does not accidentally activate units that are not
376 intended to be activated explicitly, and not accidentally
377 deactivate units that are not intended to be deactivated. These
378 options default to false.
379
380 AllowIsolate=
381 Takes a boolean argument. If true, this unit may be used with the
382 systemctl isolate command. Otherwise, this will be refused. It
383 probably is a good idea to leave this disabled except for target
384 units that shall be used similar to runlevels in SysV init systems,
385 just as a precaution to avoid unusable system states. This option
386 defaults to false.
387
388 DefaultDependencies=
389 Takes a boolean argument. If true, (the default), a few default
390 dependencies will implicitly be created for the unit. The actual
391 dependencies created depend on the unit type. For example, for
392 service units, these dependencies ensure that the service is
393 started only after basic system initialization is completed and is
394 properly terminated on system shutdown. See the respective man
395 pages for details. Generally, only services involved with early
396 boot or late shutdown should set this option to false. It is highly
397 recommended to leave this option enabled for the majority of common
398 units. If set to false, this option does not disable all implicit
399 dependencies, just non-essential ones.
400
401 JobTimeoutSec=, JobTimeoutAction=, JobTimeoutRebootArgument=
402 When a job for this unit is queued a time-out may be configured. If
403 this time limit is reached, the job will be cancelled, the unit
404 however will not change state or even enter the "failed" mode. This
405 value defaults to 0 (job timeouts disabled), except for device
406 units. NB: this timeout is independent from any unit-specific
407 timeout (for example, the timeout set with StartTimeoutSec= in
408 service units) as the job timeout has no effect on the unit itself,
409 only on the job that might be pending for it. Or in other words:
410 unit-specific timeouts are useful to abort unit state changes, and
411 revert them. The job timeout set with this option however is useful
412 to abort only the job waiting for the unit state to change.
413
414 JobTimeoutAction= optionally configures an additional action to
415 take when the time-out is hit. It takes the same values as the
416 per-service StartLimitAction= setting, see systemd.service(5) for
417 details. Defaults to none. JobTimeoutRebootArgument= configures an
418 optional reboot string to pass to the reboot(2) system call.
419
420 ConditionArchitecture=, ConditionVirtualization=, ConditionHost=,
421 ConditionKernelCommandLine=, ConditionSecurity=, ConditionCapability=,
422 ConditionACPower=, ConditionNeedsUpdate=, ConditionFirstBoot=,
423 ConditionPathExists=, ConditionPathExistsGlob=,
424 ConditionPathIsDirectory=, ConditionPathIsSymbolicLink=,
425 ConditionPathIsMountPoint=, ConditionPathIsReadWrite=,
426 ConditionDirectoryNotEmpty=, ConditionFileNotEmpty=,
427 ConditionFileIsExecutable=
428 Before starting a unit verify that the specified condition is true.
429 If it is not true, the starting of the unit will be skipped,
430 however all ordering dependencies of it are still respected. A
431 failing condition will not result in the unit being moved into a
432 failure state. The condition is checked at the time the queued
433 start job is to be executed.
434
435 ConditionArchitecture= may be used to check whether the system is
436 running on a specific architecture. Takes one of x86, x86-64, ppc,
437 ppc-le, ppc64, ppc64-le, ia64, parisc, parisc64, s390, s390x,
438 sparc, sparc64, mips, mips-le, mips64, mips64-le, alpha, arm,
439 arm-be, arm64, arm64-be, sh, sh64, m86k, tilegx, cris to test
440 against a specific architecture. The architecture is determined
441 from the information returned by uname(2) and is thus subject to
442 personality(2). Note that a Personality= setting in the same unit
443 file has no effect on this condition. A special architecture name
444 native is mapped to the architecture the system manager itself is
445 compiled for. The test may be negated by prepending an exclamation
446 mark.
447
448 ConditionVirtualization= may be used to check whether the system is
449 executed in a virtualized environment and optionally test whether
450 it is a specific implementation. Takes either boolean value to
451 check if being executed in any virtualized environment, or one of
452 vm and container to test against a generic type of virtualization
453 solution, or one of qemu, kvm, zvm, vmware, microsoft, oracle, xen,
454 bochs, uml, openvz, lxc, lxc-libvirt, systemd-nspawn, docker to
455 test against a specific implementation. See systemd-detect-virt(1)
456 for a full list of known virtualization technologies and their
457 identifiers. If multiple virtualization technologies are nested,
458 only the innermost is considered. The test may be negated by
459 prepending an exclamation mark.
460
461 ConditionHost= may be used to match against the hostname or machine
462 ID of the host. This either takes a hostname string (optionally
463 with shell style globs) which is tested against the locally set
464 hostname as returned by gethostname(2), or a machine ID formatted
465 as string (see machine-id(5)). The test may be negated by
466 prepending an exclamation mark.
467
468 ConditionKernelCommandLine= may be used to check whether a specific
469 kernel command line option is set (or if prefixed with the
470 exclamation mark unset). The argument must either be a single word,
471 or an assignment (i.e. two words, separated "="). In the former
472 case the kernel command line is searched for the word appearing as
473 is, or as left hand side of an assignment. In the latter case, the
474 exact assignment is looked for with right and left hand side
475 matching.
476
477 ConditionSecurity= may be used to check whether the given security
478 module is enabled on the system. Currently the recognized values
479 values are selinux, apparmor, ima, smack and audit. The test may be
480 negated by prepending an exclamation mark.
481
482 ConditionCapability= may be used to check whether the given
483 capability exists in the capability bounding set of the service
484 manager (i.e. this does not check whether capability is actually
485 available in the permitted or effective sets, see capabilities(7)
486 for details). Pass a capability name such as "CAP_MKNOD", possibly
487 prefixed with an exclamation mark to negate the check.
488
489 ConditionACPower= may be used to check whether the system has AC
490 power, or is exclusively battery powered at the time of activation
491 of the unit. This takes a boolean argument. If set to true, the
492 condition will hold only if at least one AC connector of the system
493 is connected to a power source, or if no AC connectors are known.
494 Conversely, if set to false, the condition will hold only if there
495 is at least one AC connector known and all AC connectors are
496 disconnected from a power source.
497
498 ConditionNeedsUpdate= takes one of /var or /etc as argument,
499 possibly prefixed with a "!" (for inverting the condition). This
500 condition may be used to conditionalize units on whether the
501 specified directory requires an update because /usr's modification
502 time is newer than the stamp file .updated in the specified
503 directory. This is useful to implement offline updates of the
504 vendor operating system resources in /usr that require updating of
505 /etc or /var on the next following boot. Units making use of this
506 condition should order themselves before systemd-update-
507 done.service(8), to make sure they run before the stamp files's
508 modification time gets reset indicating a completed update.
509
510 ConditionFirstBoot= takes a boolean argument. This condition may be
511 used to conditionalize units on whether the system is booting up
512 with an unpopulated /etc directory. This may be used to populate
513 /etc on the first boot after factory reset, or when a new system
514 instances boots up for the first time.
515
516 With ConditionPathExists= a file existence condition is checked
517 before a unit is started. If the specified absolute path name does
518 not exist, the condition will fail. If the absolute path name
519 passed to ConditionPathExists= is prefixed with an exclamation mark
520 ("!"), the test is negated, and the unit is only started if the
521 path does not exist.
522
523 ConditionPathExistsGlob= is similar to ConditionPathExists=, but
524 checks for the existence of at least one file or directory matching
525 the specified globbing pattern.
526
527 ConditionPathIsDirectory= is similar to ConditionPathExists= but
528 verifies whether a certain path exists and is a directory.
529
530 ConditionPathIsSymbolicLink= is similar to ConditionPathExists= but
531 verifies whether a certain path exists and is a symbolic link.
532
533 ConditionPathIsMountPoint= is similar to ConditionPathExists= but
534 verifies whether a certain path exists and is a mount point.
535
536 ConditionPathIsReadWrite= is similar to ConditionPathExists= but
537 verifies whether the underlying file system is readable and
538 writable (i.e. not mounted read-only).
539
540 ConditionDirectoryNotEmpty= is similar to ConditionPathExists= but
541 verifies whether a certain path exists and is a non-empty
542 directory.
543
544 ConditionFileNotEmpty= is similar to ConditionPathExists= but
545 verifies whether a certain path exists and refers to a regular file
546 with a non-zero size.
547
548 ConditionFileIsExecutable= is similar to ConditionPathExists= but
549 verifies whether a certain path exists, is a regular file and
550 marked executable.
551
552 If multiple conditions are specified, the unit will be executed if
553 all of them apply (i.e. a logical AND is applied). Condition checks
554 can be prefixed with a pipe symbol (|) in which case a condition
555 becomes a triggering condition. If at least one triggering
556 condition is defined for a unit, then the unit will be executed if
557 at least one of the triggering conditions apply and all of the
558 non-triggering conditions. If you prefix an argument with the pipe
559 symbol and an exclamation mark, the pipe symbol must be passed
560 first, the exclamation second. Except for
561 ConditionPathIsSymbolicLink=, all path checks follow symlinks. If
562 any of these options is assigned the empty string, the list of
563 conditions is reset completely, all previous condition settings (of
564 any kind) will have no effect.
565
566 AssertArchitecture=, AssertVirtualization=, AssertHost=,
567 AssertKernelCommandLine=, AssertSecurity=, AssertCapability=,
568 AssertACPower=, AssertNeedsUpdate=, AssertFirstBoot=,
569 AssertPathExists=, AssertPathExistsGlob=, AssertPathIsDirectory=,
570 AssertPathIsSymbolicLink=, AssertPathIsMountPoint=,
571 AssertPathIsReadWrite=, AssertDirectoryNotEmpty=, AssertFileNotEmpty=,
572 AssertFileIsExecutable=
573 Similar to the ConditionArchitecture=, ConditionVirtualization=,
574 ... condition settings described above these settings add assertion
575 checks to the start-up of the unit. However, unlike the conditions
576 settings any assertion setting that is not met results in failure
577 of the start job it was triggered by.
578
579 SourcePath=
580 A path to a configuration file this unit has been generated from.
581 This is primarily useful for implementation of generator tools that
582 convert configuration from an external configuration file format
583 into native unit files. This functionality should not be used in
584 normal units.
585
587 Unit file may include an "[Install]" section, which carries
588 installation information for the unit. This section is not interpreted
589 by systemd(1) during runtime. It is used exclusively by the enable and
590 disable commands of the systemctl(1) tool during installation of a
591 unit:
592
593 Alias=
594 A space-separated list of additional names this unit shall be
595 installed under. The names listed here must have the same suffix
596 (i.e. type) as the unit file name. This option may be specified
597 more than once, in which case all listed names are used. At
598 installation time, systemctl enable will create symlinks from these
599 names to the unit filename.
600
601 WantedBy=, RequiredBy=
602 This option may be used more than once, or a space-separated list
603 of unit names may be given. A symbolic link is created in the
604 .wants/ or .requires/ directory of each of the listed units when
605 this unit is installed by systemctl enable. This has the effect
606 that a dependency of type Wants= or Requires= is added from the
607 listed unit to the current unit. The primary result is that the
608 current unit will be started when the listed unit is started. See
609 the description of Wants= and Requires= in the [Unit] section for
610 details.
611
612 WantedBy=foo.service in a service bar.service is mostly equivalent
613 to Alias=foo.service.wants/bar.service in the same file. In case of
614 template units, systemctl enable must be called with an instance
615 name, and this instance will be added to the .wants/ or .requires/
616 list of the listed unit. E.g. WantedBy=getty.target in a service
617 getty@.service will result in systemctl enable getty@tty2.service
618 creating a getty.target.wants/getty@tty2.service link to
619 getty@.service.
620
621 Also=
622 Additional units to install/deinstall when this unit is
623 installed/deinstalled. If the user requests
624 installation/deinstallation of a unit with this option configured,
625 systemctl enable and systemctl disable will automatically
626 install/uninstall units listed in this option as well.
627
628 This option may be used more than once, or a space-separated list
629 of unit names may be given.
630
631 DefaultInstance=
632 In template unit files, this specifies for which instance the unit
633 shall be enabled if the template is enabled without any explicitly
634 set instance. This option has no effect in non-template unit files.
635 The specified string must be usable as instance identifier.
636
637 The following specifiers are interpreted in the Install section: %n,
638 %N, %p, %i, %U, %u, %m, %H, %b, %v. For their meaning see the next
639 section.
640
642 Many settings resolve specifiers which may be used to write generic
643 unit files referring to runtime or unit parameters that are replaced
644 when the unit files are loaded. The following specifiers are
645 understood:
646
647 Table 2. Specifiers available in unit files
648 ┌──────────┬─────────────────────┬─────────────────────────┐
649 │Specifier │ Meaning │ Details │
650 ├──────────┼─────────────────────┼─────────────────────────┤
651 │"%n" │ Full unit name │ │
652 ├──────────┼─────────────────────┼─────────────────────────┤
653 │"%N" │ Unescaped full unit │ Same as "%n", but │
654 │ │ name │ with escaping │
655 │ │ │ undone │
656 ├──────────┼─────────────────────┼─────────────────────────┤
657 │"%p" │ Prefix name │ For instantiated │
658 │ │ │ units, this refers │
659 │ │ │ to the string │
660 │ │ │ before the "@" │
661 │ │ │ character of the │
662 │ │ │ unit name. For │
663 │ │ │ non-instantiated │
664 │ │ │ units, this refers │
665 │ │ │ to the name of the │
666 │ │ │ unit with the type │
667 │ │ │ suffix removed. │
668 ├──────────┼─────────────────────┼─────────────────────────┤
669 │"%P" │ Unescaped prefix │ Same as "%p", but │
670 │ │ name │ with escaping │
671 │ │ │ undone │
672 ├──────────┼─────────────────────┼─────────────────────────┤
673 │"%i" │ Instance name │ For instantiated │
674 │ │ │ units: this is the │
675 │ │ │ string between the │
676 │ │ │ "@" character and │
677 │ │ │ the suffix of the │
678 │ │ │ unit name. │
679 ├──────────┼─────────────────────┼─────────────────────────┤
680 │"%I" │ Unescaped instance │ Same as "%i", but │
681 │ │ name │ with escaping │
682 │ │ │ undone │
683 ├──────────┼─────────────────────┼─────────────────────────┤
684 │"%f" │ Unescaped filename │ This is either the │
685 │ │ │ unescaped instance │
686 │ │ │ name (if │
687 │ │ │ applicable) with / │
688 │ │ │ prepended (if │
689 │ │ │ applicable), or the │
690 │ │ │ prefix name │
691 │ │ │ prepended with /. │
692 ├──────────┼─────────────────────┼─────────────────────────┤
693 │"%c" │ Control group path │ This path does not │
694 │ │ of the unit │ include the │
695 │ │ │ /sys/fs/cgroup/systemd/ │
696 │ │ │ prefix. │
697 ├──────────┼─────────────────────┼─────────────────────────┤
698 │"%r" │ Control group path │ This usually maps to │
699 │ │ of the slice the │ the parent cgroup path │
700 │ │ unit is placed in │ of "%c". │
701 ├──────────┼─────────────────────┼─────────────────────────┤
702 │"%R" │ Root control group │ For system instances, │
703 │ │ path below which │ this resolves to /, │
704 │ │ slices and units │ except in containers, │
705 │ │ are placed │ where this maps to the │
706 │ │ │ container's root │
707 │ │ │ control group path. │
708 ├──────────┼─────────────────────┼─────────────────────────┤
709 │"%t" │ Runtime directory │ This is either /run │
710 │ │ │ (for the system │
711 │ │ │ manager) or the path │
712 │ │ │ "$XDG_RUNTIME_DIR" │
713 │ │ │ resolves to (for user │
714 │ │ │ managers). │
715 ├──────────┼─────────────────────┼─────────────────────────┤
716 │"%u" │ User name │ This is the name of the │
717 │ │ │ configured user of the │
718 │ │ │ unit, or (if none is │
719 │ │ │ set) the user running │
720 │ │ │ the systemd instance. │
721 ├──────────┼─────────────────────┼─────────────────────────┤
722 │"%U" │ User UID │ This is the numeric UID │
723 │ │ │ of the configured user │
724 │ │ │ of the unit, or (if │
725 │ │ │ none is set) the user │
726 │ │ │ running the systemd │
727 │ │ │ user instance. Note │
728 │ │ │ that this specifier is │
729 │ │ │ not available for units │
730 │ │ │ run by the systemd │
731 │ │ │ system instance (as │
732 │ │ │ opposed to those run by │
733 │ │ │ a systemd user │
734 │ │ │ instance), unless the │
735 │ │ │ user has been │
736 │ │ │ configured as a numeric │
737 │ │ │ UID in the first place │
738 │ │ │ or the configured user │
739 │ │ │ is the root user. │
740 ├──────────┼─────────────────────┼─────────────────────────┤
741 │"%h" │ User home directory │ This is the home │
742 │ │ │ directory of the │
743 │ │ │ configured user of the │
744 │ │ │ unit, or (if none is │
745 │ │ │ set) the user running │
746 │ │ │ the systemd user │
747 │ │ │ instance. Similar to │
748 │ │ │ "%U", this specifier is │
749 │ │ │ not available for units │
750 │ │ │ run by the systemd │
751 │ │ │ system instance, unless │
752 │ │ │ the configured user is │
753 │ │ │ the root user. │
754 ├──────────┼─────────────────────┼─────────────────────────┤
755 │"%s" │ User shell │ This is the shell of │
756 │ │ │ the configured user of │
757 │ │ │ the unit, or (if none │
758 │ │ │ is set) the user │
759 │ │ │ running the systemd │
760 │ │ │ user instance. Similar │
761 │ │ │ to "%U", this specifier │
762 │ │ │ is not available for │
763 │ │ │ units run by the │
764 │ │ │ systemd system │
765 │ │ │ instance, unless the │
766 │ │ │ configured user is the │
767 │ │ │ root user. │
768 ├──────────┼─────────────────────┼─────────────────────────┤
769 │"%m" │ Machine ID │ The machine ID of the │
770 │ │ │ running system, │
771 │ │ │ formatted as string. │
772 │ │ │ See machine-id(5) for │
773 │ │ │ more information. │
774 ├──────────┼─────────────────────┼─────────────────────────┤
775 │"%b" │ Boot ID │ The boot ID of the │
776 │ │ │ running system, │
777 │ │ │ formatted as string. │
778 │ │ │ See random(4) for more │
779 │ │ │ information. │
780 ├──────────┼─────────────────────┼─────────────────────────┤
781 │"%H" │ Host name │ The hostname of the │
782 │ │ │ running system at the │
783 │ │ │ point in time the unit │
784 │ │ │ configuation is loaded. │
785 ├──────────┼─────────────────────┼─────────────────────────┤
786 │"%v" │ Kernel release │ Identical to uname -r │
787 │ │ │ output │
788 ├──────────┼─────────────────────┼─────────────────────────┤
789 │"%%" │ Single percent sign │ Use "%%" in place of │
790 │ │ │ "%" to specify a single │
791 │ │ │ percent sign. │
792 └──────────┴─────────────────────┴─────────────────────────┘
793
794 Please note that specifiers "%U", "%h", "%s" are mostly useless when
795 systemd is running in system mode. PID 1 cannot query the user account
796 database for information, so the specifiers only work as shortcuts for
797 things which are already specified in a different way in the unit file.
798
800 Example 1. Allowing units to be enabled
801
802 The following snippet (highlighted) allows a unit (e.g. foo.service)
803 to be enabled via systemctl enable:
804
805 [Unit]
806 Description=Foo
807
808 [Service]
809 ExecStart=/usr/sbin/foo-daemon
810
811 [Install]
812 WantedBy=multi-user.target
813
814 After running systemctl enable, a symlink
815 /etc/systemd/system/multi-user.target.wants/foo.service linking to the
816 actual unit will be created. It tells systemd to pull in the unit when
817 starting multi-user.target. The inverse systemctl disable will remove
818 that symlink again.
819
820 Example 2. Overriding vendor settings
821
822 There are two methods of overriding vendor settings in unit files:
823 copying the unit file from /usr/lib/systemd/system to
824 /etc/systemd/system and modifying the chosen settings. Alternatively,
825 one can create a directory named unit.d/ within /etc/systemd/system and
826 place a drop-in file name.conf there that only changes the specific
827 settings one is interested in. Note that multiple such drop-in files
828 are read if present.
829
830 The advantage of the first method is that one easily overrides the
831 complete unit, the vendor unit is not parsed at all anymore. It has the
832 disadvantage that improvements to the unit file by the vendor are not
833 automatically incorporated on updates.
834
835 The advantage of the second method is that one only overrides the
836 settings one specifically wants, where updates to the unit by the
837 vendor automatically apply. This has the disadvantage that some future
838 updates by the vendor might be incompatible with the local changes.
839
840 Note that for drop-in files, if one wants to remove entries from a
841 setting that is parsed as a list (and is not a dependency), such as
842 ConditionPathExists= (or e.g. ExecStart= in service units), one needs
843 to first clear the list before re-adding all entries except the one
844 that is to be removed. See below for an example.
845
846 Suppose there is a vendor-supplied unit
847 /usr/lib/systemd/system/httpd.service with the following contents:
848
849 [Unit]
850 Description=Some HTTP server
851 After=remote-fs.target sqldb.service
852 Requires=sqldb.service
853 AssertPathExists=/srv/webserver
854
855 [Service]
856 Type=notify
857 ExecStart=/usr/sbin/some-fancy-httpd-server
858 Nice=5
859
860 [Install]
861 WantedBy=multi-user.target
862
863 Now one wants to change some settings as an administrator: firstly, in
864 the local setup, /srv/webserver might not exist, because the HTTP
865 server is configured to use /srv/www instead. Secondly, the local
866 configuration makes the HTTP server also depend on a memory cache
867 service, memcached.service, that should be pulled in (Requires=) and
868 also be ordered appropriately (After=). Thirdly, in order to harden the
869 service a bit more, the administrator would like to set the PrivateTmp=
870 setting (see systemd.service(5) for details). And lastly, the
871 administrator would like to reset the niceness of the service to its
872 default value of 0.
873
874 The first possibility is to copy the unit file to
875 /etc/systemd/system/httpd.service and change the chosen settings:
876
877 [Unit]
878 Description=Some HTTP server
879 After=remote-fs.target sqldb.service memcached.service
880 Requires=sqldb.service memcached.service
881 AssertPathExists=/srv/www
882
883 [Service]
884 Type=notify
885 ExecStart=/usr/sbin/some-fancy-httpd-server
886 Nice=0
887 PrivateTmp=yes
888
889 [Install]
890 WantedBy=multi-user.target
891
892 Alternatively, the administrator could create a drop-in file
893 /etc/systemd/system/httpd.service.d/local.conf with the following
894 contents:
895
896 [Unit]
897 After=memcached.service
898 Requires=memcached.service
899 # Reset all assertions and then re-add the condition we want
900 AssertPathExists=
901 AssertPathExists=/srv/www
902
903 [Service]
904 Nice=0
905 PrivateTmp=yes
906
907 Note that dependencies (After=, etc.) cannot be reset to an empty list,
908 so dependencies can only be added in drop-ins. If you want to remove
909 dependencies, you have to override the entire unit.
910
912 systemd(1), systemctl(1), systemd.special(7), systemd.service(5),
913 systemd.socket(5), systemd.device(5), systemd.mount(5),
914 systemd.automount(5), systemd.swap(5), systemd.target(5),
915 systemd.path(5), systemd.timer(5), systemd.snapshot(5),
916 systemd.scope(5), systemd.slice(5), systemd.time(7), systemd-
917 analyze(1), capabilities(7), systemd.directives(7), uname(1)
918
920 1. XDG Desktop Entry Specification
921 http://standards.freedesktop.org/desktop-entry-spec/latest/
922
923 2. Interface Stability Promise
924 http://www.freedesktop.org/wiki/Software/systemd/InterfaceStabilityPromise
925
926
927
928systemd 219 SYSTEMD.UNIT(5)