Debian Codegraph @

upstream/debian-unstable/man7/systemd.generator.7

raw
1 '\" t
2 .TH "SYSTEMD\&.GENERATOR" "7" "" "systemd 261~rc3" "systemd.generator"
3 .\" -----------------------------------------------------------------
4 .\" * Define some portability stuff
5 .\" -----------------------------------------------------------------
6 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 .\" http://bugs.debian.org/507673
8 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
9 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 .ie \n(.g .ds Aq \(aq
11 .el .ds Aq '
12 .\" -----------------------------------------------------------------
13 .\" * set default formatting
14 .\" -----------------------------------------------------------------
15 .\" disable hyphenation
16 .nh
17 .\" disable justification (adjust text to left margin only)
18 .ad l
19 .\" -----------------------------------------------------------------
20 .\" * MAIN CONTENT STARTS HERE *
21 .\" -----------------------------------------------------------------
22 .SH "NAME"
23 systemd.generator \- systemd unit generators
24 .SH "SYNOPSIS"
25 .HP \w'\fB/path/to/generator\fR\ 'u
26 \fB/path/to/generator\fR \fInormal\-dir\fR [\fIearly\-dir\fR] [\fIlate\-dir\fR]
27 .PP
28 .RS 4
29 /run/systemd/system\-generators/*
30 .RE
31 .RS 4
32 /etc/systemd/system\-generators/*
33 .RE
34 .RS 4
35 /usr/local/lib/systemd/system\-generators/*
36 .RE
37 .RS 4
38 /usr/lib/systemd/system\-generators/*
39 .RE
40 .PP
41 .RS 4
42 /run/systemd/user\-generators/*
43 .RE
44 .RS 4
45 /etc/systemd/user\-generators/*
46 .RE
47 .RS 4
48 /usr/local/lib/systemd/user\-generators/*
49 .RE
50 .RS 4
51 /usr/lib/systemd/user\-generators/*
52 .RE
53 .SH "DESCRIPTION"
54 .PP
55 Generators are small executables placed in
56 /usr/lib/systemd/system\-generators/
57 and other directories listed above\&.
58 \fBsystemd\fR(1)
59 will execute these binaries very early at bootup and at configuration reload time \(em before unit files are loaded\&. Their main purpose is to convert configuration and execution context parameters that are not native to the service manager into dynamically generated unit files, symlinks or unit file drop\-ins, so that they can extend the unit file hierarchy the service manager subsequently loads and operates on\&.
60 .PP
61 \fBsystemd\fR
62 will call each generator with three directory paths that are to be used for generator output\&. In these three directories, generators may dynamically generate unit files (regular ones, instances, as well as templates), unit file
63 \&.d/
64 drop\-ins, and create symbolic links to unit files to add additional dependencies, create aliases, or instantiate existing templates\&. Those directories are included in the unit load path, allowing generated configuration to extend or override existing definitions\&. For tests, generators may be called with just one argument; the generator should assume that all three paths are the same in that case\&.
65 .PP
66 Generators executed by the system manager are invoked in a sandbox with a private writable
67 /tmp/
68 directory and where most of the file system is read\-only except for the generator output directories\&.
69 .PP
70 Directory paths for generator output differ by priority:
71 \&.../generator\&.early
72 has priority higher than the admin configuration in
73 /etc/, while
74 \&.../generator
75 has lower priority than
76 /etc/
77 but higher than vendor configuration in
78 /usr/, and
79 \&.../generator\&.late
80 has priority lower than all other configuration\&. See the next section and the discussion of unit load paths and unit overriding in
81 \fBsystemd.unit\fR(5)\&.
82 .PP
83 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
84 system\-generators/
85 and
86 user\-generators/, respectively\&. Generators found in directories listed earlier override the ones with the same name in directories lower in the list
87 \&\s-2\u[1]\d\s+2\&. A symlink to
88 /dev/null
89 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
90 /run/
91 overwrite those in
92 /etc/\&.
93 .PP
94 After installing new generators or updating the configuration,
95 \fBsystemctl daemon\-reload\fR
96 may be executed\&. This will delete the previous configuration created by generators, re\-run all generators, and cause
97 \fBsystemd\fR
98 to reload units from disk\&. See
99 \fBsystemctl\fR(1)
100 for more information\&.
101 .SH "OUTPUT DIRECTORIES"
102 .PP
103 Generators are invoked with three arguments: paths to directories where generators can place their generated unit files or symlinks\&. By default, those paths are runtime directories that are included in the search path of
104 \fBsystemd\fR, but a generator may be called with different paths for debugging purposes\&. If only one argument is provided, the generator should use the same directory as the three output paths\&.
105 .sp
106 .RS 4
107 .ie n \{\
108 \h'-04' 1.\h'+01'\c
109 .\}
110 .el \{\
111 .sp -1
112 .IP " 1." 4.2
113 .\}
114 \fInormal\-dir\fR
115 .sp
116 In normal use this is
117 /run/systemd/generator
118 in case of the system generators and
119 $XDG_RUNTIME_DIR/systemd/generator
120 in case of the user generators\&. Unit files placed in this directory take precedence over vendor unit configuration but not over native user/administrator unit configuration\&.
121 .RE
122 .sp
123 .RS 4
124 .ie n \{\
125 \h'-04' 2.\h'+01'\c
126 .\}
127 .el \{\
128 .sp -1
129 .IP " 2." 4.2
130 .\}
131 \fIearly\-dir\fR
132 .sp
133 In normal use this is
134 /run/systemd/generator\&.early
135 in case of the system generators and
136 $XDG_RUNTIME_DIR/systemd/generator\&.early
137 in case of the user generators\&. Unit files placed in this directory override unit files in
138 /usr/,
139 /run/
140 and
141 /etc/\&. This means that unit files placed in this directory take precedence over all normal configuration, both vendor and user/administrator\&.
142 .RE
143 .sp
144 .RS 4
145 .ie n \{\
146 \h'-04' 3.\h'+01'\c
147 .\}
148 .el \{\
149 .sp -1
150 .IP " 3." 4.2
151 .\}
152 \fIlate\-dir\fR
153 .sp
154 In normal use this is
155 /run/systemd/generator\&.late
156 in case of the system generators and
157 $XDG_RUNTIME_DIR/systemd/generator\&.late
158 in case of the user generators\&. This directory 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\&.
159 .RE
160 .PP
161 Note: generators
162 \fImust not\fR
163 write to other locations or otherwise make changes to system state\&. Generator output is supposed to last only until the next
164 \fBdaemon\-reload\fR
165 or
166 \fBdaemon\-reexec\fR; if the generator is replaced or masked, its effects should vanish\&.
167 .SH "ENVIRONMENT"
168 .PP
169 The service manager sets a number of environment variables when invoking generator executables\&. They carry information about the execution context of the generator, in order to simplify conditionalizing generators to specific environments\&. The following environment variables are set:
170 .PP
171 \fI$SYSTEMD_SCOPE\fR
172 .RS 4
173 If the generator is invoked from the system service manager this variable is set to
174 "system"; if invoked from the per\-user service manager it is set to
175 "user"\&.
176 .sp
177 Added in version 251\&.
178 .RE
179 .PP
180 \fI$SYSTEMD_IN_INITRD\fR
181 .RS 4
182 If the generator is run as part of an initrd this is set to
183 "1"\&. If it is run from the regular host (i\&.e\&. after the transition from initrd to host) it is set to
184 "0"\&. This environment variable is only set for system generators\&.
185 .sp
186 Added in version 251\&.
187 .RE
188 .PP
189 \fI$SYSTEMD_SOFT_REBOOTS_COUNT\fR
190 .RS 4
191 If the system has soft\-rebooted, this variable is set to the count of soft\-reboots\&. This environment variable is only set for system generators\&.
192 .sp
193 Added in version 257\&.
194 .RE
195 .PP
196 \fI$SYSTEMD_FIRST_BOOT\fR
197 .RS 4
198 If this boot\-up cycle is considered a "first boot", this is set to
199 "1"; if it is a subsequent, regular boot it is set to
200 "0"\&. For details see the documentation of
201 \fIConditionFirstBoot=\fR
202 in
203 \fBsystemd.unit\fR(5)\&. This environment variable is only set for system generators\&.
204 .sp
205 Added in version 251\&.
206 .RE
207 .PP
208 \fI$SYSTEMD_VIRTUALIZATION\fR
209 .RS 4
210 If the service manager is run in a virtualized environment,
211 \fI$SYSTEMD_VIRTUALIZATION\fR
212 is set to a pair of strings, separated by a colon\&. The first string is either
213 "vm"
214 or
215 "container", categorizing the type of virtualization\&. The second string identifies the implementation of the virtualization technology\&. If no virtualization is detected this variable will not be set\&. This data is identical to what
216 \fBsystemd-detect-virt\fR(1)
217 detects and reports, and uses the same vocabulary of virtualization implementation identifiers\&.
218 .sp
219 Added in version 251\&.
220 .RE
221 .PP
222 \fI$SYSTEMD_ARCHITECTURE\fR
223 .RS 4
224 This variable is set to a short identifier of the reported architecture of the system\&. For details about defined values, see documentation of
225 \fIConditionArchitecture=\fR
226 in
227 \fBsystemd.unit\fR(5)\&.
228 .sp
229 Added in version 251\&.
230 .RE
231 .PP
232 \fI$CREDENTIALS_DIRECTORY\fR, \fI$ENCRYPTED_CREDENTIALS_DIRECTORY\fR
233 .RS 4
234 If set, refers to the directory system credentials have been placed in\&. Credentials passed into the system in plaintext form will be placed in
235 \fI$CREDENTIALS_DIRECTORY\fR, and those passed in in encrypted form will be placed in
236 \fI$ENCRYPTED_CREDENTIALS_DIRECTORY\fR\&. Use the
237 \fBsystemd-creds\fR(1)
238 command to automatically decrypt/authenticate credentials passed in, if needed\&. Specifically, use the
239 \fBsystemd\-creds \-\-system cat\fR
240 command\&.
241 .sp
242 Added in version 254\&.
243 .RE
244 .PP
245 \fI$SYSTEMD_CONFIDENTIAL_VIRTUALIZATION\fR
246 .RS 4
247 If the service manager is run in a confidential virtualized environment,
248 \fI$SYSTEMD_CONFIDENTIAL_VIRTUALIZATION\fR
249 is set to a string that identifies the confidential virtualization hardware technology\&. If no confidential virtualization is detected this variable will not be set\&. This data is identical to what
250 \fBsystemd-detect-virt\fR(1)
251 detects and reports, and uses the same vocabulary of confidential virtualization technology identifiers\&.
252 .sp
253 Added in version 254\&.
254 .RE
255 .SH "NOTES ABOUT WRITING GENERATORS"
256 .sp
257 .RS 4
258 .ie n \{\
259 \h'-04'\(bu\h'+03'\c
260 .\}
261 .el \{\
262 .sp -1
263 .IP \(bu 2.3
264 .\}
265 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\&.
266 .RE
267 .sp
268 .RS 4
269 .ie n \{\
270 \h'-04'\(bu\h'+03'\c
271 .\}
272 .el \{\
273 .sp -1
274 .IP \(bu 2.3
275 .\}
276 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
277 \fBsyslog\fR(3), or
278 \fBsystemd\fR
279 itself (this means: no
280 \fBsystemctl\fR(1))! Non\-essential file systems like
281 /var/
282 and
283 /home/
284 are mounted after generators have run\&. Generators can however rely on the most basic kernel functionality to be available, as well as mounted
285 /sys/,
286 /proc/,
287 /dev/,
288 /usr/
289 and
290 /run/
291 file systems\&.
292 .RE
293 .sp
294 .RS 4
295 .ie n \{\
296 \h'-04'\(bu\h'+03'\c
297 .\}
298 .el \{\
299 .sp -1
300 .IP \(bu 2.3
301 .\}
302 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
303 \fBsystemd\fR
304 itself\&.
305 .RE
306 .sp
307 .RS 4
308 .ie n \{\
309 \h'-04'\(bu\h'+03'\c
310 .\}
311 .el \{\
312 .sp -1
313 .IP \(bu 2.3
314 .\}
315 Generators should only be used to generate unit files,
316 \&.d/*\&.conf
317 drop\-ins for them and symlinks to them, not any other kind of non\-unit related 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\&.
318 .sp
319 Note that using the
320 \fIStandardInputData=\fR/\fIStandardInputText=\fR
321 settings of service unit files (see
322 \fBsystemd.exec\fR(5)), it is possible to make arbitrary input data (including daemon\-specific configuration) part of the unit definitions, which often might be sufficient to embed data or configuration for other programs into unit files in a native fashion\&.
323 .RE
324 .sp
325 .RS 4
326 .ie n \{\
327 \h'-04'\(bu\h'+03'\c
328 .\}
329 .el \{\
330 .sp -1
331 .IP \(bu 2.3
332 .\}
333 Since
334 \fBsyslog\fR(3)
335 is not available (see above), log messages have to be written to
336 /dev/kmsg
337 instead\&.
338 .RE
339 .sp
340 .RS 4
341 .ie n \{\
342 \h'-04'\(bu\h'+03'\c
343 .\}
344 .el \{\
345 .sp -1
346 .IP \(bu 2.3
347 .\}
348 The generator should always include its own name in a comment at the top of the generated file, so that the user can easily figure out which component created or amended a particular unit\&.
349 .sp
350 The
351 \fISourcePath=\fR
352 directive should be used in generated files to specify the source configuration file they are generated 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\&. The
353 \fISourcePath=\fR
354 value does not have to be a file in a physical filesystem\&. For example, in the common case of the generator looking at the kernel command line,
355 \fBSourcePath=/proc/cmdline\fR
356 should be used\&.
357 .RE
358 .sp
359 .RS 4
360 .ie n \{\
361 \h'-04'\(bu\h'+03'\c
362 .\}
363 .el \{\
364 .sp -1
365 .IP \(bu 2.3
366 .\}
367 Generators may write out dynamic unit files or just hook unit files into other units with the usual
368 \&.wants/
369 or
370 \&.requires/
371 symlinks\&. Often, it is nicer to simply instantiate a template unit file from
372 /usr/
373 with a generator instead of writing out entirely dynamic unit files\&. Of course, this works only if a single parameter is to be used\&.
374 .RE
375 .sp
376 .RS 4
377 .ie n \{\
378 \h'-04'\(bu\h'+03'\c
379 .\}
380 .el \{\
381 .sp -1
382 .IP \(bu 2.3
383 .\}
384 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 are slow\&.
385 .RE
386 .sp
387 .RS 4
388 .ie n \{\
389 \h'-04'\(bu\h'+03'\c
390 .\}
391 .el \{\
392 .sp -1
393 .IP \(bu 2.3
394 .\}
395 Regarding overriding semantics: there are two rules we try to follow when thinking about the overriding semantics:
396 .sp
397 .RS 4
398 .ie n \{\
399 \h'-04' 1.\h'+01'\c
400 .\}
401 .el \{\
402 .sp -1
403 .IP " 1." 4.2
404 .\}
405 User configuration should override vendor configuration\&. This (mostly) means that stuff from
406 /etc/
407 should override stuff from
408 /usr/\&.
409 .RE
410 .sp
411 .RS 4
412 .ie n \{\
413 \h'-04' 2.\h'+01'\c
414 .\}
415 .el \{\
416 .sp -1
417 .IP " 2." 4.2
418 .\}
419 Native configuration should override non\-native configuration\&. This (mostly) means that stuff you generate should never override native unit files for the same purpose\&.
420 .RE
421 .sp
422 Of these two rules the first rule is probably the more important one and breaks the second one sometimes\&. Hence, when deciding whether to use argv[1], argv[2], or argv[3], your default choice should probably be argv[1]\&.
423 .RE
424 .sp
425 .RS 4
426 .ie n \{\
427 \h'-04'\(bu\h'+03'\c
428 .\}
429 .el \{\
430 .sp -1
431 .IP \(bu 2.3
432 .\}
433 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\&.
434 .RE
435 .SH "EXAMPLES"
436 .PP
437 \fBExample\ \&1.\ \&systemd\-fstab\-generator\fR
438 .PP
439 \fBsystemd-fstab-generator\fR(8)
440 converts
441 /etc/fstab
442 into native mount units\&. It uses argv[1] as location to place the generated unit files in order to allow the user to override
443 /etc/fstab
444 with their own native unit files, but also to ensure that
445 /etc/fstab
446 overrides any vendor default from
447 /usr/\&.
448 .PP
449 After editing
450 /etc/fstab, the user should invoke
451 \fBsystemctl daemon\-reload\fR\&. This will re\-run all generators and cause
452 \fBsystemd\fR
453 to reload units from disk\&. To actually mount new directories added to
454 fstab,
455 \fBsystemctl start \fR\fB\fI/path/to/mountpoint\fR\fR
456 or
457 \fBsystemctl start local\-fs\&.target\fR
458 may be used\&.
459 .PP
460 \fBExample\ \&2.\ \&systemd\-system\-update\-generator\fR
461 .PP
462 \fBsystemd-system-update-generator\fR(8)
463 temporarily redirects
464 default\&.target
465 to
466 system\-update\&.target, if a system update is scheduled\&. Since this needs to override the default user configuration for
467 default\&.target, it uses argv[2]\&. For details about this logic, see
468 \fBsystemd.offline-updates\fR(7)\&.
469 .PP
470 \fBExample\ \&3.\ \&Debugging a generator\fR
471 .sp
472 .if n \{\
473 .RS 4
474 .\}
475 .nf
476 dir=$(mktemp \-d)
477 SYSTEMD_LOG_LEVEL=debug /usr/lib/systemd/system\-generators/systemd\-fstab\-generator \e
478 "$dir" "$dir" "$dir"
479 find $dir
480 .fi
481 .if n \{\
482 .RE
483 .\}
484 .SH "SEE ALSO"
485 .PP
486 \fBsystemd\fR(1), \fBsystemd-cryptsetup-generator\fR(8), \fBsystemd-debug-generator\fR(8), \fBsystemd-fstab-generator\fR(8), \fBfstab\fR(5), \fBsystemd-getty-generator\fR(8), \fBsystemd-gpt-auto-generator\fR(8), \fBsystemd-hibernate-resume-generator\fR(8), \fBsystemd-system-update-generator\fR(8), \fBsystemd-xdg-autostart-generator\fR(8), \fBsystemd.unit\fR(5), \fBsystemctl\fR(1), \fBsystemd.environment-generator\fR(7)
487 .SH "NOTES"
488 .IP " 1." 4
489 ๐Ÿ’ฃ๐Ÿ’ฅ๐Ÿงจ๐Ÿ’ฅ๐Ÿ’ฅ๐Ÿ’ฃ Please note that those configuration files must be available at all times. If
490 /usr/local/
491 is a separate partition, it may not be available during early boot, and must not be used for configuration.
492