Generators are small binaries that live in
/usr/lib/systemd/user-generators/ and other directories listed above.
systemd(1) will execute those binaries very early at bootup and at
configuration reload time — before unit files are loaded. Generators
can dynamically generate unit files or create symbolic links to unit
files to add additional dependencies, thus extending or overriding
existing definitions. Their main purpose is to convert configuration
files that are not native unit files dynamically into native unit
Generators are loaded from a set of paths determined during
compilation, as listed above. System and user generators are loaded
from directories with names ending in system-generators/ and
user-generators/, respectively. Generators found in directories
listed earlier override the ones with the same name in directories
lower in the list. A symlink to /dev/null or an empty file can be
used to mask a generator, thereby preventing it from running. Please
note that the order of the two directories with the highest priority
is reversed with respect to the unit load path, and generators in
/run overwrite those in /etc.
After installing new generators or updating the configuration,
systemctl daemon-reload may be executed. This will delete the
previous configuration created by generators, re-run all generators,
and cause systemd to reload units from disk. See systemctl(1) for
Generators are invoked with three arguments: paths to runtime
directories where generators can place their generated unit files or
argv may be used to override unit files in /usr, but not those
in /etc. This means that unit files placed in this directory take
precedence over vendor unit configuration but not over native
user/administrator unit configuration.
argv may be used to override unit files in /usr and in /etc.
This means that unit files placed in this directory take
precedence over all configuration, both vendor and
argv may be used to extend the unit file tree without
overriding any other unit files. Any native configuration files
supplied by the vendor or user/administrator take precedence over
the generated ones placed in this directory.
· All generators are executed in parallel. That means all
executables are started at the very same time and need to be able
to cope with this parallelism.
· Generators are run very early at boot and cannot rely on any
external services. They may not talk to any other process. That
includes simple things such as logging to syslog(3), or systemd
itself (this means: no systemctl(1))! Non-essential file systems
like /var and /home are mounted after generators have run.
Generators can however rely on the most basic kernel
functionality to be available, including a mounted /sys, /proc,
· Units written by generators are removed when the configuration is
reloaded. That means the lifetime of the generated units is
closely bound to the reload cycles of systemd itself.
· Generators should only be used to generate unit files, not any
other kind of configuration. Due to the lifecycle logic mentioned
above, generators are not a good fit to generate dynamic
configuration for other services. If you need to generate dynamic
configuration for other services, do so in normal services you
order before the service in question.
· Since syslog(3) is not available (see above), log messages have
to be written to /dev/kmsg instead.
· It is a good idea to use the SourcePath= directive in generated
unit files to specify the source configuration file you are
generating the unit from. This makes things more easily
understood by the user and also has the benefit that systemd can
warn the user about configuration files that changed on disk but
have not been read yet by systemd.
· Generators may write out dynamic unit files or just hook unit
files into other units with the usual .wants/ or .requires/
symlinks. Often, it is nicer to simply instantiate a template
unit file from /usr with a generator instead of writing out
entirely dynamic unit files. Of course, this works only if a
single parameter is to be used.
· If you are careful, you can implement generators in shell
scripts. We do recommend C code however, since generators are
executed synchronously and hence delay the entire boot if they
· Regarding overriding semantics: there are two rules we try to
follow when thinking about the overriding semantics:
1. User configuration should override vendor configuration. This
(mostly) means that stuff from /etc should override stuff
2. Native configuration should override non-native
configuration. This (mostly) means that stuff you generate
should never override native unit files for the same purpose.
Of these two rules the first rule is probably the more important
one and breaks the second one sometimes. Hence, when deciding
whether to user argv, argv, or argv, your default choice
should probably be argv.
· Instead of heading off now and writing all kind of generators for
legacy configuration file formats, please think twice! It is
often a better idea to just deprecate old stuff instead of
keeping it artificially alive.
Example 1. systemd-fstab-generatorsystemd-fstab-generator(8) converts /etc/fstab into native mount
units. It uses argv as location to place the generated unit files
in order to allow the user to override /etc/fstab with her own native
unit files, but also to ensure that /etc/fstab overrides any vendor
default from /usr.
After editing /etc/fstab, the user should invoke systemctldaemon-reload. This will re-run all generators and cause systemd to
reload units from disk. To actually mount new directories added to
fstab, systemctl start /path/to/mountpoint or systemctl startlocal-fs.target may be used.
Example 2. systemd-system-update-generatorsystemd-system-update-generator(8) temporarily redirects
default.target to system-update.target, if a system update is
scheduled. Since this needs to override the default user
configuration for default.target, it uses argv. For details about
this logic, see systemd.offline-updates(7).
Example 3. Debugging a generator
SYSTEMD_LOG_LEVEL=debug /usr/lib/systemd/system-generators/systemd-fstab-generator \
"$dir" "$dir" "$dir"
This page is part of the systemd (systemd system and service manager)
project. Information about the project can be found at
⟨http://www.freedesktop.org/wiki/Software/systemd⟩. If you have a bug
report for this manual page, see
page was obtained from the project's upstream Git repository
⟨https://github.com/systemd/systemd.git⟩ on 2017-03-13. If you dis‐
cover any rendering problems in this HTML version of the page, or you
believe there is a better or more up-to-date source for the page, or
you have corrections or improvements to the information in this
COLOPHON (which is not part of the original manual page), send a mail
systemd 233 SYSTEMD.GENERATOR(7)