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
15 systemd is free software; you can redistribute it and/or modify it
16 under the terms of the GNU Lesser General Public License as published by
17 the Free Software Foundation; either version 2.1 of the License, or
18 (at your option) any later version.
20 systemd is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 Lesser General Public License for more details.
25 You should have received a copy of the GNU Lesser General Public License
26 along with systemd; If not, see <http://www.gnu.org/licenses/>.
29 <refentry id=
"systemd.environment-generator" conditional='ENABLE_ENVIRONMENT_D'
30 xmlns:
xi=
"http://www.w3.org/2001/XInclude">
32 <title>systemd.environment-generator
</title>
33 <productname>systemd
</productname>
37 <contrib>Developer
</contrib>
38 <firstname>Zbigniew
</firstname>
39 <surname>Jędrzejewski-Szmek
</surname>
40 <email>zbyszek@in.waw.pl
</email>
46 <refentrytitle>systemd.environment-generator
</refentrytitle>
47 <manvolnum>7</manvolnum>
51 <refname>systemd.environment-generator
</refname>
52 <refpurpose>Systemd environment file generators
</refpurpose>
57 <command>&systemenvgeneratordir;/some-generator
</command>
60 <command>&userenvgeneratordir;/some-generator
</command>
64 <literallayout><filename>/run/systemd/system-environment-generators/*
</filename>
65 <filename>/etc/systemd/system-environment-generators/*
</filename>
66 <filename>/usr/local/lib/systemd/system-environment-generators/*
</filename>
67 <filename>&systemenvgeneratordir;/*
</filename></literallayout>
71 <literallayout><filename>/run/systemd/user-environment-generators/*
</filename>
72 <filename>/etc/systemd/user-environment-generators/*
</filename>
73 <filename>/usr/local/lib/systemd/user-environment-generators/*
</filename>
74 <filename>&userenvgeneratordir;/*
</filename></literallayout>
79 <title>Description
</title>
80 <para>Generators are small executables that live in
81 <filename>&systemenvgeneratordir;/
</filename> and other directories listed above.
82 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry> will
83 execute those binaries very early at the startup of each manager and at configuration
84 reload time, before running the generators described in
85 <citerefentry><refentrytitle>systemd.generator
</refentrytitle><manvolnum>7</manvolnum></citerefentry>
86 and before starting any units. Environment generators can override the environment that the
87 manager exports to services and other processes.
</para>
89 <para>Generators are loaded from a set of paths determined during compilation, as listed
90 above. System and user environment generators are loaded from directories with names ending in
91 <filename>system-environment-generators/
</filename> and
92 <filename>user-environment-generators/
</filename>, respectively. Generators found in directories
93 listed earlier override the ones with the same name in directories lower in the list. A symlink
94 to
<filename>/dev/null
</filename> or an empty file can be used to mask a generator, thereby
95 preventing it from running. Please note that the order of the two directories with the highest
96 priority is reversed with respect to the unit load path, and generators in
97 <filename>/run
</filename> overwrite those in
<filename>/etc
</filename>.
</para>
99 <para>After installing new generators or updating the configuration,
<command>systemctl
100 daemon-reload
</command> may be executed. This will re-run all generators, updating environment
101 configuration. It will be used for any services that are started subsequently.
</para>
103 <para>Environment file generators are executed similarly to unit file generators described
105 <citerefentry><refentrytitle>systemd.generator
</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
106 with the following differences:
</para>
110 <para>Generators are executed sequentially in the alphanumerical order of the final
111 component of their name. The output of each generator output is immediately parsed and used
112 to update the environment for generators that run after that. Thus, later generators can use
113 and/or modify the output of earlier generators.
</para>
117 <para>Generators are run by every manager instance, their output can be different for each
122 <para>It is recommended to use numerical prefixes for generator names to simplify ordering.
</para>
126 <title>Examples
</title>
129 <title>A simple generator that extends an environment variable if a directory exists in the file system
</title>
131 <programlisting>#
50-xdg-data-dirs.sh
133 <xi:include href=
"50-xdg-data-dirs.sh" parse=
"text" /></programlisting>
137 <title>A more complicated generator which reads existing configuration and mutates one variable
</title>
139 <programlisting>#
90-rearrange-path.py
141 <xi:include href=
"90-rearrange-path.py" parse=
"text" /></programlisting>
145 <title>Debugging a generator
</title>
147 <programlisting>SYSTEMD_LOG_LEVEL=debug VAR_A=something
VAR_B=
"something else" \
148 &systemenvgeneratordir;/path-to-generator
154 <title>See also
</title>
157 <citerefentry><refentrytitle>systemd-environment-d-generator
</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
158 <citerefentry><refentrytitle>systemd.generator
</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
159 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
160 <citerefentry><refentrytitle>systemctl
</refentrytitle><manvolnum>1</manvolnum></citerefentry>