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