]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/systemd.environment-generator.xml
Merge pull request #9301 from keszybz/man-drop-authorgroup
[thirdparty/systemd.git] / man / systemd.environment-generator.xml
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" >
5 %entities;
6 ]>
7
8 <!--
9 SPDX-License-Identifier: LGPL-2.1+
10 -->
11
12 <refentry id="systemd.environment-generator" conditional='ENABLE_ENVIRONMENT_D'
13 xmlns:xi="http://www.w3.org/2001/XInclude">
14 <refentryinfo>
15 <title>systemd.environment-generator</title>
16 <productname>systemd</productname>
17 </refentryinfo>
18
19 <refmeta>
20 <refentrytitle>systemd.environment-generator</refentrytitle>
21 <manvolnum>7</manvolnum>
22 </refmeta>
23
24 <refnamediv>
25 <refname>systemd.environment-generator</refname>
26 <refpurpose>systemd environment file generators</refpurpose>
27 </refnamediv>
28
29 <refsynopsisdiv>
30 <cmdsynopsis>
31 <command>&systemenvgeneratordir;/some-generator</command>
32 </cmdsynopsis>
33 <cmdsynopsis>
34 <command>&userenvgeneratordir;/some-generator</command>
35 </cmdsynopsis>
36
37 <para>
38 <literallayout><filename>/run/systemd/system-environment-generators/*</filename>
39 <filename>/etc/systemd/system-environment-generators/*</filename>
40 <filename>/usr/local/lib/systemd/system-environment-generators/*</filename>
41 <filename>&systemenvgeneratordir;/*</filename></literallayout>
42 </para>
43
44 <para>
45 <literallayout><filename>/run/systemd/user-environment-generators/*</filename>
46 <filename>/etc/systemd/user-environment-generators/*</filename>
47 <filename>/usr/local/lib/systemd/user-environment-generators/*</filename>
48 <filename>&userenvgeneratordir;/*</filename></literallayout>
49 </para>
50 </refsynopsisdiv>
51
52 <refsect1>
53 <title>Description</title>
54 <para>Generators are small executables that live in
55 <filename>&systemenvgeneratordir;/</filename> and other directories listed above.
56 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry> will
57 execute those binaries very early at the startup of each manager and at configuration
58 reload time, before running the generators described in
59 <citerefentry><refentrytitle>systemd.generator</refentrytitle><manvolnum>7</manvolnum></citerefentry>
60 and before starting any units. Environment generators can override the environment that the
61 manager exports to services and other processes.</para>
62
63 <para>Generators are loaded from a set of paths determined during compilation, as listed
64 above. System and user environment generators are loaded from directories with names ending in
65 <filename>system-environment-generators/</filename> and
66 <filename>user-environment-generators/</filename>, respectively. Generators found in directories
67 listed earlier override the ones with the same name in directories lower in the list. A symlink
68 to <filename>/dev/null</filename> or an empty file can be used to mask a generator, thereby
69 preventing it from running. Please note that the order of the two directories with the highest
70 priority is reversed with respect to the unit load path, and generators in
71 <filename>/run</filename> overwrite those in <filename>/etc</filename>.</para>
72
73 <para>After installing new generators or updating the configuration, <command>systemctl
74 daemon-reload</command> may be executed. This will re-run all generators, updating environment
75 configuration. It will be used for any services that are started subsequently.</para>
76
77 <para>Environment file generators are executed similarly to unit file generators described
78 in
79 <citerefentry><refentrytitle>systemd.generator</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
80 with the following differences:</para>
81
82 <itemizedlist>
83 <listitem>
84 <para>Generators are executed sequentially in the alphanumerical order of the final
85 component of their name. The output of each generator output is immediately parsed and used
86 to update the environment for generators that run after that. Thus, later generators can use
87 and/or modify the output of earlier generators.</para>
88 </listitem>
89
90 <listitem>
91 <para>Generators are run by every manager instance, their output can be different for each
92 user.</para>
93 </listitem>
94 </itemizedlist>
95
96 <para>It is recommended to use numerical prefixes for generator names to simplify ordering.</para>
97 </refsect1>
98
99 <refsect1>
100 <title>Examples</title>
101
102 <example>
103 <title>A simple generator that extends an environment variable if a directory exists in the file system</title>
104
105 <programlisting># 50-xdg-data-dirs.sh
106
107 <xi:include href="50-xdg-data-dirs.sh" parse="text" /></programlisting>
108 </example>
109
110 <example>
111 <title>A more complicated generator which reads existing configuration and mutates one variable</title>
112
113 <programlisting># 90-rearrange-path.py
114
115 <xi:include href="90-rearrange-path.py" parse="text" /></programlisting>
116 </example>
117
118 <example>
119 <title>Debugging a generator</title>
120
121 <programlisting>SYSTEMD_LOG_LEVEL=debug VAR_A=something VAR_B="something else" \
122 &systemenvgeneratordir;/path-to-generator
123 </programlisting>
124 </example>
125 </refsect1>
126
127 <refsect1>
128 <title>See also</title>
129
130 <para>
131 <citerefentry><refentrytitle>systemd-environment-d-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
132 <citerefentry><refentrytitle>systemd.generator</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
133 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
134 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
135 </para>
136 </refsect1>
137 </refentry>