summaryrefslogtreecommitdiffstats
path: root/upstream/fedora-rawhide/man7/systemd.generator.7
blob: 3e7f3aaabd550421fd0280e1afe7732157426777 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
'\" t
.TH "SYSTEMD\&.GENERATOR" "7" "" "systemd 255" "systemd.generator"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
systemd.generator \- systemd unit generators
.SH "SYNOPSIS"
.HP \w'\fB/path/to/generator\fR\ 'u
\fB/path/to/generator\fR \fInormal\-dir\fR [\fIearly\-dir\fR] [\fIlate\-dir\fR]
.PP
.nf
/run/systemd/system\-generators/*
/etc/systemd/system\-generators/*
/usr/local/lib/systemd/system\-generators/*
/usr/lib/systemd/system\-generators/*
.fi
.PP
.nf
/run/systemd/user\-generators/*
/etc/systemd/user\-generators/*
/usr/local/lib/systemd/user\-generators/*
/usr/lib/systemd/user\-generators/*
.fi
.sp
.SH "DESCRIPTION"
.PP
Generators are small executables placed in
/usr/lib/systemd/system\-generators/
and other directories listed above\&.
\fBsystemd\fR(1)
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\&.
.PP
\fBsystemd\fR
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
\&.d/
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\&.
.PP
Directory paths for generator output differ by priority:
\&.../generator\&.early
has priority higher than the admin configuration in
/etc/, while
\&.../generator
has lower priority than
/etc/
but higher than vendor configuration in
/usr/, and
\&.../generator\&.late
has priority lower than all other configuration\&. See the next section and the discussion of unit load paths and unit overriding in
\fBsystemd.unit\fR(5)\&.
.PP
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/\&.
.PP
After installing new generators or updating the configuration,
\fBsystemctl daemon\-reload\fR
may be executed\&. This will delete the previous configuration created by generators, re\-run all generators, and cause
\fBsystemd\fR
to reload units from disk\&. See
\fBsystemctl\fR(1)
for more information\&.
.SH "OUTPUT DIRECTORIES"
.PP
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
\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\&.
.sp
.RS 4
.ie n \{\
\h'-04' 1.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  1." 4.2
.\}
\fInormal\-dir\fR
.sp
In normal use this is
/run/systemd/generator
in case of the system generators and
$XDG_RUNTIME_DIR/systemd/generator
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\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 2.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  2." 4.2
.\}
\fIearly\-dir\fR
.sp
In normal use this is
/run/systemd/generator\&.early
in case of the system generators and
$XDG_RUNTIME_DIR/systemd/generator\&.early
in case of the user generators\&. Unit files placed in this directory override unit files in
/usr/,
/run/
and
/etc/\&. This means that unit files placed in this directory take precedence over all normal configuration, both vendor and user/administrator\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 3.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  3." 4.2
.\}
\fIlate\-dir\fR
.sp
In normal use this is
/run/systemd/generator\&.late
in case of the system generators and
$XDG_RUNTIME_DIR/systemd/generator\&.late
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\&.
.RE
.PP
Note: generators
\fImust not\fR
write to other locations or otherwise make changes to system state\&. Generator output is supposed to last only until the next
\fBdaemon\-reload\fR
or
\fBdaemon\-reexec\fR; if the generator is replaced or masked, its effects should vanish\&.
.SH "ENVIRONMENT"
.PP
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:
.PP
\fI$SYSTEMD_SCOPE\fR
.RS 4
If the generator is invoked from the system service manager this variable is set to
"system"; if invoked from the per\-user service manager it is set to
"user"\&.
.sp
Added in version 251\&.
.RE
.PP
\fI$SYSTEMD_IN_INITRD\fR
.RS 4
If the generator is run as part of an initrd this is set to
"1"\&. If it is run from the regular host (i\&.e\&. after the transition from initrd to host) it is set to
"0"\&. This environment variable is only set for system generators\&.
.sp
Added in version 251\&.
.RE
.PP
\fI$SYSTEMD_FIRST_BOOT\fR
.RS 4
If this boot\-up cycle is considered a "first boot", this is set to
"1"; if it is a subsequent, regular boot it is set to
"0"\&. For details see the documentation of
\fIConditionFirstBoot=\fR
in
\fBsystemd.unit\fR(5)\&. This environment variable is only set for system generators\&.
.sp
Added in version 251\&.
.RE
.PP
\fI$SYSTEMD_VIRTUALIZATION\fR
.RS 4
If the service manager is run in a virtualized environment,
\fI$SYSTEMD_VIRTUALIZATION\fR
is set to a pair of strings, separated by a colon\&. The first string is either
"vm"
or
"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
\fBsystemd-detect-virt\fR(1)
detects and reports, and uses the same vocabulary of virtualization implementation identifiers\&.
.sp
Added in version 251\&.
.RE
.PP
\fI$SYSTEMD_ARCHITECTURE\fR
.RS 4
This variable is set to a short identifier of the reported architecture of the system\&. For details about defined values, see documentation of
\fIConditionArchitecture=\fR
in
\fBsystemd.unit\fR(5)\&.
.sp
Added in version 251\&.
.RE
.PP
\fI$CREDENTIALS_DIRECTORY\fR, \fI$ENCRYPTED_CREDENTIALS_DIRECTORY\fR
.RS 4
If set, refers to the directory system credentials have been placed in\&. Credentials passed into the system in plaintext form will be placed in
\fI$CREDENTIALS_DIRECTORY\fR, and those passed in in encrypted form will be placed in
\fI$ENCRYPTED_CREDENTIALS_DIRECTORY\fR\&. Use the
\fBsystemd-creds\fR(1)
command to automatically decrypt/authenticate credentials passed in, if needed\&. Specifically, use the
\fBsystemd\-creds \-\-system cat\fR
command\&.
.sp
Added in version 254\&.
.RE
.PP
\fI$SYSTEMD_CONFIDENTIAL_VIRTUALIZATION\fR
.RS 4
If the service manager is run in a confidential virtualized environment,
\fI$SYSTEMD_CONFIDENTIAL_VIRTUALIZATION\fR
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
\fBsystemd-detect-virt\fR(1)
detects and reports, and uses the same vocabulary of confidential virtualization technology identifiers\&.
.sp
Added in version 254\&.
.RE
.SH "NOTES ABOUT WRITING GENERATORS"
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
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\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
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
\fBsyslog\fR(3), or
\fBsystemd\fR
itself (this means: no
\fBsystemctl\fR(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, as well as mounted
/sys/,
/proc/,
/dev/,
/usr/
and
/run/
file systems\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
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
\fBsystemd\fR
itself\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
Generators should only be used to generate unit files,
\&.d/*\&.conf
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\&.
.sp
Note that using the
\fIStandardInputData=\fR/\fIStandardInputText=\fR
settings of service unit files (see
\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\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
Since
\fBsyslog\fR(3)
is not available (see above), log messages have to be written to
/dev/kmsg
instead\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
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\&.
.sp
The
\fISourcePath=\fR
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
\fISourcePath=\fR
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,
\fBSourcePath=/proc/cmdline\fR
should be used\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
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\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
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\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
Regarding overriding semantics: there are two rules we try to follow when thinking about the overriding semantics:
.sp
.RS 4
.ie n \{\
\h'-04' 1.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  1." 4.2
.\}
User configuration should override vendor configuration\&. This (mostly) means that stuff from
/etc/
should override stuff from
/usr/\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 2.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  2." 4.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\&.
.RE
.sp
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]\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
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\&.
.RE
.SH "EXAMPLES"
.PP
\fBExample\ \&1.\ \&systemd\-fstab\-generator\fR
.PP
\fBsystemd-fstab-generator\fR(8)
converts
/etc/fstab
into native mount units\&. It uses argv[1] as location to place the generated unit files in order to allow the user to override
/etc/fstab
with their own native unit files, but also to ensure that
/etc/fstab
overrides any vendor default from
/usr/\&.
.PP
After editing
/etc/fstab, the user should invoke
\fBsystemctl daemon\-reload\fR\&. This will re\-run all generators and cause
\fBsystemd\fR
to reload units from disk\&. To actually mount new directories added to
fstab,
\fBsystemctl start \fR\fB\fI/path/to/mountpoint\fR\fR
or
\fBsystemctl start local\-fs\&.target\fR
may be used\&.
.PP
\fBExample\ \&2.\ \&systemd\-system\-update\-generator\fR
.PP
\fBsystemd-system-update-generator\fR(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[2]\&. For details about this logic, see
\fBsystemd.offline-updates\fR(7)\&.
.PP
\fBExample\ \&3.\ \&Debugging a generator\fR
.sp
.if n \{\
.RS 4
.\}
.nf
dir=$(mktemp \-d)
SYSTEMD_LOG_LEVEL=debug /usr/lib/systemd/system\-generators/systemd\-fstab\-generator \e
        "$dir" "$dir" "$dir"
find $dir
.fi
.if n \{\
.RE
.\}
.SH "SEE ALSO"
.PP
\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-rc-local-generator\fR(8),
\fBsystemd-system-update-generator\fR(8),
\fBsystemd-sysv-generator\fR(8),
\fBsystemd-xdg-autostart-generator\fR(8),
\fBsystemd.unit\fR(5),
\fBsystemctl\fR(1),
\fBsystemd.environment-generator\fR(7)