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