1 <?xml version='
1.0'
?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC
"-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
4 <!ENTITY % entities SYSTEM
"custom-entities.ent" >
9 SPDX-License-Identifier: LGPL-2.1+
11 This file is part of systemd.
13 Copyright 2017 Zbigniew Jędrzejewski-Szmek
16 <refentry id=
"systemd.environment-generator" conditional='ENABLE_ENVIRONMENT_D'
17 xmlns:
xi=
"http://www.w3.org/2001/XInclude">
19 <title>systemd.environment-generator
</title>
20 <productname>systemd
</productname>
24 <contrib>Developer
</contrib>
25 <firstname>Zbigniew
</firstname>
26 <surname>Jędrzejewski-Szmek
</surname>
27 <email>zbyszek@in.waw.pl
</email>
33 <refentrytitle>systemd.environment-generator
</refentrytitle>
34 <manvolnum>7</manvolnum>
38 <refname>systemd.environment-generator
</refname>
39 <refpurpose>systemd environment file generators
</refpurpose>
44 <command>&systemenvgeneratordir;/some-generator
</command>
47 <command>&userenvgeneratordir;/some-generator
</command>
51 <literallayout><filename>/run/systemd/system-environment-generators/*
</filename>
52 <filename>/etc/systemd/system-environment-generators/*
</filename>
53 <filename>/usr/local/lib/systemd/system-environment-generators/*
</filename>
54 <filename>&systemenvgeneratordir;/*
</filename></literallayout>
58 <literallayout><filename>/run/systemd/user-environment-generators/*
</filename>
59 <filename>/etc/systemd/user-environment-generators/*
</filename>
60 <filename>/usr/local/lib/systemd/user-environment-generators/*
</filename>
61 <filename>&userenvgeneratordir;/*
</filename></literallayout>
66 <title>Description
</title>
67 <para>Generators are small executables that live in
68 <filename>&systemenvgeneratordir;/
</filename> and other directories listed above.
69 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry> will
70 execute those binaries very early at the startup of each manager and at configuration
71 reload time, before running the generators described in
72 <citerefentry><refentrytitle>systemd.generator
</refentrytitle><manvolnum>7</manvolnum></citerefentry>
73 and before starting any units. Environment generators can override the environment that the
74 manager exports to services and other processes.
</para>
76 <para>Generators are loaded from a set of paths determined during compilation, as listed
77 above. System and user environment generators are loaded from directories with names ending in
78 <filename>system-environment-generators/
</filename> and
79 <filename>user-environment-generators/
</filename>, respectively. Generators found in directories
80 listed earlier override the ones with the same name in directories lower in the list. A symlink
81 to
<filename>/dev/null
</filename> or an empty file can be used to mask a generator, thereby
82 preventing it from running. Please note that the order of the two directories with the highest
83 priority is reversed with respect to the unit load path, and generators in
84 <filename>/run
</filename> overwrite those in
<filename>/etc
</filename>.
</para>
86 <para>After installing new generators or updating the configuration,
<command>systemctl
87 daemon-reload
</command> may be executed. This will re-run all generators, updating environment
88 configuration. It will be used for any services that are started subsequently.
</para>
90 <para>Environment file generators are executed similarly to unit file generators described
92 <citerefentry><refentrytitle>systemd.generator
</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
93 with the following differences:
</para>
97 <para>Generators are executed sequentially in the alphanumerical order of the final
98 component of their name. The output of each generator output is immediately parsed and used
99 to update the environment for generators that run after that. Thus, later generators can use
100 and/or modify the output of earlier generators.
</para>
104 <para>Generators are run by every manager instance, their output can be different for each
109 <para>It is recommended to use numerical prefixes for generator names to simplify ordering.
</para>
113 <title>Examples
</title>
116 <title>A simple generator that extends an environment variable if a directory exists in the file system
</title>
118 <programlisting>#
50-xdg-data-dirs.sh
120 <xi:include href=
"50-xdg-data-dirs.sh" parse=
"text" /></programlisting>
124 <title>A more complicated generator which reads existing configuration and mutates one variable
</title>
126 <programlisting>#
90-rearrange-path.py
128 <xi:include href=
"90-rearrange-path.py" parse=
"text" /></programlisting>
132 <title>Debugging a generator
</title>
134 <programlisting>SYSTEMD_LOG_LEVEL=debug VAR_A=something
VAR_B=
"something else" \
135 &systemenvgeneratordir;/path-to-generator
141 <title>See also
</title>
144 <citerefentry><refentrytitle>systemd-environment-d-generator
</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
145 <citerefentry><refentrytitle>systemd.generator
</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
146 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
147 <citerefentry><refentrytitle>systemctl
</refentrytitle><manvolnum>1</manvolnum></citerefentry>