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