Debian Codegraph @

man/systemd.environment-generator.xml

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