'\" t .TH "SYSTEMD\&.GENERATOR" "7" "" "systemd 230" "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/* /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 binaries that live in /usr/lib/systemd/user\-generators/ and other directories listed above\&. \fBsystemd\fR(1) will execute those binaries very early at bootup and at configuration reload time \(em 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 files\&. .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 "WRITING GENERATORS" .PP Generators are invoked with three arguments: paths to runtime directories where generators can place their generated unit files or symlinks\&. .sp .RS 4 .ie n \{\ \h'-04' 1.\h'+01'\c .\} .el \{\ .sp -1 .IP " 1." 4.2 .\} \fInormal\-dir\fR .sp argv[1] 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\&. .RE .sp .RS 4 .ie n \{\ \h'-04' 2.\h'+01'\c .\} .el \{\ .sp -1 .IP " 2." 4.2 .\} \fIearly\-dir\fR .sp argv[2] 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 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 argv[3] 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\&. .RE .SS "Notes" .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, including a mounted /sys, /proc, /dev, /usr\&. .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, 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\&. .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 .\} It is a good idea to use the \fISourcePath=\fR 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\&. .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 user 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 her 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 \m[blue]\fBImplementing Offline System Updates\fR\m[]\&\s-2\u[1]\d\s+2\&. .PP \fBExample\ \&3.\ \&Debugging a generator\fR .sp .if n \{\ .RS 4 .\} .nf dir=$(mktemp \-d) SYSTEMD_LOG_LEVEL=debug /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-system-update-generator\fR(8), \fBsystemd-sysv-generator\fR(8), \fBsystemd.unit\fR(5), \fBsystemctl\fR(1) .SH "NOTES" .IP " 1." 4 Implementing Offline System Updates .RS 4 \%http://www.freedesktop.org/wiki/Software/systemd/SystemUpdates .RE