SYSTEMD.UNIT(5)

๐Ÿ’– systemd.unit(5) โ€” Unit configuration ๐Ÿ’–

okay bestie, welcome to systemd.unit(5), the manual page that spills the tea on Unit configuration. This is the group chat where every .service, .socket, .device, .mount, .automount, .swap, .target, .path, .timer, .slice, and .scope gets its whole personality. ๐Ÿ’…


โœจ NAME โœจ

systemd.unit โ€” Unit configuration


๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

service.service, socket.socket, device.device, mount.mount,
automount.automount, swap.swap, target.target, path.path, timer.timer,
slice.slice, scope.scope

๐ŸŒˆ System Unit Search Path ๐ŸŒˆ

/etc/systemd/system.control/*
/run/systemd/system.control/*
/run/systemd/transient/*
/run/systemd/generator.early/*
/etc/systemd/system/*
/etc/systemd/system.attached/*
/run/systemd/system/*
/run/systemd/system.attached/*
/run/systemd/generator/*
...
/usr/local/lib/systemd/system/*
/usr/lib/systemd/system/*
/run/systemd/generator.late/*

๐ŸŒธ User Unit Search Path ๐ŸŒธ

~/.config/systemd/user.control/*
$XDG_RUNTIME_DIR/systemd/user.control/*
$XDG_RUNTIME_DIR/systemd/transient/*
$XDG_RUNTIME_DIR/systemd/generator.early/*
~/.config/systemd/user/*
$XDG_CONFIG_DIRS/systemd/user/*
/etc/systemd/user/*
$XDG_RUNTIME_DIR/systemd/user/*
/run/systemd/user/*
$XDG_RUNTIME_DIR/systemd/generator/*
$XDG_DATA_HOME/systemd/user/*
$XDG_DATA_DIRS/systemd/user/*
...
/usr/local/lib/systemd/user/*
/usr/lib/systemd/user/*
$XDG_RUNTIME_DIR/systemd/generator.late/*

๐Ÿ’– DESCRIPTION ๐Ÿ’–

A unit file is a plain text, ini-style file โ€” yes, the config-file aesthetic โ€” that encodes information about a service, a socket, a device, a mount point, an automount point, a swap file or partition, a start-up target, a watched file system path, a timer controlled and supervised by systemd(1), a resource management slice or a group of externally created processes. For the general syntax tea, go see systemd.syntax(7). ๐Ÿซถ

This man page lists the common configuration options of all the unit types. These options need to be configured in the [Unit] or [Install] sections of the unit files.

In addition to the generic [Unit] and [Install] sections described here, each unit may have a type-specific section, e.g. [Service] for a service unit. See the respective man pages for more information: systemd.service(5), systemd.socket(5), systemd.device(5), systemd.mount(5), systemd.automount(5), systemd.swap(5), systemd.target(5), systemd.path(5), systemd.timer(5), systemd.slice(5), systemd.scope(5).

Unit files are loaded from a set of paths determined during compilation, described in the next section.

Valid unit names consist of a "unit name prefix", and a suffix specifying the unit type which begins with a dot. The "unit name prefix" must consist of one or more valid characters (ASCII letters, digits, :, -, _, ., and \). The total length of the unit name including the suffix must not exceed 255 characters. The unit type suffix must be one of .service, .socket, .device, .mount, .automount, .swap, .target, .path, .timer, .slice, or .scope.

Unit names can be parameterized by a single argument called the "instance name". The unit is then constructed based on a "template file" which serves as the definition of multiple services or other units. A template unit must have a single @ at the end of the unit name prefix (right before the type suffix). The name of the full unit is formed by inserting the instance name between @ and the unit type suffix. In the unit file itself, the instance parameter may be referred to using %i and other specifiers, see below.

Unit files may contain additional options on top of those listed here. If systemd encounters an unknown option, it will write a warning log message but continue loading the unit. If an option or section name is prefixed with X-, it is ignored completely by systemd. Options within an ignored section do not need the prefix. Applications may use this to include additional information in the unit files. To access those options, applications need to parse the unit files on their own.

Units can be aliased (have an alternative name), by creating a symlink from the new name to the existing name in one of the unit search paths. For example, systemd-networkd.service has the alias dbus-org.freedesktop.network1.service, created during installation as a symlink, so when systemd is asked through D-Bus to load dbus-org.freedesktop.network1.service, it'll load systemd-networkd.service. As another example, default.target โ€” the default system target started at boot โ€” is commonly aliased to either multi-user.target or graphical.target to select what is started by default. Alias names may be used in commands like disable, start, stop, status, and similar, and in all unit dependency directives, including Wants=, Requires=, Before=, After=. Aliases cannot be used with the preset command.

Aliases obey the following restrictions: a unit of a certain type (.service, .socket, ...) can only be aliased by a name with the same type suffix. A plain unit (not a template or an instance), may only be aliased by a plain name. A template instance may only be aliased by another template instance, and the instance part must be identical. A template may be aliased by another template (in which case the alias applies to all instances of the template). As a special case, a template instance (e.g. alias@inst.service) may be a symlink to different template (e.g. template@inst.service). In that case, just this specific instance is aliased, while other instances of the template (e.g. alias@foo.service, alias@bar.service) are not aliased. Those rules preserve the requirement that the instance (if any) is always uniquely defined for a given unit and all its aliases. The target of alias symlink must point to a valid unit file location, i.e. the symlink target name must match the symlink source name as described, and the destination path must be in one of the unit search paths, see UNIT FILE LOAD PATH section below for more details. Note that the target file might not exist, i.e. the symlink may be dangling.

Unit files may specify aliases through the Alias= directive in the [Install] section. When the unit is enabled, symlinks will be created for those names, and removed when the unit is disabled. For example, reboot.target specifies Alias=ctrl-alt-del.target, so when enabled, the symlink /etc/systemd/system/ctrl-alt-del.target pointing to the reboot.target file will be created, and when Ctrl+Alt+Del is invoked, systemd will look for ctrl-alt-del.target, follow the symlink to reboot.target, and execute reboot.service as part of that target. systemd does not look at the [Install] section at all during normal operation, so any directives in that section only have an effect through the symlinks created during enablement.

Along with a unit file foo.service, the directory foo.service.wants/ may exist. All unit files symlinked from such a directory are implicitly added as dependencies of type Wants= to the unit. Similar functionality exists for Requires= type dependencies as well, the directory suffix is .requires/ in this case. This functionality is useful to hook units into the start-up of other units, without having to modify their unit files. For details about the semantics of Wants= and Requires=, see below. The preferred way to create symlinks in the .wants/ or .requires/ directories is by specifying the dependency in [Install] section of the target unit, and creating the symlink in the file system with the enable or preset commands of systemctl(1). The target can be a normal unit (either plain or a specific instance of a template unit). In case when the source unit is a template, the target can also be a template, in which case the instance will be "propagated" to the target unit to form a valid unit instance. The target of symlinks in .wants/ or .requires/ must thus point to a valid unit file location, i.e. the symlink target name must satisfy the described requirements, and the destination path must be in one of the unit search paths, see UNIT FILE LOAD PATH section below for more details. Note that the target file might not exist, i.e. the symlink may be dangling.

Along with a unit file foo.service, a "drop-in" directory foo.service.d/ may exist. All files with the suffix .conf from this directory will be merged in the alphanumeric order and parsed after the main unit file itself has been parsed. This is useful to alter or add configuration settings for a unit, without having to modify unit files. Each drop-in file must contain appropriate section headers. For instantiated units, this logic will first look for the instance .d/ subdirectory (e.g. foo@bar.service.d/) and read its .conf files, followed by the template .d/ subdirectory (e.g. foo@.service.d/) and the .conf files there. Moreover, for unit names containing dashes (-), the set of directories generated by repeatedly truncating the unit name after all dashes is searched too. Specifically, for a unit name foo-bar-baz.service not only the regular drop-in directory foo-bar-baz.service.d/ is searched but also both foo-bar-.service.d/ and foo-.service.d/. This is useful for defining common drop-ins for a set of related units, whose names begin with a common prefix. This scheme is particularly useful for mount, automount and slice units, whose systematic naming structure is built around dashes as component separators. Note that equally named drop-in files further down the prefix hierarchy override those further up, i.e. foo-bar-.service.d/10-override.conf overrides foo-.service.d/10-override.conf.

In cases of unit aliases (described above), dropins for the aliased name and all aliases are loaded. In the example of default.target aliasing graphical.target, default.target.d/, default.target.wants/, default.target.requires/, graphical.target.d/, graphical.target.wants/, graphical.target.requires/ would all be read. For templates, dropins for the template, any template aliases, the template instance, and all alias instances are read. When just a specific template instance is aliased, then the dropins for the target template, the target template instance, and the alias template instance are read.

In addition to /etc/systemd/system, the drop-in .d/ directories for system services can be placed in /usr/lib/systemd/system or /run/systemd/system directories. Drop-in files in /etc/ take precedence over those in /run/ which in turn take precedence over those in /usr/lib/. Drop-in files under any of these directories take precedence over unit files wherever located. Multiple drop-in files with different names are applied in lexicographic order, regardless of which of the directories they reside in.

Files in type.d/ are lower precedence than the files in those name-specific override directories, so keep that in mind. And the usual rules still apply: if you've got multiple drop-in files with different names, they get applied in lexicographic order, no matter which of the directories they're chillin' in. Which means a file in type.d/ only actually applies to a unit if there are no drop-ins or masks with that name in any higher-precedence directory. See Examples for the receipts. ๐Ÿ“‚


Okay so real talk bestie: even though systemd hands you this flexible dependency system between units, the recommendation is to use it sparingly. Like, a little treat. ๐Ÿ“ Instead, lean on stuff like bus-based or socket-based activation, which makes dependencies implicit โ€” and that gives you a system that's both simpler and more flexible. Main character system design, honestly. ๐Ÿ‘‘

As mentioned above, a unit can be instantiated from a template file. This is the slay-est trick: you get multiple units out of a single configuration file. โœจ

So here's how it goes down. When systemd is looking for a unit configuration file, it first searches for the literal unit name in the file system. If that comes up empty and the unit name contains an @ character, systemd goes hunting for a unit template that has the same name but with the instance string (that's the part between the @ character and the suffix) removed. ๐Ÿ’…

Example, because examples are everything: if a service getty@tty3.service is requested and there's no file by that name, systemd will look for getty@.service and instantiate a service from that configuration file if it finds it. Boom. Iconic.

And if you wanna refer to that instance string from inside the configuration file, you use the special %i specifier in many of the configuration options. Details are below. ๐Ÿ‘‡


Now, if a unit file is empty (like, file size 0 empty) or is symlinked to /dev/null, its configuration will not be loaded and it shows up with a load state of "masked", and it cannot be activated. Use this as an effective way to fully disable a unit, making it impossible to start even manually. ๐Ÿšซ

This is the nuclear option and it works. Respect it.

Files (including directories, yes directories) with names that match certain patterns are generally ignored. That includes names that start with a . or end with a .ignore. ๐Ÿ™ˆ


When unit aliasing gets introduced during reload/reexec (say, converting b.service into a symlink pointing to a.service), the running state of the canonical unit (a.service) is preserved. The old serialized state of the now-aliased unit gets migrated to a new stub orphaned unit, so that stale data doesn't corrupt the canonical unit's live state. ๐Ÿ’€

Dependencies that reference the alias name are automatically resolved to the canonical unit, and the dependency graph gets rebuilt from unit files, which keeps everything consistent. If the now-aliased unit had resources like running processes, those are now tracked under the new orphaned unit. And once all those resources are gone (e.g. all the processes have exited), the orphaned unit gets garbage collected automatically. ๐Ÿ—‘๏ธโœจ

The unit file format is covered by the Interface Portability and Stability Promise[1].


๐ŸŒธ STRING ESCAPING FOR INCLUSION IN UNIT NAMES ๐ŸŒธ

Sometimes it's genuinely useful to convert arbitrary strings into unit names, and to make that happen there's a whole method of string escaping. The goal? Map strings that contain arbitrary byte values (except NUL, don't even try) into valid unit names and their restricted character set. ๐Ÿ”ค

A common special case is unit names that reflect paths to objects in the file system hierarchy. Example: a device unit dev-sda.device refers to a device with the device node /dev/sda in the file system. See how that works? Chef's kiss. ๐Ÿ‘จโ€๐Ÿณ๐Ÿ’‹

The escaping algorithm operates like this: given a string, any "/" character is replaced by "-", and all other characters that are not ASCII alphanumerics, ":", "_" or "." get replaced by C-style "\x2d" escapes. Plus, "." gets replaced with such a C-style escape when it would appear as the first character in the escaped string. ๐ŸŽ€

When the input qualifies as an absolute file system path, this algorithm gets extended slightly: the path to the root directory "/" is encoded as a single dash "-". And any leading, trailing or duplicate "/" characters are removed from the string before transformation. Example: /foo//bar/baz/ becomes "foo-bar-baz". Clean. ๐Ÿงผ

This escaping is fully reversible, as long as you know whether the escaped string was a path โ€” because the unescaping results are different for paths and non-path strings. Lowkey important. The systemd-escape(1) command may be used to apply and reverse escaping on arbitrary strings. Use systemd-escape --path to escape path strings, and systemd-escape without --path otherwise. ๐Ÿฆ‹


๐Ÿ”ฅ AUTOMATIC DEPENDENCIES ๐Ÿ”ฅ

โœจ Implicit Dependencies โœจ

A number of unit dependencies are implicitly established, depending on unit type and unit configuration. These implicit dependencies can make a unit configuration file cleaner. For the implicit dependencies in each unit type, please refer to the section "Implicit Dependencies" in the respective man pages. ๐Ÿ“–

For example, service units with Type=dbus automatically acquire dependencies of type Requires= and After= on dbus.socket. See systemd.service(5) for details. โšก

๐Ÿ’œ Default Dependencies ๐Ÿ’œ

Default dependencies are similar to implicit dependencies, but โ€” plot twist โ€” they can be turned on and off by setting DefaultDependencies= to yes (which is the default) and no, while implicit dependencies are always in effect, no takebacks. See the section "Default Dependencies" in the respective man pages for the effect of enabling DefaultDependencies= in each unit type. ๐Ÿ”

For example, target units will complement all configured dependencies of type Wants= or Requires= with dependencies of type After=. See systemd.target(5) for details. And note that this behavior can be opted out by setting DefaultDependencies=no in the specified units, or it can be selectively overridden via an explicit Before= dependency. ๐ŸŽฏ


๐Ÿงš UNIT FILE LOAD PATH ๐Ÿงš

Unit files are loaded from a set of paths determined during compilation, described in the two tables below. Unit files found in directories listed earlier override files with the same name in directories lower in the list [2]. โฌ†๏ธ

When the variable $SYSTEMD_UNIT_PATH is set, the contents of this variable overrides the unit load path. And if $SYSTEMD_UNIT_PATH ends with an empty component (":"), the usual unit load path gets appended to the contents of the variable. ๐Ÿซถ

Table 1. Load path when running in system mode (--system).

  • /etc/systemd/system.control โ€” Persistent and transient configuration created using the dbus API
  • /run/systemd/system.control โ€” Persistent and transient configuration created using the dbus API
  • /run/systemd/transient โ€” Dynamic configuration for transient units
  • /run/systemd/generator.early โ€” Generated units with high priority (see early-dir in systemd.generator(7))
  • /etc/systemd/system โ€” System units created by the administrator
  • /run/systemd/system โ€” Runtime units
  • /run/systemd/generator โ€” Generated units with medium priority (see normal-dir in systemd.generator(7))
  • /usr/local/lib/systemd/system โ€” System units installed by the administrator
  • /usr/lib/systemd/system โ€” System units installed by the distribution package manager
  • /run/systemd/generator.late โ€” Generated units with low priority (see late-dir in systemd.generator(7))

Table 2 โœจ โ€” load path when you're running in user mode (--user)

okay so here's the user-mode list, and bestie, order MATTERS. earlier = higher priority, so read top to bottom and let it sink in ๐Ÿ’…

  1. $XDG_CONFIG_HOME/systemd/user.control or ~/.config/systemd/user.control โ€” persistent and transient configuration that was created using the dbus API. ($XDG_CONFIG_HOME gets used if it's set, otherwise ~/.config.) ๐ŸŽ€
  2. $XDG_RUNTIME_DIR/systemd/transient โ€” dynamic configuration for transient units โšก
  3. $XDG_RUNTIME_DIR/systemd/generator.early โ€” generated units with high priority (peep early-dir in systemd.generator(7)) ๐ŸŒ…
  4. $XDG_CONFIG_HOME/systemd/user or $HOME/.config/systemd/user โ€” user configuration ($XDG_CONFIG_HOME is used if set, otherwise ~/.config) ๐Ÿ’–
  5. $XDG_CONFIG_DIRS/systemd/user or /etc/xdg/systemd/user โ€” additional configuration directories as specified by the XDG base directory specification ($XDG_CONFIG_DIRS is used if set, otherwise /etc/xdg) ๐Ÿ—‚๏ธ
  6. /etc/systemd/user โ€” user units created by the administrator ๐Ÿ‘‘
  7. $XDG_RUNTIME_DIR/systemd/user โ€” runtime units (only used when $XDG_RUNTIME_DIR is set) โฑ๏ธ
  8. /run/systemd/user โ€” runtime units ๐Ÿƒ
  9. $XDG_RUNTIME_DIR/systemd/generator โ€” generated units with medium priority (see normal-dir in systemd.generator(7)) ๐Ÿงš
  10. $XDG_DATA_HOME/systemd/user or $HOME/.local/share/systemd/user โ€” units of packages that have been installed in the home directory ($XDG_DATA_HOME is used if set, otherwise ~/.local/share) ๐Ÿ 
  11. $XDG_DATA_DIRS/systemd/user or /usr/local/share/systemd/user and /usr/share/systemd/user โ€” additional data directories as specified by the XDG base directory specification ($XDG_DATA_DIRS is used if set, otherwise /usr/local/share and /usr/share) ๐Ÿ“ฆ
  12. $dir/systemd/user for each $dir in $XDG_DATA_DIRS โ€” extra locations for installed user units, one for every entry in $XDG_DATA_DIRS ๐ŸŒˆ
  13. /usr/local/lib/systemd/user โ€” user units installed by the administrator ๐Ÿ› ๏ธ
  14. /usr/lib/systemd/user โ€” user units installed by the distribution package manager ๐Ÿง
  15. $XDG_RUNTIME_DIR/systemd/generator.late โ€” generated units with low priority (see late-dir in systemd.generator(7)) ๐ŸŒ™

and likeโ€ฆ the set of load paths for the user manager instance can get augmented or changed using various environment variables, no cap. and those environment variables can in turn be set using environment generators โ€” see systemd.environment-generator(7). in particular, $XDG_DATA_HOME and $XDG_DATA_DIRS are super easy to set using systemd-environment-d-generator(8). so basically, the directories listed above are just the defaults, okay? to see the actual list that would be used based on compilation options and the current environment, run:

systemd-analyze --user unit-paths

also โ€” plot twist โ€” additional units might get loaded into systemd from directories that are not on the unit load path, by creating a symlink that points to a unit file in those directories. you can use systemctl link for this; see systemctl(1). the file system where the linked unit files live must be accessible when systemd is started (so like, anything underneath /home/ or /var/ is not allowed, unless those directories are located on the root file system). noted. ๐Ÿ“

it is SO important to distinguish "linked unit files" from "unit file aliases", bestie, this is the part people get wrong ๐Ÿ˜ญ any symlink where the symlink target is within the unit load path becomes an alias: the source name and the target file name have to satisfy those specific constraints listed above in the discussion of aliases, but the symlink target doesn't have to exist, and honestly the symlink target path isn't used at all โ€” except to check whether the target is within the unit load path. in contrast, a symlink that goes outside of the unit load path signifies a linked unit file. the symlink gets followed when loading the file, but the destination name is otherwise unused (and may even not be a valid unit file name) ๐Ÿ™ˆ

for example, the symlinks

  • /etc/systemd/system/alias1.service โ†’ service1.service
  • /etc/systemd/system/alias2.service โ†’ /usr/lib/systemd/service1.service
  • /etc/systemd/system/alias3.service โ†’ /etc/systemd/system/service1.service

are all valid aliases, and service1.service will have four names โ€” even if the unit file is located at /run/systemd/system/service1.service. slay. ๐Ÿ’…

in contrast, a symlink /etc/systemd/system/link1.service โ†’ ../link1_service_file means that link1.service is a "linked unit" and the contents of /etc/systemd/link1_service_file provide its configuration. two completely different vibes, iykyk ๐Ÿฆ‹

๐Ÿ—‘๏ธ UNIT GARBAGE COLLECTION

okay so here's the tea bestie ๐Ÿ’– systemd does not just hoard every unit file forever like it's a collector of vintage beanie babies. It loads a unit's config the first time something references it, and then โ€” when nobody needs it anymore โ€” it unloads the config and the state. That's the "garbage collection" moment โœจ

A unit counts as referenced (so it stays loaded) through a bunch of different mechanisms:

  1. Another loaded unit references it with a dependency such as After=, Wants=, ...
  2. The unit is currently starting, running, reloading or stopping.
  3. The unit is currently in the failed state. (But see below ๐Ÿ‘€)
  4. A job for the unit is pending.
  5. The unit is pinned by an active IPC client program.
  6. The unit is a special "perpetual" unit that is always active and loaded. Examples for perpetual units are the root mount unit -.mount or the scope unit init.scope that the service manager itself lives in.
  7. The unit has running processes associated with it.

You can mess with the garbage collection logic with the CollectMode= option โ€” that's the one that lets you configure whether automatic unloading of units that are in failed state is permissible. More on that below โฌ‡๏ธ

โš ๏ธ heads up bestie: when a unit's configuration and state is unloaded, all execution results โ€” exit codes, exit signals, resource consumption, all the other statistics โ€” are lost. The only survivors are whatever made it into the log subsystem. so log it or lose it, fr fr ๐Ÿ’€

Want to reload unit configuration while the unit is already loaded? Use systemctl daemon-reload or an equivalent command. What happens then: every configuration setting gets flushed out and replaced with the new configuration (which, lowkey, might not be in effect immediately ๐Ÿ‘€), but all runtime state is saved/restored. best of both worlds, slay ๐Ÿ’…


๐Ÿ“‹ [Unit] SECTION OPTIONS

Your unit file can have a [Unit] section, and that's where the generic stuff lives โ€” the info about the unit that doesn't depend on what type of unit it is. like the unit's whole personality, not just its job ๐Ÿฆ‹

  • Description= โ€” a brief, meaningful, human-readable text identifying the unit. systemd (and suitable UIs) may use this as a user-visible label for the unit, so this string should identify the unit rather than just describe it โ€” despite the name, okay?? ๐Ÿ˜ญ This string also should not just repeat the unit name. "Apache HTTP Server" or "Postfix Mail Server" are good examples. Bad examples are "high-performance lightweight HTTP server" (too generic) or "Apache" (meaningless for people who do not know the Apache HTTP server project, and it duplicates the unit name ๐Ÿ™ˆ). systemd may use this string as a noun in status messages ("Starting Description...", "Started Description.", "Reached target Description.", "Failed to start Description."), so it should be capitalized, and should not be a full sentence, or a phrase with a verb conjugated in the present continuous, or end in a full stop. Bad examples include "exiting the container", "updating the database once per day.", or "OpenSSH server second instance daemon".

Added in version 201.

  • Documentation= โ€” a space-separated list of URIs referencing documentation for this unit or its configuration. Accepted are only URIs of the types "http://", "https://", "file:", "info:", "man:". For more information about the syntax of these URIs, see uri(7). List them in order of relevance, starting with the most relevant โœจ It's a good idea to first reference documentation that explains what the unit's purpose is, followed by how it is configured, followed by any other related documentation. This option may be specified more than once, in which case the specified list of URIs is merged. If the empty string is assigned to this option, the list is reset and all prior assignments will have no effect.

Added in version 201.

  • Wants= โ€” configures (weak) requirement dependencies on other units ๐Ÿ’ซ This option may be specified more than once, or multiple space-separated units may be specified in one option, in which case dependencies for all listed names will be created. Dependencies of this type may also be configured outside of the unit configuration file by adding a symlink to a .wants/ directory accompanying the unit file. For details, see above.

Units listed in this option will be started if the configuring unit is. However โ€” and this is the whole point โ€” if the listed units fail to start or cannot be added to the transaction, this has no impact on the validity of the transaction as a whole, and this unit will still be started. This is the recommended way to hook the start-up of one unit to the start-up of another unit ๐Ÿ‘‘

no cap: requirement dependencies do not influence the order in which services are started or stopped. That has to be configured independently with the After= or Before= options. If unit foo.service pulls in unit bar.service as configured with Wants= and no ordering is configured with After= or Before=, then both units will be started simultaneously and without any delay between them if foo.service is activated. chaotic? yes. intended? also yes ๐Ÿ’€

Added in version 201.

  • Requires= โ€” similar to Wants=, but declares a stronger requirement dependency. Dependencies of this type may also be configured by adding a symlink to a .requires/ directory accompanying the unit file.

If this unit gets activated, the units listed will be activated as well. If one of the other units fails to activate, and an ordering dependency After= on the failing unit is set, this unit will not be started. Besides, with or without specifying After=, this unit will be stopped (or restarted) if one of the other units is explicitly stopped (or restarted).

Often, it is a better choice to use Wants= instead of Requires= in order to achieve a system that is more robust when dealing with failing services. (bestie, learn from everyone's mistakes here ๐Ÿซถ)

Note that this dependency type does not imply that the other unit always has to be in active state when this unit is running. Specifically: failing condition checks (such as ConditionPathExists=, ConditionPathIsSymbolicLink=, ... โ€” see below) do not cause the start job of a unit with a Requires= dependency on it to fail. Also, some unit types may deactivate on their own (for example, a service process may decide to exit cleanly, or a device may be unplugged by the user), which is not propagated to units having a Requires= dependency. Use the BindsTo= dependency type together with After= to ensure that a unit may never be in active state without a specific other unit also in active state (see below) ๐Ÿ‘€

Added in version 201.

  • Requisite= โ€” similar to Requires=. However, if the units listed here are not started already, they will not be started and the starting of this unit will fail immediately. Requisite= does not imply an ordering dependency, even if both units are started in the same transaction. Hence this setting should usually be combined with After=, to ensure this unit is not started before the other unit. it's giving "you better already be there or i'm leaving" ๐Ÿ˜ค

When Requisite=b.service is used on a.service, this dependency will show as RequisiteOf=a.service in property listing of b.service. RequisiteOf= dependency cannot be specified directly.

Added in version 201.

  • BindsTo= โ€” configures requirement dependencies, very similar in style to Requires=. However, this dependency type is stronger: in addition to the effects of Requires= โ€” which already stops (or restarts) the configuring unit when a listed unit is explicitly stopped (or restarted) โ€” it also does so when a listed unit stops unexpectedly (which includes when it fails). Units can suddenly, unexpectedly enter inactive state for different reasons: the main process of a service unit might terminate on its own choice, the backing device of a device unit might be unplugged, or the mount point of a mount unit might be unmounted without involvement of the system and service manager. we are bound bound, no takebacks ๐Ÿ’…

When used in conjunction with After= on the same unit the behaviour of BindsTo= is even stronger. In this case, the unit bound to strictly has to be in active state for this unit to also be in active state. This not only means a unit bound to another unit that suddenly enters inactive state, but also one that is bound to another unit that gets skipped due to an unmet condition check (such as ConditionPathExists=, ConditionPathIsSymbolicLink=, ... โ€” see below) will be stopped, should it be running. Hence, in many cases it is best to combine BindsTo= with After=.

When BindsTo=b.service is used on a.service, this dependency will show as BoundBy=a.service in property listing of b.service. BoundBy= dependency cannot be specified directly.

Added in version 201.

  • PartOf= โ€” configures dependencies similar to Requires=, but limited to stopping and restarting of units. When systemd stops or restarts the units listed here, the action is propagated to this unit. Note that this is a one-way dependency โ€” changes to this unit do not affect the listed units. one-way street, bestie, no U-turns allowed ๐Ÿšซ

When PartOf=b.service is used on a.service, this dependency will show as ConsistsOf=a.service in property listing of b.service. ConsistsOf= dependency cannot be specified directly.

Added in version 201.

  • Upholds= โ€” configures dependencies similar to Wants=, but as long as this unit is up, all units listed in Upholds= are started whenever found to be inactive or failed, and no job is queued for them. While a Wants= dependency on another unit has a one-time effect when this units started, a Upholds= dependency on it has a continuous effect, constantly restarting the unit if necessary. This is an alternative to the Restart= setting of service units, to ensure they are kept running whatever happens ๐Ÿ”ฅ The restart happens without delay, and usual per-unit rate-limit applies.

When Upholds=b.service is used on a.service, this dependency will show as UpheldBy=a.service in the property listing of b.service.

Added in version 249.

  • Conflicts= โ€” a space-separated list of unit names. Configures negative requirement dependencies. If a unit has a Conflicts= requirement on a set of other units, then starting it will stop all of them and starting any of them will stop it. it's giving mutual beef, iconically ๐Ÿ’€

Okay so real talk, continuing the Conflicts= tea from before:

This setting does not imply an ordering dependency โ€” same vibe as the Wants= and Requires= deps we talked about up top. So if you actually need the conflicting unit to be stopped before the other one gets started, you have to declare an After= or Before= dependency yourself. Which one you pick doesn't matter, bestie, because stop jobs are always ordered before start jobs โ€” that's literally spelled out in the Before=/After= discussion below. ๐Ÿ’…

And if unit A (which conflicts with unit B) is scheduled to be started at the exact same time as B? Then the transaction either:

  • fails โ€” in case both are required parts of the transaction, or
  • gets modified to be fixed โ€” in case one or both jobs aren't a required part of the transaction. When that happens, the job that isn't required gets removed; or if both aren't required, the unit that conflicts gets started and the unit that is conflicted gets stopped. โœจ

Added in version 201.


  • Before=, After= โ€” these two expect a space-separated list of unit names, and you can specify them more than once, in which case dependencies get created for every single name you listed. ๐Ÿซถ

These two configure ordering dependencies between units. If unit foo.service contains the setting Before=bar.service and both units are being started, then bar.service's start-up is delayed until foo.service has finished starting up. After= is the inverse of Before=: while Before= makes sure the configured unit starts before the listed unit begins starting up, After= makes sure the opposite โ€” that the listed unit is fully started up before the configured unit is started.

When two units with an ordering dependency between them get shut down, the inverse of the start-up order applies. I.e. if a unit is configured with After= on another unit, the former gets stopped before the latter when both are shut down. Now say two units have any ordering dependency between them, and one is being shut down while the other is being started up โ€” the shutdown is ordered before the start-up. Doesn't matter whether the dep is After= or Before= in that case, and it also doesn't matter which of the two is the one shutting down: as long as one goes down and the other comes up, the shutdown goes first, every single time. And if two units have no ordering dependencies between them at all? They just get shut down or started up simultaneously, no ordering whatsoever. ๐Ÿ‘‘

When precisely a unit counts as "finished starting up" depends on the unit type. Most importantly: for service units, start-up is considered completed for the purposes of Before=/After= when all its configured start-up commands have been invoked and they either failed or reported start-up success. Note that this includes ExecStartPost= (or ExecStopPost= for the shutdown case). ๐Ÿ’€

Note that these settings are independent of and orthogonal to the requirement dependencies configured by Requires=, Wants=, Requisite=, or BindsTo=. A super common pattern is putting a unit name in both the After= and Wants= options โ€” in that case the unit you listed gets started before the unit configured with these options. ๐ŸŒธ

Note that Before= dependencies on device units have no effect and are not supported. Devices generally become available as a result of an external hotplug event, and systemd creates the corresponding device unit without delay. No cap.

Added in version 201.

  • OnFailure= โ€” a space-separated list of one or more units that get activated when this unit enters the "failed" state. ๐Ÿ˜ญ

Added in version 201.

  • OnSuccess= โ€” a space-separated list of one or more units that get activated when this unit enters the "inactive" state.

Added in version 249.

  • PropagatesReloadTo=, ReloadPropagatedFrom= โ€” a space-separated list of one or more units that reload requests from this unit shall be propagated to, or units from which reload requests shall be propagated to this unit, respectively. Issuing a reload request on a unit will automatically also enqueue reload requests on every unit linked to it using these two settings. It's giving group chat, but for reloads. ๐Ÿ“ฃ

Added in version 201.

  • PropagatesStopTo=, StopPropagatedFrom= โ€” a space-separated list of one or more units that stop requests from this unit shall be propagated to, or units from which stop requests shall be propagated to this unit, respectively. Issuing a stop request on a unit will automatically also enqueue stop requests on all units linked to it using these two settings.

Added in version 249.

  • JoinsNamespaceOf= โ€” for units that start processes (think service units), this lists one or more other units whose network and/or temporary file namespace to join. If it's specified on a unit (say, a.service has JoinsNamespaceOf=b.service), then the inverse dependency (JoinsNamespaceOf=a.service for b.service) is implied. This only applies to unit types that support the PrivateNetwork=, NetworkNamespacePath=, PrivateIPC=, IPCNamespacePath=, and PrivateTmp= directives (see systemd.exec(5) for the details, bestie). If a unit with this setting set gets started, its processes will see the same /tmp/, /var/tmp/, IPC namespace and network namespace as one listed unit that is started. And if multiple listed units are already started and they don't share their namespace? Then it is not defined which namespace gets joined. ๐Ÿ™ˆ Note that this setting only has an effect if PrivateNetwork=/NetworkNamespacePath=, PrivateIPC=/IPCNamespacePath= and/or PrivateTmp= is enabled for both the unit that joins the namespace and the unit whose namespace is joined.

Added in version 209.

  • RequiresMountsFor= โ€” takes a space-separated list of absolute paths. It automatically adds dependencies of type Requires= and After= for all mount units required to access the specified path. ๐Ÿ”๏ธ

Mount points marked with noauto are not mounted automatically through local-fs.target, but they are still honored for the purposes of this option, i.e. they will be pulled in by this unit.

Added in version 201.

  • WantsMountsFor= โ€” same as RequiresMountsFor=, but adds dependencies of type Wants= instead of Requires=. Little sister energy, softer ask. ๐Ÿฅบ

Added in version 256.

  • OnSuccessJobMode=, OnFailureJobMode= โ€” takes a value of "fail", "replace", "replace-irreversibly", "isolate", "flush", "ignore-dependencies" or "ignore-requirements". OnFailureJobMode= defaults to "replace", and OnSuccessJobMode= defaults to "fail". This specifies how the units listed in OnSuccess=/OnFailure= will be enqueued. See systemctl(1)'s --job-mode= option for the deets on the possible values. And heads up: if this is set to "isolate", only a single unit may be listed in OnSuccess=/OnFailure=.

Added in version 209.

  • IgnoreOnIsolate= โ€” takes a boolean argument. If true, this unit will not be stopped when isolating another unit. It defaults to false for service, target, socket, timer, and path units, and true for slice, scope, device, swap, mount, and automount units.

Added in version 201.

  • StopWhenUnneeded= โ€” takes a boolean argument. If true, this unit gets stopped when it is no longer used. Note that, in order to minimize the work to be executed, systemd will not stop units by default unless they're conflicting with other units, or the user explicitly requested their shut down. If this option is set, a unit gets automatically cleaned up if no other active unit requires it. Defaults to false.

Added in version 201.

  • RefuseManualStart=, RefuseManualStop= โ€” takes a boolean argument. If true, this unit can only be activated or deactivated indirectly. In this case, explicit start-up or termination requested by the user is denied โ€” however, if it's started or stopped as a dependency of another unit, start-up or termination will succeed. This is mostly a safety feature, to make sure the user doesn't accidentally activate units that aren't meant to be activated explicitly, and doesn't accidentally deactivate units that aren't meant to be deactivated. These options default to false. ๐Ÿšง

Added in version 201.

  • AllowIsolate= โ€” takes a boolean argument. If true, this unit may be used with the systemctl isolate command. Otherwise, that gets refused. It probably is a good idea to leave this disabled except for target units that shall be used similar to runlevels in SysV init systems โ€” just as a precaution to avoid unusable system states. This option defaults to false. โš ๏ธ

Added in version 201.

  • DefaultDependencies= โ€” takes a boolean argument. If yes (the default), a few default dependencies will implicitly be created for the unit. Which actual dependencies get created depends on the unit type. For example, for service units these dependencies ensure the service is started only after basic system initialization is completed, and is properly terminated on system shutdown. See the respective man pages for details. Generally, only services involved with early boot or late shutdown should set this option to no. It is highly recommended to leave this option enabled for the majority of common units. And if set to no, this option does not disable all implicit dependencies โ€” just the non-essential ones.

Added in version 201.

  • SurviveFinalKillSignal= โ€” takes a boolean argument. Defaults to no. If yes, processes belonging to this unit will not be sent the final "SIGTERM" and "SIGKILL" signals during the final phase of the system shutdown process. This functionality replaces the older mechanism that allowed a program to set "argv[0][0] = '@'" as described at systemd and Storage Daemons for the Root File System[3] โ€” which, however, continues to be supported. ๐Ÿ’€โœจ

Added in version 255.

  • CollectMode= โ€” this one tweaks the โœจgarbage collectionโœจ algorithm for the unit, and it takes one of two values: inactive or inactive-or-failed. Set it to inactive and the unit gets unloaded when it's sitting in the inactive state and nobody's referencing it โ€” not clients, not jobs, not other units โ€” BUT (and this is the plot twist ๐Ÿซฃ) it will not be unloaded if it's in the failed state. In failed mode, failed units stay put until someone runs systemctl reset-failed on them to clear the failed state, or does the equivalent. All of that changes if you set it to inactive-or-failed: now the unit gets unloaded even when it's failed, so you don't have to explicitly reset the failed state. Heads up bestie: in that mode, unit results (exit codes, exit signals, consumed resources, ...) get flushed out the instant the unit completes โ€” everything except what's stored in the logging subsystem. Defaults to inactive.

Since v261: if FileDescriptorStorePreserve= is set to yes and the unit has file descriptors stored, garbage collection is disabled until the unit is removed, the service manager exits, or those file descriptors get EPOLLHUP or EPOLLERR. ๐Ÿ’…

Added in version 236.

  • FailureAction=, SuccessAction= โ€” these configure what action gets taken when the unit stops and enters a failed state or an inactive state. Values it accepts: none, reboot, reboot-force, reboot-immediate, poweroff, poweroff-force, poweroff-immediate, exit, exit-force, soft-reboot, soft-reboot-force, kexec, kexec-force, halt, halt-force and halt-immediate. In system mode, every option is allowed. In user mode, only none, exit, and exit-force are allowed. Both options default to none.

These actions are tied to the unit's state transitions, and they only fire when the unit actually transitions out of an active or activating state. Which means: Condition...= and Assert...= directives that fail do not trigger SuccessAction= or FailureAction= โ€” they prevent activation from happening at all, so no state transition ever occurs, no action, nothing. By contrast, the ExecCondition= directive in systemd.service(5) runs as part of activation, so an ExecCondition= skip will trigger SuccessAction=. ๐Ÿ‘€

If none is set, no action is triggered, periodt. reboot causes a reboot following the normal shutdown procedure (equivalent to systemctl reboot). reboot-force causes a forced reboot which terminates all processes forcibly but should cause no dirty file systems on reboot (equivalent to systemctl reboot -f), and reboot-immediate causes immediate execution of the reboot(2) system call, which might result in data loss (equivalent to systemctl reboot -ff). ๐Ÿ˜ญ Similarly, poweroff, poweroff-force, poweroff-immediate, kexec, kexec-force, halt, halt-force and halt-immediate have the effect of powering down the system, executing kexec, and halting the system respectively, with similar semantics. exit causes the manager to exit following the normal shutdown procedure, and exit-force causes it to terminate without shutting down services. When exit or exit-force is used, by default the exit status of the main process of the unit (if this applies) is returned from the service manager. If there's no such status, FailureAction= returns 255 instead, while SuccessAction= leaves the exit status unchanged. But โ€” you can override that with FailureActionExitStatus=/SuccessActionExitStatus=, see below. soft-reboot will trigger a userspace reboot operation. soft-reboot-force does that too, but it does not go through the shutdown transaction beforehand.

Added in version 236.

  • FailureActionExitStatus=, SuccessActionExitStatus= โ€” controls the exit status that gets propagated back to an invoking container manager (for a system service) or service manager (for a user manager) when FailureAction=/SuccessAction= are set to exit or exit-force and the action gets triggered. By default, the exit status of the main process of the triggering unit (if that applies) is propagated. Takes a value in the range 0...255, or the empty string to request the default behaviour.

Added in version 240.

  • JobTimeoutSec=, JobRunningTimeoutSec= โ€” JobTimeoutSec= sets a timeout for the whole job, and it starts running when the job gets queued. JobRunningTimeoutSec= sets a timeout that starts running when the queued job actually starts. If either limit gets hit, the job is cancelled โ€” but the unit itself does not change state or even enter the "failed" mode. Wild, I know. ๐Ÿซ 

Both settings take a time span with the default unit of seconds, but other units may be specified, see systemd.time(7). The default is "infinity" (job timeouts disabled), except for device units, where JobRunningTimeoutSec= defaults to DefaultDeviceTimeoutSec=.

Note: these timeouts are independent from any unit-specific timeouts (like the one set with TimeoutStartSec= in service units). The job timeout has no effect on the unit itself. Or, put another way: unit-specific timeouts are useful for aborting unit state changes and reverting them. The job timeout set with this option is useful for aborting only the job that's waiting for the unit state to change. ๐Ÿ’…

Added in version 201.

  • JobTimeoutAction=, JobTimeoutRebootArgument= โ€” JobTimeoutAction= optionally configures an additional action to take when the timeout is hit, see the description of JobTimeoutSec= and JobRunningTimeoutSec= above. It takes the same values as FailureAction=/SuccessAction=. Defaults to none.

JobTimeoutRebootArgument= configures an optional reboot string to pass to the reboot(2) system call.

Added in version 240.

  • StartLimitIntervalSec=interval, StartLimitBurst=burst โ€” these configure unit start rate limiting. Units that get started more than burst times within an interval time span are not permitted to start any more. Use StartLimitIntervalSec= to configure the checking interval and StartLimitBurst= to configure how many starts per interval are allowed.

interval is a time span with the default unit of seconds, but other units may be specified, see systemd.time(7). The special value "infinity" can be used to limit the total number of start attempts, even if they happen at large time intervals. Defaults to DefaultStartLimitIntervalSec= in the manager configuration file, and may be set to 0 to disable any kind of rate limiting. burst is a number and defaults to DefaultStartLimitBurst= in the manager configuration file.

These configuration options are especially useful alongside the service setting Restart= (see systemd.service(5)) โ€” but they apply to all kinds of starts (manual ones included), not just the ones triggered by the Restart= logic. ๐Ÿ‘‘

Note that units configured for Restart= that reach the start limit are not attempted to be restarted anymore; however, they may still be restarted manually or from a timer or socket later, after the interval has passed. From that point on, the restart logic is activated again. systemctl reset-failed will cause the restart rate counter for a service to be flushed, which is handy if the administrator wants to manually start a unit and the start limit is getting in the way. Rate-limiting is enforced after any unit condition checks are executed, so unit activations with failing conditions don't count towards the rate limit. ๐Ÿงš

When a unit is unloaded due to the garbage collection logic (see above), its rate limit counters get flushed out too. Which means configuring start rate limiting for a unit that isn't referenced continuously has no effect. ๐Ÿ’€

This setting does not apply to slice, target, device, and scope units, since those are unit types whose activation may either never fail, or may succeed only a single time.

Added in version 229.

  • StartLimitAction= โ€” configure an additional action to take if the rate limit configured with StartLimitIntervalSec= and StartLimitBurst= gets hit. Takes the same values as the FailureAction=/SuccessAction= settings. If none is set, hitting the rate limit triggers no action except that the start will not be permitted. Defaults to none.

Added in version 229.

  • RebootArgument= โ€” configure the optional argument for the reboot(2) system call if StartLimitAction= or FailureAction= is a reboot action. This works just like the optional argument to the systemctl reboot command.

Added in version 229.

  • SourcePath= โ€” a path to a configuration file this unit has been generated from. This is primarily useful for implementing generator tools that convert configuration from an external configuration file format into native unit files. This functionality should not be used in normal units, bestie, fr fr.

Added in version 201.


๐ŸŒธ Conditions and Asserts ๐ŸŒธ

Unit files may also include a bunch of Condition...= and Assert...= settings. Before the unit is started, systemd verifies that the specified conditions and asserts are true. If they're not, the starting of the unit will be skipped โ€” mostly silently, in the case of conditions โ€” or aborted with an error message, in the case of asserts. Failing conditions or asserts will not result in the unit being moved into the "failed" state. ๐Ÿ™…โ™€๏ธ

The conditions and asserts are checked at the time the queued start job is to be executed. The ordering dependencies are still respected, so other units are still pulled in and ordered as if this unit was successfully activated, and the conditions and asserts are executed the precise moment the unit would normally start โ€” which means they can validate system state after the units ordered before them completed initialization. Use condition expressions for skipping units that do not apply to the local system, for example because the kernel or runtime environment doesn't require their functionality. โœจ

okay so when you've got multiple conditions going at once, bestie, the unit only gets executed if all of them apply โ€” that's a logical AND, no exceptions, no wiggle room. ๐Ÿ’…

And here's the fun part: condition checks can use a pipe symbol ("|") right after the equals sign (Condition...=|...), and that upgrades the condition into a triggering condition. So if at least one triggering condition is defined for a unit, then the unit will be started if at least one of the triggering conditions of the unit applies and all of the regular (i.e. non-triggering) conditions apply. โœจ

tiny order-of-operations warning: if you're prefixing an argument with the pipe symbol and an exclamation mark, the pipe symbol must be passed first, the exclamation second. Do not flip them. ๐Ÿ’€

Also โ€” if any of these options is assigned the empty string, the entire list of conditions is reset completely, and all previous condition settings (of any kind) will have no effect. Poof. Gone. ๐Ÿ™ˆ


The AssertArchitecture=, AssertVirtualization=, โ€ฆ options are basically conditions' meaner, more dramatic sibling ๐Ÿ˜ค โ€” instead of the job being skipped, they cause the start job to fail. And yes, the failed check gets logged.

Units with unmet conditions are considered to be in a clean state and will be garbage collected if they are not referenced. Which means when you query them, the condition failure may or may not show up in the state of the unit. It's giving quantum uncertainty, honestly. ๐Ÿฆ‹

Note that neither assertion nor condition expressions result in unit state changes. Also note that both are checked at the time the job is to be executed โ€” i.e. long after depending jobs and it itself were queued. So neither condition nor assertion expressions are suitable for conditionalizing unit dependencies. periodt.

The condition verb of systemd-analyze(1) can be used to test condition and assert expressions. ๐Ÿ‘‘

Except for ConditionPathIsSymbolicLink=, all path checks follow symlinks. ๐Ÿซถ


ConditionArchitecture=

Check whether the system is running on a specific architecture. Takes one of "x86", "x86-64", "ppc", "ppc-le", "ppc64", "ppc64-le", "ia64", "parisc", "parisc64", "s390", "s390x", "sparc", "sparc64", "mips", "mips-le", "mips64", "mips64-le", "alpha", "arm", "arm-be", "arm64", "arm64-be", "sh", "sh64", "m68k", "tilegx", "cris", "arc", "arc-be", or "native".

Use systemd-analyze(1) for the complete list of known architectures. โœจ

The architecture is determined from the information returned by uname(2) and is thus subject to personality(2). Note that a Personality= setting in the same unit file has no effect on this condition. A special architecture name "native" is mapped to the architecture the system manager itself is compiled for. The test may be negated by prepending an exclamation mark.

Added in version 201.


ConditionFirmware=

Check whether the system's firmware is of a certain type. The following values are possible:

  • "uefi" matches systems with EFI.
  • "device-tree" matches systems with a device tree.
  • "device-tree-compatible(value)" matches systems with a device tree that are compatible with "value".
  • "smbios-field(field operator value)" matches systems with a SMBIOS field containing a certain value. field is the name of the SMBIOS field exposed as "sysfs" attribute file below /sys/class/dmi/id/. operator is one of "<", "<=", ">=", ">", "==", "<>" for version comparisons, "=" and "!=" for literal string comparisons, or "$=", "!$=" for shell-style glob comparisons. value is the expected value of the SMBIOS field value (possibly containing shell style globs in case "$="/"!$=" is used).

Added in version 249.


ConditionVirtualization=

Check whether the system is executed in a virtualized environment, and optionally test whether it's a specific implementation. ๐Ÿ‘€

Takes either a boolean value to check if it's being executed in any virtualized environment at all, or one of "vm" and "container" to test against a generic type of virtualization solution, or one of "qemu", "kvm", "amazon", "zvm", "vmware", "microsoft", "oracle", "powervm", "xen", "bochs", "uml", "bhyve", "qnx", "apple", "sre", "openvz", "lxc", "lxc-libvirt", "systemd-nspawn", "docker", "podman", "rkt", "wsl", "proot", "pouch", "acrn" to test against a specific implementation, or "private-users" to check whether we are running in a user namespace.

See systemd-detect-virt(1) for a full list of known virtualization technologies and their identifiers. If multiple virtualization technologies are nested, only the innermost is considered. The test may be negated by prepending an exclamation mark.

Added in version 244.


ConditionHost=

ConditionHost= may be used to match against the hostname, machine ID, boot ID or product UUID of the host. ๐Ÿ 

This either takes a hostname string (optionally with shell style globs) which is tested against the locally set hostname as returned by gethostname(2), or a 128bit ID or UUID, formatted as string. The latter is compared against machine ID, boot ID and the firmware product UUID if there is any. See machine-id(5) for details about the machine ID. The test may be negated by prepending an exclamation mark.

Added in version 244.


ConditionFraction=

ConditionFraction= may be used to enable a unit on a stable, pseudo-random subset of a fleet of machines. ๐ŸŽฒ It is primarily useful for staged rollouts: the same unit (or drop-in) is distributed to every machine in a fleet, but only the configured fraction of them will actually have it enabled. The decision is derived locally from the machine ID (see machine-id(5)), so it requires no central coordination and is stable over time: a given machine always lands on the same side of the threshold. Iconic, honestly.

The argument consists of an optional tag followed by a percentage, separated by whitespace, for example "30%" or "myrollout 30%". The percentage may include up to two decimal places (e.g. "0.5%"). The condition is satisfied on approximately the configured percentage of all machines; "0%" matches no machine and "100%" matches every machine.

The optional tag is an arbitrary string (not containing whitespace) that is mixed into the derivation, so that independent rollouts select independent subsets of the fleet. Without it, all untagged ConditionFraction= checks would select the very same machines (the same machines would always be picked first). Use distinct tags for unrelated rollouts, and a shared tag to deliberately target the same machines across several units. ๐ŸŽ€

The test may be negated by prepending an exclamation mark, in which case it is satisfied on the complementary fraction of machines (e.g. "!myrollout 30%" matches the other โ‰ˆ70%). If the machine ID cannot be determined, the condition fails. ๐Ÿ’€

Added in version 261.


ConditionKernelCommandLine=

ConditionKernelCommandLine= may be used to check whether a specific kernel command line option is set (or if prefixed with the exclamation mark โ€” unset). The argument must either be a single word, or an assignment (i.e. two words, separated by "="). In the former case the kernel command line is searched for the word appearing as is, or as left hand side of an assignment. In the latter case, the exact assignment is looked for with right and left hand side matching.

This operates on the kernel command line communicated to userspace via /proc/cmdline, except when the service manager is invoked as payload of a container manager, in which case the command line of PID 1 is used instead (i.e. /proc/1/cmdline). ๐Ÿงš

Added in version 244.


ConditionKernelVersion=

ConditionKernelVersion= may be used to check whether the kernel version (as reported by uname -r) matches a certain expression, or if prefixed with the exclamation mark, does not match.

The argument must be a list of (potentially quoted) expressions. Each expression starts with one of "=" or "!=" for string comparisons, "<", "<=", "==", "<>", ">=", ">" for version comparisons, or "$=", "!$=" for a shell-style glob match. If no operator is specified, "$=" is implied.

heads up bestie ๐Ÿšจ โ€” using the kernel version string is an unreliable way to determine which features are supported by a kernel, because of the widespread practice of backporting drivers, features, and fixes from newer upstream kernels into older versions provided by distributions. Hence, this check is inherently unportable and should not be used for units which may be used on different distributions.

Added in version 244.


ConditionVersion=

ConditionVersion= may be used to check whether a software version matches a certain expression, or if prefixed with the exclamation mark, does not match. ๐ŸŒˆ

The first argument is the software whose version has to be checked. Currently "kernel", "systemd" and "glibc" are supported. If this argument is omitted, "kernel" is implied. The second argument must be a list of (potentially quoted) expressions. Each expression starts with one of "=" or "!=" for string comparisons, "<", "<=", "==", "<>", ">=", ">" for version comparisons, or "$=", "!$=" for a shell-style glob match. If no operator is specified, "$=" is implied.

Added in version 258.


ConditionCredential=

ConditionCredential= may be used to check whether a credential by the specified name was passed into the service manager. ๐Ÿ”‘

See System and Service Credentials[4] for details about credentials. If used in services for the system service manager this may be used to conditionalize services based on system credentials passed in. If used in services for the per-user service manager this may be used to conditionalize services based on credentials passed into the unit@.service service instance belonging to the user. The argument must be a valid credential name.

Added in version 252.

  • ConditionEnvironment= โ€” bestie, this one does a vibe check on the service manager's own environment block ๐ŸŒธ wondering if a specific env var is set. You can pass a single word to check if that variable exists at all, or hand it an assignment like "name=value" to check that the variable is defined with that exact value. And if you prefix it with ! โ€” yup, exclamation mark โ€” the whole thing flips and it checks that the variable is unset. โš ๏ธ important tea: it checks the environment block of the service manager itself, not any variables you set with Environment= or EnvironmentFile= up above. That's a different thing entirely, no cap. This is lowkey iconic when the service manager is running inside a containerized environment or as a per-user service manager, so you can peek at variables passed in by the enclosing container manager or PAM. ๐Ÿซถ

Added in version 246.

  • ConditionSecurity= โ€” checks whether a given security technology is enabled on the system. โœจ Currently these values are recognized (Table 3, "Recognized security technologies" โ€” serving it as a list because we don't do tables here ๐Ÿ’…):
    • selinux โ€” SELinux MAC
    • apparmor โ€” AppArmor MAC
    • tomoyo โ€” Tomoyo MAC
    • smack โ€” SMACK MAC
    • ima โ€” Integrity Measurement Architecture (IMA)
    • audit โ€” Linux Audit Framework
    • uefi-secureboot โ€” UEFI SecureBoot
    • tpm2 โ€” Trusted Platform Module 2.0 (TPM2) (with full UEFI support, including the TCG PC Client Platform Firmware Profile)
    • cvm โ€” Confidential virtual machine (SEV/TDX)
    • measured-uki โ€” Unified Kernel Image with PCR 11 Measurements, as per systemd-stub(7). Added in version 255.
    • measured-os โ€” OS PCR measurements enabled. This is typically equivalent to measured-uki, however may also be set explicitly via the systemd.tpm2_measured_os= kernel command line switch, see kernel-command-line(7) for details. The various system services doing boot and runtime measurements are conditioned on this flag. Added in version 261.

The test may be negated by prepending an exclamation mark. ๐Ÿ™ˆ

Added in version 244.

  • ConditionCapability= โ€” checks whether the given capability exists in the capability bounding set of the service manager. ๐Ÿ‘‘ Heads up though โ€” this does not check whether the capability is actually available in the permitted or effective sets, so peep capabilities(7) for the full details. Pass a capability name like "CAP_MKNOD", and yes you can prefix it with an exclamation mark to negate the check. ๐Ÿ’…

Added in version 244.

  • ConditionACPower= โ€” checks whether the system has AC power, or is exclusively battery powered at the moment the unit activates. ๐Ÿ”Œ Takes a boolean argument. If you set it to "true", the condition holds only if at least one AC connector of the system is plugged into a power source, or if no AC connectors are known at all. Flip it: if you set it to "false", the condition holds only if there is at least one AC connector known and all of them are disconnected from a power source. Periodt.

Added in version 244.

  • ConditionNeedsUpdate= โ€” takes either /var/ or /etc/ as its argument, and you can prefix it with a "!" to invert the condition. ๐Ÿฆ‹ This one conditionalizes units on whether that directory needs an update, because /usr/'s modification time is newer than the stamp file .updated sitting in the specified directory. Super useful for implementing offline updates of vendor OS resources in /usr/ that need /etc/ or /var/ refreshed on the next boot. Units using this condition should order themselves before systemd-update-done.service(8) so they run before the stamp file's modification time gets reset (which signals a completed update).

If the systemd.condition_needs_update= option is specified on the kernel command line (it takes a boolean), it overrides the result of this condition check and takes precedence over any file modification time checks. If that kernel command line option is used, systemd-update-done.service will not have immediate effect on any following ConditionNeedsUpdate= checks, until the system is rebooted without the kernel command line option specified anymore. ๐Ÿ˜ญ

Note that to make this scheme effective, the timestamp of /usr/ should be explicitly updated after its contents are modified. The kernel automatically updates the modification timestamp on a directory only when immediate children of that directory are modified โ€” so modifying nested files will not automatically result in /usr/'s mtime being updated. ๐Ÿ’€

Also note that if the update method includes a call to execute the appropriate post-update steps itself, it should not touch the timestamp of /usr/. In a typical distribution packaging scheme, packages do any required update steps as part of installation or upgrade, making package contents immediately usable. ConditionNeedsUpdate= should be used with other update mechanisms where such an immediate update does not happen.

Added in version 244.

  • ConditionFirstBoot= โ€” takes a boolean argument, and it conditionalizes units on whether the system is booting up for the first time. ๐ŸŒธ Roughly, that means /etc/ was unpopulated when the system started booting (for details, see "First Boot Semantics" in machine-id(5)). First Boot is considered finished โ€” meaning this condition evaluates as false โ€” after the manager has finished the startup phase.

This condition may be used to populate /etc/ on the first boot after a factory reset, or when a new system instance boots up for the very first time. โœจ

Note that the service manager itself performs setup steps during First Boot: it initializes machine-id(5) and presets all units, enabling or disabling them according to the systemd.preset(5) settings. Additional setup may be performed via units with ConditionFirstBoot=yes.

For robustness, units with ConditionFirstBoot=yes should order themselves before first-boot-complete.target and pull in this passive target with Wants=. This ensures that in a case of an aborted first boot, these units get re-run during the next system startup. ๐Ÿซถ

If the systemd.condition_first_boot= option is specified on the kernel command line (it takes a boolean), it overrides the result of this condition check, taking precedence over /etc/machine-id existence checks.

Added in version 244.

  • ConditionPathExists= โ€” checks for the existence of a path. ๐Ÿ‘€ This applies to any file system object (regular file, directory, device node, FIFO, socket โ€” the whole roster), not just regular files. Symbolic links are followed, so a broken symbolic link is not considered to exist, no cap. If the specified absolute path name doesn't exist, the condition fails. And if the absolute path name you pass to ConditionPathExists= is prefixed with an exclamation mark ("!"), the test is negated โ€” meaning the unit only starts if the path does not exist. ๐Ÿ’…

Added in version 244.

  • ConditionPathExistsGlob= โ€” same energy as ConditionPathExists=, but it checks for the existence of at least one file or directory matching the specified globbing pattern. ๐ŸŒˆ

Added in version 244.

  • ConditionPathIsDirectory= โ€” also similar to ConditionPathExists=, but this one verifies that a certain path exists and is a directory. ๐Ÿ“

Added in version 244.

  • ConditionPathIsSymbolicLink= โ€” literally the same energy as ConditionPathExists=, except it ALSO needs that path to actually be a symbolic link. like, exists AND is a symlink, both, no exceptions bestie ๐Ÿ”—

Added in version 244.

  • ConditionPathIsMountPoint= โ€” again, sibling of ConditionPathExists=, but this one verifies the path exists and it's a mount point. is it a mount point or is it not, we're checking ๐ŸŽ€

Added in version 244.

  • ConditionPathIsReadWrite= โ€” ConditionPathExists= but make it read-write. it verifies that the underlying file system is readable AND writable โ€” i.e. it's not mounted read-only. no read-only vibes allowed ๐Ÿ’…

Added in version 244.

  • ConditionPathIsEncrypted= โ€” ConditionPathExists='s most paranoid cousin: it verifies that the underlying file system's backing block device is encrypted using dm-crypt/LUKS ๐Ÿ”. but bestie, listen, there are receipts on this one:
    • this check does not cover ext4 per-directory encryption โ€” it only detects block level encryption.
    • and if the specified path lives on a file system sitting on top of a loopback block device, only encryption above the loopback device is detected. it does not detect whether the file system backing the loopback block device is encrypted. so, yk, lowkey a narrow check.

Added in version 246.

  • ConditionPathIsSocket= โ€” you guessed it, ConditionPathExists= but it verifies that a certain path exists and is a socket ๐Ÿงฆ

Added in version 260.

  • ConditionDirectoryNotEmpty= โ€” ConditionPathExists=, but the path has to exist and be a non-empty directory. an empty directory? not passing, sorry, we need content โœจ

Added in version 244.

  • ConditionFileNotEmpty= โ€” ConditionPathExists= again, but the path must exist and refer to a regular file with a non-zero size. no zero-byte files in this house ๐Ÿ™ˆ

Added in version 244.

  • ConditionFileIsExecutable= โ€” ok so ConditionPathExists=, but the path must exist, be a regular file, and be marked executable. the little x bit is the moment ๐Ÿ‘‘

Added in version 244.

  • ConditionUser= โ€” takes a numeric UID, a UNIX user name, or the special value "@system". use it to check whether the service manager is running as the given user. the special value "@system" checks if the user id is inside the system user range. heads up though: this option is not useful for system services, because the system manager exclusively runs as the root user, so the test result is justโ€ฆ constant. like, it always gives the same answer. ๐Ÿ’€

Added in version 244.

  • ConditionGroup= โ€” the ConditionUser= girlie but for groups: verifies that the service manager's real or effective group, or any of its auxiliary groups, matches the specified group or GID. and nope, this setting does not support the special value "@system". periodt ๐Ÿซถ

Added in version 244.

  • ConditionControlGroupController= โ€” checks whether the given cgroup controllers (e.g. "cpu") are available for use on the system, or whether the legacy v1 cgroup hierarchy or the modern v2 cgroup hierarchy is in use.

you can pass multiple controllers separated by a space โ€” and in that case the condition only passes if all listed controllers are available for use. controllers unknown to systemd are ignored. the valid controllers are "cpu", "io", "memory", and "pids". and even if a controller is available in the kernel, it might not be available if it was disabled on the kernel command line with cgroup_disable=controller. sneaky ๐Ÿ”ฅ

alternatively, two special strings "v1" and "v2" may be specified (with no controller names). "v2" will pass if the unified v2 cgroup hierarchy is used, and "v1" will pass if the legacy v1 hierarchy or the hybrid hierarchy are used. and note: legacy or hybrid hierarchies have been deprecated. see systemd(1) for more info. ๐ŸŒˆ

Added in version 244.

  • ConditionMemory= โ€” verifies that the specified amount of system memory is available to the current system. takes a memory size in bytes as argument, optionally prefixed with a comparison operator: "<", "<=", "=" (or "=="), "!=" (or "<>"), ">=", ">". on bare-metal systems it compares the amount of physical memory in the system against the specified size, following whichever comparison operator you gave it. in containers, it compares the amount of memory assigned to the container instead. ๐Ÿง 

Added in version 244.

  • ConditionCPUs= โ€” verifies that the specified number of CPUs is available to the current system. takes a number of CPUs as argument, optionally prefixed with a comparison operator: "<", "<=", "=" (or "=="), "!=" (or "<>"), ">=", ">". it compares the number of CPUs in the CPU affinity mask configured for the service manager itself against the specified number, honoring the comparison operator. on physical systems that number usually matches the number of physical CPUs, but in special and virtual environments it might differ โ€” in particular, in containers the affinity mask usually matches the number of CPUs assigned to the container, not the physically available ones. ๐Ÿ˜ญ

Added in version 244.

  • ConditionCPUFeature= โ€” on i386 and x86-64, verifies that a given CPU feature is available via the "CPUID" instruction. it checks the leaves "1", "7", "0x80000001", and "0x80000007". the valid values are: "fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce", "cx8", "apic", "sep", "mtrr", "pge", "mca", "cmov", "pat", "pse36", "clflush", "mmx", "fxsr", "sse", "sse2", "ht", "pni", "pclmul", "monitor", "ssse3", "fma3", "cx16", "sse4_1", "sse4_2", "movbe", "popcnt", "aes", "xsave", "osxsave", "avx", "f16c", "rdrand", "bmi1", "avx2", "bmi2", "rdseed", "adx", "sha_ni", "syscall", "rdtscp", "lm", "lahf_lm", "abm", "constant_tsc".

on arm64, the valid values are the corresponding arm64 feature names, such as "asimd", "paca", "pacg", "bti", "mte", among others. for the full list, see the documentation on ARM64 ELF hwcaps[5] ๐Ÿ‘‘

to avoid ambiguities in mixed-architecture fleets, the value can be prefixed with the architecture name using the form "ARCH.FEATURE". if the architecture prefix doesn't match the running system, the condition evaluates to false. for example, you can specify "arm64.bti" on arm64 systems to check if "bti" is supported. in this example, "ConditionCPUFeature=arm64.bti" and "ConditionCPUFeature=bti" are functionally equivalent. see ConditionArchitecture= for valid architecture names. ๐Ÿฆ‹

on architectures other than x86 and arm64, it is assumed that the CPU does not support the given feature. like, no cap, we just assume nope.

Added in version 248.

  • ConditionOSRelease= โ€” verifies that a specific "key=value" pair is set in the host's os-release(5). ๐Ÿ“

other than exact string matching (with "=" and "!="), relative comparisons are supported for versioned parameters (e.g. "VERSION_ID"; with "<", "<=", "==", "<>", ">=", ">"), and shell-style wildcard comparisons ("*", "?", "[]") are supported with the "$=" (match) and "!$=" (non-match). โœจ

if the given key is not found in the file, the match is done against an empty value.

Added in version 249.

  • ConditionMachineTag= โ€” may be used to match against the tags assigned to the local machine. machine tags are short labels that classify and group machines for management purposes; they're configured in the TAGS= field of machine-info(5) and may be queried and changed with the tags command of hostnamectl(1). the argument is a single tag pattern, which is compared against each of the configured tags using shell-style globbing ("*", "?", "[]"). the condition is satisfied if at least one of the configured tags matches the pattern. the test may be negated by prepending an exclamation mark, in which case it is satisfied if none of the configured tags matches. ๐Ÿ’…

tags may be parameterized with a value in the form "key=value"; the "=" and the value are part of the tag and thus part of the string the pattern is matched against. hence "ConditionMachineTag=role=webserver" matches the tag "role=webserver" exactly, "ConditionMachineTag=role=*" matches any value assigned to the "role" key, and "ConditionMachineTag=role" (without "=") does not match "role=webserver". see machine-info(5) for the precise syntax of machine tags. ๐ŸŽ€

Added in version 261.

  • ConditionMemoryPressure=, ConditionCPUPressure=, ConditionIOPressure= โ€” verify that the overall system (memory, CPU or IO) pressure is below or equal to a threshold. this setting takes a threshold value as argument. it can be specified as a simple percentage value, suffixed with "%", in which case the pressure is measured as an average over the last five minutes before the attempt to start the unit is performed. alternatively, the average timespan can also be specified using "/" as a separator, for example: "10%/1min". the supported timespans match what the kernel provides, and are limited to "10sec", "1min" and "5min". the "full" PSI will be checked first, and if not found "some" will be checked. for more details, see the documentation on PSI (Pressure Stall Information)[6]. ๐ŸŒธ

optionally, the threshold value can be prefixed with the slice unit under which the pressure will be checked, followed by a ":". if the slice unit is not specified, the overall system pressure will be measured instead of a particular cgroup's. ๐Ÿซถ

Added in version 250.

  • ConditionKernelModuleLoaded= โ€” tests whether the specified kernel module has been loaded and is already fully initialized. not just loaded, bestie โ€” fully initialized. it's giving patient ๐Ÿงš

Added in version 258.

  • AssertArchitecture=
  • AssertVirtualization=
  • AssertHost=
  • AssertFraction=
  • AssertKernelCommandLine=
  • AssertKernelVersion=
  • AssertVersion=
  • AssertCredential=
  • AssertEnvironment=
  • AssertSecurity=
  • AssertCapability=
  • AssertACPower=
  • AssertNeedsUpdate=
  • AssertFirstBoot=
  • AssertPathExists=
  • AssertPathExistsGlob=
  • AssertPathIsDirectory=
  • AssertPathIsSymbolicLink=
  • AssertPathIsMountPoint=
  • AssertPathIsReadWrite=
  • AssertPathIsEncrypted=
  • AssertPathIsSocket=
  • AssertDirectoryNotEmpty=
  • AssertFileNotEmpty=
  • AssertFileIsExecutable=
  • AssertUser=
  • AssertGroup=
  • AssertControlGroupController=
  • AssertMemory=
  • AssertCPUs=
  • AssertCPUFeature=
  • AssertOSRelease=
  • AssertMachineTag=
  • AssertMemoryPressure=
  • AssertCPUPressure=
  • AssertIOPressure=
  • AssertKernelModuleLoaded=

So these are literally the same vibe as the ConditionArchitecture=, ConditionVirtualization=, โ€ฆ condition settings we just talked about, except they're the assertion girlies โ€” they add assertion checks to the start-up of the unit. ๐ŸŽ€

And here's the plot twist, bestie: unlike the condition settings, any assertion setting that is not met results in failure of the start job (which means this is logged loudly ๐Ÿ“ข). It's giving "I said what I said."

But lowkey important โ€” hitting a configured assertion does not cause the unit to enter the "failed" state (or in fact result in any state change of the unit at all, no cap). It affects only the job queued for it. ๐Ÿ™ˆ

Use assertion expressions for units that cannot operate when specific requirements are not met, and when this is something the administrator or user should look into. Like, this is a "hey, a human needs to see this" situation, not a "silently skip it" situation. ๐Ÿ’…

Added in version 218.


๐Ÿฆ‹ MAPPING OF UNIT PROPERTIES TO THEIR INVERSES ๐Ÿฆ‹

okay so this part is genuinely iconic, pay attention. Unit settings that create a relationship with a second unit usually show up in properties of both units โ€” for example in systemctl show output. In some cases the name of the property is the same as the name of the configuration setting, but not always. ๐Ÿคฏ

This table lists the properties that are shown on two units which are connected through some dependency, and shows which property on "source" unit corresponds to which property on "target" unit.

๐Ÿ’– Table 4. Forward and reverse unit properties

  • Forward property: Before= ยท Reverse property: After= ยท Where used: [Unit] section
  • Forward property: After= ยท Reverse property: Before= ยท Where used: [Unit] section
  • Forward property: Requires= ยท Reverse property: RequiredBy= ยท Where used: [Unit] section and [Install] section
  • Forward property: Wants= ยท Reverse property: WantedBy= ยท Where used: [Unit] section and [Install] section
  • Forward property: Upholds= ยท Reverse property: UpheldBy= ยท Where used: [Unit] section and [Install] section
  • Forward property: PartOf= ยท Reverse property: ConsistsOf= ยท Where used: [Unit] section and an automatic property
  • Forward property: BindsTo= ยท Reverse property: BoundBy= ยท Where used: [Unit] section and an automatic property
  • Forward property: Requisite= ยท Reverse property: RequisiteOf= ยท Where used: [Unit] section and an automatic property
  • Forward property: Conflicts= ยท Reverse property: ConflictedBy= ยท Where used: [Unit] section and an automatic property
  • Forward property: Triggers= ยท Reverse property: TriggeredBy= ยท Where used: Automatic properties, see notes below
  • Forward property: PropagatesReloadTo= ยท Reverse property: ReloadPropagatedFrom= ยท Where used: [Unit] section
  • Forward property: ReloadPropagatedFrom= ยท Reverse property: PropagatesReloadTo= ยท Where used: [Unit] section
  • Forward property: PropagatesStopTo= ยท Reverse property: StopPropagatedFrom= ยท Where used: [Unit] section
  • Forward property: StopPropagatedFrom= ยท Reverse property: PropagatesStopTo= ยท Where used: [Unit] section
  • Forward property: Following= ยท Reverse property: n/a ยท Where used: An automatic property

๐Ÿ’€ Note: WantedBy=, RequiredBy=, and UpheldBy= are used in the [Install] section to create symlinks in .wants/, .requires/, and .upholds/ directories. They cannot be used directly as a unit configuration setting. Not up for debate, bestie.
๐Ÿซถ Note: ConsistsOf=, BoundBy=, RequisiteOf=, ConflictedBy= are created implicitly along with their reverses and cannot be specified directly. They just spawn in, like, automatically. โœจ
๐ŸŒธ Note: Triggers= is created implicitly between a socket, path unit, or an automount unit, and the unit they activate. By default, a unit with the same name is triggered, but this can be overridden using Sockets=, Service=, and Unit= settings. See systemd.service(5), systemd.socket(5), systemd.path(5), and systemd.automount(5) for details. TriggeredBy= is created implicitly on the triggered unit. iykyk. ๐Ÿ’…
๐Ÿ‘‘ Note: Following= is used to group device aliases and points to the "primary" device unit that systemd is using to track device state, usually corresponding to a sysfs path. It does not show up in the "target" unit. Rude of it, honestly, but that's the rules. ๐Ÿฆ‹

โœจ [INSTALL] SECTION OPTIONS โœจ

okay so unit files can have an [Install] section too, and it's lowkey the glow-up section โ€” it's all the info about how the unit gets installed. Important thing tho: systemd(1) does NOT read this at runtime. Nope. It's purely for the enable and disable commands of systemctl(1) when you're actually installing a unit. So it's giving backstage, not main stage ๐Ÿ’…


  • Alias= โ€” a space-separated list of extra names this unit should get installed under. Heads up bestie: every name in here has to have the same suffix (i.e. the same type) as the unit filename itself. You can put this option more than once, and if you do, all the listed names get used. When you install, systemctl enable creates symlinks from these names pointing at the unit filename. โš ๏ธ But not every unit type supports alias names, and for those this setting just isn't supported โ€” specifically, mount, slice, swap, and automount units do not support aliasing. no aliases for you, sorry ๐Ÿซถ

Added in version 201.

  • WantedBy=, RequiredBy=, UpheldBy= โ€” you can use this more than once, or just hand it a space-separated list of unit names. When this unit gets installed by systemctl enable, a symlink is created in the .wants/, .requires/, or .upholds/ directory of each of the units you listed. The vibe? It's exactly like a dependency of type Wants=, Requires=, or Upholds= being added from the listed unit to the current unit. Peep the description of those dependency types in the [Unit] section for the full tea.

Now, the template unit situation ๐Ÿ‘‘ โ€” if template units are listing non-template units, the listing unit must have DefaultInstance= set, or else systemctl enable has to be called with an instance name. That instance (default or specified, whichever) gets added to the .wants/, .requires/, or .upholds/ list of the listed unit. For example, WantedBy=getty.target in a service getty@.service will make systemctl enable getty@tty2.service create a getty.target.wants/getty@tty2.service link to getty@.service. Same energy applies when you're listing specific instances of templated units: that specific instance will gain the dependency. Also a template unit can list a template unit, in which case a generic dependency gets added where every instance of the listing unit depends on an instance of the listed template with the same instance value. For example, WantedBy=container@.target in a service monitor@.service will make systemctl enable monitor@.service create a container@.target.wants/monitor@.service link to monitor@.service, and that applies to all instances of container@.target. slay ๐ŸŒˆ

Added in version 201.

  • Also= โ€” extra units to install/deinstall right along with this unit when it gets installed/deinstalled. So if the user asks to install/deinstall a unit that has this option configured, systemctl enable and systemctl disable will automatically install/uninstall the units listed here too. buy one get one fr fr

You can use this option more than once, or give it a space-separated list of unit names.

Added in version 201.

  • DefaultInstance= โ€” in template unit files, this says which instance the unit should be enabled for when the template gets enabled without any explicitly set instance. In non-template unit files this option does literally nothing, zero effect, doesn't even go here ๐Ÿ™ˆ The string you specify must be usable as an instance identifier.

Added in version 215.


The following specifiers are interpreted in the Install section: %a, %b, %B, %g, %G, %H, %i, %j, %l, %m, %n, %N, %o, %p, %u, %U, %v, %w, %W, %%. For their meaning, see the next section ๐Ÿ‘€

๐ŸŒŸ SPECIFIERS ๐ŸŒŸ

So many settings resolve specifiers, and that's the whole magic trick that lets you write generic unit files โ€” files that refer to runtime or unit parameters, which get swapped in for real values when the unit files are loaded. ๐Ÿช„

โš ๏ธ Big caveat tho: specifiers have to be known and resolvable for the setting to be valid. Can't resolve it? Not valid. Periodt.

The following specifiers are understood:

๐ŸŒธ Table 5 โ€” Specifiers available in unit files ๐ŸŒธ

okay bestie, this is the big specifier list, and every single one of these is a lil placeholder that systemd swaps out for real info when it loads your unit ๐Ÿ’– no cap, they all work the same way โ€” you drop the code in, systemd does the substitution, done.

  • %a โ€” Architecture. A short string identifying the architecture of the local system. A string such as x86, x86-64 or arm64. See the architectures defined for ConditionArchitecture= above for a full list. ๐Ÿ–ฅ๏ธ
  • %A โ€” Operating system image version. The operating system image version identifier of the running system, as read from the IMAGE_VERSION= field of /etc/os-release. If not set, resolves to an empty string. See os-release(5) for more information. ๐Ÿ“€
  • %b โ€” Boot ID. The boot ID of the running system, formatted as string. See random(4) for more information. ๐Ÿ”„
  • %B โ€” Operating system build ID. The operating system build identifier of the running system, as read from the BUILD_ID= field of /etc/os-release. If not set, resolves to an empty string. See os-release(5) for more information. ๐Ÿ—๏ธ
  • %C โ€” Cache directory root. This is either /var/cache (for the system manager) or the path $XDG_CACHE_HOME resolves to (for user managers). ๐Ÿ’พ
  • %d โ€” Credentials directory. This is the value of the $CREDENTIALS_DIRECTORY environment variable if available. See section "Credentials" in systemd.exec(5) for more information. ๐Ÿ”
  • %D โ€” Shared data directory. This is either /usr/share/ (for the system manager) or the path $XDG_DATA_HOME resolves to (for user managers). ๐Ÿ“š
  • %E โ€” Configuration directory root. This is either /etc/ (for the system manager) or the path $XDG_CONFIG_HOME resolves to (for user managers). โš™๏ธ
  • %f โ€” Unescaped filename. This is either the unescaped instance name (if applicable) with / prepended (if applicable), or the unescaped prefix name prepended with /. This implements unescaping according to the rules for escaping absolute file system paths discussed above. ๐Ÿ—‚๏ธ
  • %g โ€” User group. This is the name of the group running the service manager instance. In case of the system manager this resolves to root. ๐Ÿ‘‘
  • %G โ€” User GID. This is the numeric GID of the user running the service manager instance. In case of the system manager this resolves to 0. ๐Ÿ”ข
  • %h โ€” User home directory. This is the home directory of the user running the service manager instance. In case of the system manager this resolves to /root. ๐Ÿ 
heads up bestie: this setting is not influenced by the User= setting configurable in the [Service] section of the service unit. so don't be out here thinking User= changes your %h โ€” it does NOT. ๐Ÿ’…
  • %H โ€” Host name. The hostname of the running system at the point in time the unit configuration is loaded. ๐ŸŒ
  • %i โ€” Instance name. For instantiated units this is the string between the first @ character and the type suffix. Empty for non-instantiated units. โœจ

  • %I โ€” the unescaped instance name. It's giving %i energy but with all the escaping undone, so it's the raw, readable version. โœจ
  • %j โ€” final component of the prefix. This is the string between the last - and the end of the prefix name. And if there's literally no - in there? Then it's just the same as %p, bestie. ๐Ÿ’…
  • %J โ€” unescaped final component of the prefix. Same as %j, but with escaping undone. periodt.
  • %l โ€” short host name. This is the hostname of the running system at the point in time the unit configuration is loaded, truncated at the first dot to remove any domain component. so it's the hostname but make it โœ‚๏ธ short.
  • %L โ€” log directory root. This is either /var/log (for the system manager) or the path $XDG_STATE_HOME resolves to with /log appended (for user managers). ๐Ÿชต
  • %m โ€” machine ID. The machine ID of the running system, formatted as string. See machine-id(5) for more information. ๐Ÿ”‘
  • %M โ€” operating system image identifier. The operating system image identifier of the running system, as read from the IMAGE_ID= field of /etc/os-release. If not set, it resolves to an empty string. See os-release(5) for more information. ๐Ÿ–ผ๏ธ
  • %n โ€” full unit name. that's it, that's the whole vibe. ๐Ÿ‘‘
  • %N โ€” full unit name, but make it stripped. Same as %n, but with the type suffix removed. ๐ŸŽ€
  • %o โ€” operating system ID. The operating system identifier of the running system, as read from the ID= field of /etc/os-release. See os-release(5) for more information. ๐Ÿง
  • %p โ€” prefix name. For instantiated units, this refers to the string before the first @ character of the unit name. For non-instantiated units, same as %N. iykyk.
  • %P โ€” unescaped prefix name. Same as %p, but with escaping undone. ๐Ÿฆ‹
  • %q โ€” pretty host name. The pretty hostname of the running system at the point in time the unit configuration is loaded, as read from the PRETTY_HOSTNAME= field of /etc/machine-info. If not set, it resolves to the short hostname. See machine-info(5) for more information. she's pretty, she's iconic. ๐ŸŒธ
  • %s โ€” user shell. This is the shell of the user running the service manager instance. ๐Ÿš
  • %S โ€” state directory root. This is either /var/lib (for the system manager) or the path $XDG_STATE_HOME resolves to (for user managers). ๐Ÿ’พ
  • %t โ€” runtime directory root. This is either /run/ (for the system manager) or the path "$XDG_RUNTIME_DIR" resolves to (for user managers). ๐Ÿƒ
  • %T โ€” directory for temporary files. This is either /tmp or the path "$TMPDIR", "$TEMP" or "$TMP" are set to. (Note that the directory may be specified without a trailing slash.) โณ
  • %u โ€” user name. This is the name of the user running the service manager instance. In case of the system manager this resolves to "root". Note that this setting is not influenced by the User= setting configurable in the [Service] section of the service unit. ๐Ÿ™ˆ like, do not get it twisted, %u is not reading your User=.
  • %U โ€” user UID. This is the numeric UID of the user running the

Oh and also, bestie, quick heads-up: this setting is not influenced by the User= setting you can configure over in the [Service] section of the service unit. Like, zero crossover, they don't talk. ๐Ÿ™…โ€โ™€๏ธ


  • %v โ€” Kernel release. Literally identical to what uname -r spits out. ๐Ÿง
  • %V โ€” Directory for larger and persistent temporary files. This is either /var/tmp, or whatever path "$TMPDIR", "$TEMP" or "$TMP" happen to be set to. (Sneaky lil note: that directory might be specified with no trailing slash, so don't be shocked ๐Ÿ‘€)
  • %w โ€” Operating system version ID. The operating system version identifier of the running system, read straight from the VERSION_ID= field of /etc/os-release. If it's not set? You get an empty string, bestie, nothing more. See os-release(5) for the full lore. ๐Ÿ“–
  • %W โ€” Operating system variant ID. The operating system variant identifier of the running system, pulled from the VARIANT_ID= field of /etc/os-release. Not set โ†’ empty string, same deal. Again, os-release(5) has more if you're nosy. ๐Ÿฆ‹
  • %y โ€” The path to the fragment. This is the path where the main part of the unit file lives. For linked unit files, the real path outside of the unit search directories gets used instead. And for units that don't have a fragment file at all? This specifier will straight up raise an error. ๐Ÿ’€ So likeโ€ฆ know your units.
  • %Y โ€” The directory of the fragment. It's just the directory part of "%y". Simple. Clean. Iconic. โœจ
  • %% โ€” Single percent sign. Use "%%" in place of "%" whenever you want one single percent sign to actually show up. Yes, it's the escape-the-escape move, and yes, you will forget it at least once. ๐ŸŽ€

โœจ EXAMPLES โœจ

okay bestie, time for the fun part โ€” actual real-life scenarios, no cap ๐Ÿ’…


๐ŸŽ€ Example 1. Allowing units to be enabled

so like, this little snippet (the highlighted bit) is literally all it takes to let a unit โ€” say foo.service โ€” be enabled with systemctl enable:

[Unit]
Description=Foo

[Service]
ExecStart=/usr/sbin/foo-daemon

[Install]
WantedBy=multi-user.target

and then once you run systemctl enable, a symlink gets created at /etc/systemd/system/multi-user.target.wants/foo.service, pointing at the actual unit. it's giving personal assistant energy tbh ๐Ÿซถ โ€” that symlink tells systemd to pull the unit in whenever it starts multi-user.target. and the inverse, systemctl disable, just removes that symlink again. iconic. periodt.


๐ŸŒธ Example 2. Overriding vendor settings

so there's two ways to override vendor settings in unit files, and ngl they both have their moments:

  1. copy the unit file from /usr/lib/systemd/system to /etc/systemd/system and then edit the settings you actually care about. OR
  2. make a directory called unit.d/ inside /etc/systemd/system, drop a file named name.conf in there, and only change the specific settings you're interested in.

and heads up: if multiple such drop-in files are present, systemd reads all of them, processing them in lexicographic order of their filename ๐Ÿ”ค

method one pros and cons: the slay part is that you override the complete unit, easy peasy โ€” the vendor unit isn't even parsed anymore. the not-so-slay part is that any improvements the vendor makes to that unit file won't be automatically incorporated when you update ๐Ÿ˜ญ

method two pros and cons: the slay part is that you only override the settings you specifically want, so vendor updates apply automatically. the not-so-slay part is that some future vendor updates might be incompatible with your local changes. it's a vibe. ๐Ÿคท

this whole thing also applies to user instances of systemd, just with different locations for the unit files โ€” check the unit load paths section for the deets.

okay so picture this: there's a vendor-supplied unit at /usr/lib/systemd/system/httpd.service that looks like this:

[Unit]
Description=Some HTTP Server
After=remote-fs.target sqldb.service
Requires=sqldb.service
AssertPathExists=/srv/webserver

[Service]
Type=notify
ExecStart=/usr/sbin/some-fancy-httpd-server
Nice=5

[Install]
WantedBy=multi-user.target

now our admin bestie wants to change a few things. first up: in the local setup, /srv/webserver might not exist, because the HTTP server is configured to use /srv/www instead. second: the local config makes the HTTP server also depend on a memory cache service, memcached.service, which should be pulled in (Requires=) and also ordered appropriately (After=). third: to harden the service a lil more, the admin wants to set the PrivateTmp= setting (go look at systemd.exec(5) for the details, iykyk). and lastly: they wanna reset the niceness of the service back to its default value of 0.

possibility one โ€” copy the unit file over to /etc/systemd/system/httpd.service and change the chosen settings:

[Unit]
Description=Some HTTP Server
After=remote-fs.target sqldb.service memcached.service
Requires=sqldb.service memcached.service
AssertPathExists=/srv/www

[Service]
Type=notify
ExecStart=/usr/sbin/some-fancy-httpd-server
Nice=0
PrivateTmp=yes

[Install]
WantedBy=multi-user.target

or alternatively โ€” the admin could create a drop-in file at /etc/systemd/system/httpd.service.d/local.conf with these contents:

[Unit]
After=memcached.service
Requires=memcached.service
# Reset all assertions and then re-add the condition we want
AssertPathExists=
AssertPathExists=/srv/www

[Service]
Nice=0
PrivateTmp=yes
โš ๏ธ okay real talk, this one matters: for drop-in files, if you want to remove entries from a setting that's parsed as a list (and isn't a dependency) โ€” like AssertPathExists= or, say, ExecStart= in service units โ€” you need to first clear the list before re-adding all the entries except the one you're removing. and dependencies (After=, etc.) cannot be reset to an empty list, so dependencies can only ever be added in drop-ins. if you want to remove dependencies, you have to override the entire unit. no shortcuts, bestie ๐Ÿ’€

๐Ÿฆ‹ Example 3. Top level drop-ins with template units

top level per-type drop-ins are lowkey genius โ€” they let you change some aspect of all units of a particular type. for example, by creating the /etc/systemd/system/service.d/ directory with a drop-in file inside, the contents of that drop-in get applied to every single service unit. and we can take this even further by having the top-level drop-in instantiate a secondary helper unit ๐Ÿ‘‘

consider, for example, this set of units and drop-in files where we install an OnFailure= dependency for all service units:

/etc/systemd/system/failure-handler@.service:

[Unit]
Description=My Failure Handler For %i

[Service]
Type=oneshot
# Perform some special action for when %i exits unexpectedly.
ExecStart=/usr/sbin/myfailurehandler %i

and then we can add an instance of failure-handler@.service as an OnFailure= dependency for all service units:

/etc/systemd/system/service.d/10-all.conf:

[Unit]
OnFailure=failure-handler@%N.service

now, after running systemctl daemon-reload, all services will have acquired an OnFailure= dependency on failure-handler@%N.service. the thing is though โ€” the template instance units will also have gained that dependency, which results in the creation of a recursive dependency chain ๐Ÿ˜ตโ€๐Ÿ’ซ systemd will try to detect these recursive dependency chains, where a template unit directly and recursively depends on itself, and it'll remove such dependencies automatically if it finds them. but if systemd does not detect the recursive dependency chain, we can break the chain ourselves by disabling the drop-in for the template instance units via a symlink to /dev/null:

mkdir /etc/systemd/system/failure-handler@.service.d/
ln -s /dev/null /etc/systemd/system/failure-handler@.service.d/10-all.conf
systemctl daemon-reload

this ensures that if a failure-handler@.service instance fails, it will not trigger an instance named failure-handler@failure-handler.service. crisis averted, bestie ๐Ÿงš


๐Ÿ‘€ SEE ALSO

go read these next, they're all bangers fr fr:


๐Ÿ“ NOTES

  1. Interface Portability and Stability Promise โ€” https://systemd.io/PORTABILITY_AND_STABILITY/
  2. ๐Ÿ’ฃ๐Ÿ’ฅ๐Ÿงจ๐Ÿ’ฅ๐Ÿ’ฅ๐Ÿ’ฃ Please note that those configuration files must be available at all times. If /usr/local/ is a separate partition, it may not be available during early boot, and must not be used for configuration.
  3. systemd and Storage Daemons for the Root File System โ€” https://systemd.io/ROOT_STORAGE_DAEMONS
  4. System and Service Credentials โ€” https://systemd.io/CREDENTIALS
  5. ARM64 ELF hwcaps โ€” https://docs.kernel.org/arch/arm64/elf_hwcaps.html
  6. PSI (Pressure Stall Information) โ€” https://docs.kernel.org/accounting/psi.html

and that's a wrap on SYSTEMD.UNIT(5) bestie!! ๐ŸŽ‰๐Ÿ’– this was the systemd 262.1 version of the page, and you just finished reading the whole thing โ€” main character energy, honestly ๐Ÿ‘‘ you now know more about unit files than 99% of people who use Linux, no cap. go forth and write the most gorgeous .service files the world has ever seen. slay, stay safe, and remember: never Nice= a unit you don't understand ๐ŸŒˆโœจ๐Ÿ’…

๐Ÿ“ฆ where this page comes from
  • arch rolling: systemd 262.1-1 ยท LGPL-2.1-or-later AND CC0-1.0 AND GPL-2.0-or-later AND MIT-0
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms