1SYSTEMD.GENERATOR(7)           systemd.generator          SYSTEMD.GENERATOR(7)
2
3
4

NAME

6       systemd.generator - systemd unit generators
7

SYNOPSIS

9       /path/to/generator normal-dir early-dir late-dir
10
11       /run/systemd/system-generators/*
12       /etc/systemd/system-generators/*
13       /usr/local/lib/systemd/system-generators/*
14       /usr/lib/systemd/system-generators/*
15
16       /run/systemd/user-generators/*
17       /etc/systemd/user-generators/*
18       /usr/local/lib/systemd/user-generators/*
19       /usr/lib/systemd/user-generators/*
20
21

DESCRIPTION

23       Generators are small executables that live in
24       /usr/lib/systemd/system-generators/ and other directories listed above.
25       systemd(1) will execute those binaries very early at bootup and at
26       configuration reload time — before unit files are loaded. Their main
27       purpose is to convert configuration that is not native into dynamically
28       generated unit files.
29
30       Each generator is called with three directory paths that are to be used
31       for generator output. In these three directories, generators may
32       dynamically generate unit files (regular ones, instances, as well as
33       templates), unit file .d/ drop-ins, and create symbolic links to unit
34       files to add additional dependencies, create aliases, or instantiate
35       existing templates. Those directories are included in the unit load
36       path of systemd(1), allowing generated configuration to extend or
37       override existing definitions.
38
39       Directory paths for generator output differ by priority:
40       .../generator.early has priority higher than the admin configuration in
41       /etc, while .../generator has lower priority than /etc but higher than
42       vendor configuration in /usr, and .../generator.late has priority lower
43       than all other configuration. See the next section and the discussion
44       of unit load paths and unit overriding in systemd.unit(5).
45
46       Generators are loaded from a set of paths determined during
47       compilation, as listed above. System and user generators are loaded
48       from directories with names ending in system-generators/ and
49       user-generators/, respectively. Generators found in directories listed
50       earlier override the ones with the same name in directories lower in
51       the list. A symlink to /dev/null or an empty file can be used to mask a
52       generator, thereby preventing it from running. Please note that the
53       order of the two directories with the highest priority is reversed with
54       respect to the unit load path, and generators in /run overwrite those
55       in /etc.
56
57       After installing new generators or updating the configuration,
58       systemctl daemon-reload may be executed. This will delete the previous
59       configuration created by generators, re-run all generators, and cause
60       systemd to reload units from disk. See systemctl(1) for more
61       information.
62

OUTPUT DIRECTORIES

64       Generators are invoked with three arguments: paths to directories where
65       generators can place their generated unit files or symlinks. By default
66       those paths are runtime directories that are included in the search
67       path of systemd, but a generator may be called with different paths for
68       debugging purposes.
69
70        1. normal-dir
71
72           In normal use this is /run/systemd/generator in case of the system
73           generators and $XDG_RUNTIME_DIR/generator in case of the user
74           generators. Unit files placed in this directory take precedence
75           over vendor unit configuration but not over native
76           user/administrator unit configuration.
77
78        2. early-dir
79
80           In normal use this is /run/systemd/generator.early in case of the
81           system generators and $XDG_RUNTIME_DIR/generator.early in case of
82           the user generators. Unit files placed in this directory override
83           unit files in /usr, /run and /etc. This means that unit files
84           placed in this directory take precedence over all normal
85           configuration, both vendor and user/administrator.
86
87        3. late-dir
88
89           In normal use this is /run/systemd/generator.late in case of the
90           system generators and $XDG_RUNTIME_DIR/generator.late in case of
91           the user generators. This directory may be used to extend the unit
92           file tree without overriding any other unit files. Any native
93           configuration files supplied by the vendor or user/administrator
94           take precedence.
95

NOTES ABOUT WRITING GENERATORS

97       ·   All generators are executed in parallel. That means all executables
98           are started at the very same time and need to be able to cope with
99           this parallelism.
100
101       ·   Generators are run very early at boot and cannot rely on any
102           external services. They may not talk to any other process. That
103           includes simple things such as logging to syslog(3), or systemd
104           itself (this means: no systemctl(1))! Non-essential file systems
105           like /var and /home are mounted after generators have run.
106           Generators can however rely on the most basic kernel functionality
107           to be available, including a mounted /sys, /proc, /dev, /usr.
108
109       ·   Units written by generators are removed when the configuration is
110           reloaded. That means the lifetime of the generated units is closely
111           bound to the reload cycles of systemd itself.
112
113       ·   Generators should only be used to generate unit files and symlinks
114           to them, not any other kind of configuration. Due to the lifecycle
115           logic mentioned above, generators are not a good fit to generate
116           dynamic configuration for other services. If you need to generate
117           dynamic configuration for other services, do so in normal services
118           you order before the service in question.
119
120       ·   Since syslog(3) is not available (see above), log messages have to
121           be written to /dev/kmsg instead.
122
123       ·   It is a good idea to use the SourcePath= directive in generated
124           unit files to specify the source configuration file you are
125           generating the unit from. This makes things more easily understood
126           by the user and also has the benefit that systemd can warn the user
127           about configuration files that changed on disk but have not been
128           read yet by systemd.
129
130       ·   Generators may write out dynamic unit files or just hook unit files
131           into other units with the usual .wants/ or .requires/ symlinks.
132           Often, it is nicer to simply instantiate a template unit file from
133           /usr with a generator instead of writing out entirely dynamic unit
134           files. Of course, this works only if a single parameter is to be
135           used.
136
137       ·   If you are careful, you can implement generators in shell scripts.
138           We do recommend C code however, since generators are executed
139           synchronously and hence delay the entire boot if they are slow.
140
141       ·   Regarding overriding semantics: there are two rules we try to
142           follow when thinking about the overriding semantics:
143
144            1. User configuration should override vendor configuration. This
145               (mostly) means that stuff from /etc should override stuff from
146               /usr.
147
148            2. Native configuration should override non-native configuration.
149               This (mostly) means that stuff you generate should never
150               override native unit files for the same purpose.
151
152           Of these two rules the first rule is probably the more important
153           one and breaks the second one sometimes. Hence, when deciding
154           whether to use argv[1], argv[2], or argv[3], your default choice
155           should probably be argv[1].
156
157       ·   Instead of heading off now and writing all kind of generators for
158           legacy configuration file formats, please think twice! It is often
159           a better idea to just deprecate old stuff instead of keeping it
160           artificially alive.
161

EXAMPLES

163       Example 1. systemd-fstab-generator
164
165       systemd-fstab-generator(8) converts /etc/fstab into native mount units.
166       It uses argv[1] as location to place the generated unit files in order
167       to allow the user to override /etc/fstab with her own native unit
168       files, but also to ensure that /etc/fstab overrides any vendor default
169       from /usr.
170
171       After editing /etc/fstab, the user should invoke systemctl
172       daemon-reload. This will re-run all generators and cause systemd to
173       reload units from disk. To actually mount new directories added to
174       fstab, systemctl start /path/to/mountpoint or systemctl start
175       local-fs.target may be used.
176
177       Example 2. systemd-system-update-generator
178
179       systemd-system-update-generator(8) temporarily redirects default.target
180       to system-update.target, if a system update is scheduled. Since this
181       needs to override the default user configuration for default.target, it
182       uses argv[2]. For details about this logic, see systemd.offline-
183       updates(7).
184
185       Example 3. Debugging a generator
186
187           dir=$(mktemp -d)
188           SYSTEMD_LOG_LEVEL=debug /usr/lib/systemd/system-generators/systemd-fstab-generator \
189                   "$dir" "$dir" "$dir"
190           find $dir
191

SEE ALSO

193       systemd(1), systemd-cryptsetup-generator(8), systemd-debug-
194       generator(8), systemd-fstab-generator(8), fstab(5), systemd-getty-
195       generator(8), systemd-gpt-auto-generator(8), systemd-hibernate-resume-
196       generator(8), systemd-rc-local-generator(8), systemd-system-update-
197       generator(8), systemd-sysv-generator(8), systemd.unit(5), systemctl(1),
198       systemd.environment-generator(7)
199
200
201
202systemd 239                                               SYSTEMD.GENERATOR(7)
Impressum