]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/systemd.environment-generator.xml
verify: use manager_load_startable_unit_or_warn() to load units for verification
[thirdparty/systemd.git] / man / systemd.environment-generator.xml
CommitLineData
1bd2d4e3
ZJS
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<!--
572eb058
ZJS
9 SPDX-License-Identifier: LGPL-2.1+
10
1bd2d4e3
ZJS
11 This file is part of systemd.
12
13 Copyright 2017 Zbigniew Jędrzejewski-Szmek
14
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.
19
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.
24
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/>.
27-->
28
232bd677 29<refentry id="systemd.environment-generator" conditional='ENABLE_ENVIRONMENT_D'
30 xmlns:xi="http://www.w3.org/2001/XInclude">
1bd2d4e3
ZJS
31 <refentryinfo>
32 <title>systemd.environment-generator</title>
33 <productname>systemd</productname>
34
35 <authorgroup>
36 <author>
37 <contrib>Developer</contrib>
38 <firstname>Zbigniew</firstname>
39 <surname>Jędrzejewski-Szmek</surname>
40 <email>zbyszek@in.waw.pl</email>
41 </author>
42 </authorgroup>
43 </refentryinfo>
44
45 <refmeta>
46 <refentrytitle>systemd.environment-generator</refentrytitle>
47 <manvolnum>7</manvolnum>
48 </refmeta>
49
50 <refnamediv>
51 <refname>systemd.environment-generator</refname>
f95b0be7 52 <refpurpose>systemd environment file generators</refpurpose>
1bd2d4e3
ZJS
53 </refnamediv>
54
55 <refsynopsisdiv>
56 <cmdsynopsis>
57 <command>&systemenvgeneratordir;/some-generator</command>
58 </cmdsynopsis>
59 <cmdsynopsis>
60 <command>&userenvgeneratordir;/some-generator</command>
61 </cmdsynopsis>
62
63 <para>
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>
68 </para>
69
70 <para>
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>
75 </para>
76 </refsynopsisdiv>
77
78 <refsect1>
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>
88
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>
98
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>
102
103 <para>Environment file generators are executed similarly to unit file generators described
104 in
105 <citerefentry><refentrytitle>systemd.generator</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
106 with the following differences:</para>
107
108 <itemizedlist>
109 <listitem>
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>
114 </listitem>
115
116 <listitem>
117 <para>Generators are run by every manager instance, their output can be different for each
118 user.</para>
119 </listitem>
120 </itemizedlist>
121
122 <para>It is recommended to use numerical prefixes for generator names to simplify ordering.</para>
123 </refsect1>
124
125 <refsect1>
126 <title>Examples</title>
127
128 <example>
129 <title>A simple generator that extends an environment variable if a directory exists in the file system</title>
130
131 <programlisting># 50-xdg-data-dirs.sh
132
133<xi:include href="50-xdg-data-dirs.sh" parse="text" /></programlisting>
134 </example>
135
136 <example>
137 <title>A more complicated generator which reads existing configuration and mutates one variable</title>
138
139 <programlisting># 90-rearrange-path.py
140
141<xi:include href="90-rearrange-path.py" parse="text" /></programlisting>
142 </example>
143
144 <example>
145 <title>Debugging a generator</title>
146
147 <programlisting>SYSTEMD_LOG_LEVEL=debug VAR_A=something VAR_B="something else" \
148&systemenvgeneratordir;/path-to-generator
149</programlisting>
150 </example>
151 </refsect1>
152
153 <refsect1>
154 <title>See also</title>
155
156 <para>
f63c4aab 157 <citerefentry><refentrytitle>systemd-environment-d-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
1bd2d4e3
ZJS
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>
161 </para>
162 </refsect1>
163</refentry>