|
423 | 423 | <varlistentry> |
424 | 424 | <term><varname>PassEnvironment=</varname></term> |
425 | 425 |
|
426 | | - <listitem><para>Pass environment variables from the systemd system |
427 | | - manager to executed processes. Takes a space-separated list of variable |
428 | | - names. This option may be specified more than once, in which case all |
429 | | - listed variables will be set. If the empty string is assigned to this |
430 | | - option, the list of environment variables is reset, all prior |
431 | | - assignments have no effect. Variables that are not set in the system |
432 | | - manager will not be passed and will be silently ignored.</para> |
433 | | - |
434 | | - <para>Variables passed from this setting are overridden by those passed |
435 | | - from <varname>Environment=</varname> or |
436 | | - <varname>EnvironmentFile=</varname>.</para> |
| 426 | + <listitem><para>Pass environment variables set for the system service manager to executed processes. Takes a |
| 427 | + space-separated list of variable names. This option may be specified more than once, in which case all listed |
| 428 | + variables will be passed. If the empty string is assigned to this option, the list of environment variables to |
| 429 | + pass is reset, all prior assignments have no effect. Variables specified that are not set for the system |
| 430 | + manager will not be passed and will be silently ignored. Note that this option is only relevant for the system |
| 431 | + service manager, as system services by default do not automatically inherit any environment variables set for |
| 432 | + the service manager itself. However, in case of the user service manager all environment variables are passed |
| 433 | + to the executed processes anyway, hence this option is without effect for the user service manager.</para> |
| 434 | + |
| 435 | + <para>Variables set for invoked processes due to this setting are subject to being overridden by those |
| 436 | + configured with <varname>Environment=</varname> or <varname>EnvironmentFile=</varname>.</para> |
437 | 437 |
|
438 | 438 | <para>Example: |
439 | 439 | <programlisting>PassEnvironment=VAR1 VAR2 VAR3</programlisting> |
|
447 | 447 | for details about environment variables.</para></listitem> |
448 | 448 | </varlistentry> |
449 | 449 |
|
| 450 | + <varlistentry> |
| 451 | + <term><varname>UnsetEnvironment=</varname></term> |
| 452 | + |
| 453 | + <listitem><para>Explicitly unset environment variable assignments that would normally be passed from the |
| 454 | + service manager to invoked processes of this unit. Takes a space-separated list of variable names or variable |
| 455 | + assignments. This option may be specified more than once, in which case all listed variables/assignments will |
| 456 | + be unset. If the empty string is assigned to this option, the list of environment variables/assignments to |
| 457 | + unset is reset. If a variable assignment is specified (that is: a variable name, followed by |
| 458 | + <literal>=</literal>, followed by its value), then any environment variable matching this precise assignment is |
| 459 | + removed. If a variable name is specified (that is a variable name without any following <literal>=</literal> or |
| 460 | + value), then any assignment matching the variable name, regardless of its value is removed. Note that the |
| 461 | + effect of <varname>UnsetEnvironment=</varname> is applied as final step when the environment list passed to |
| 462 | + executed processes is compiled. That means it may undo assignments from any configuration source, including |
| 463 | + assignments made through <varname>Environment=</varname> or <varname>EnvironmentFile=</varname>, inherited from |
| 464 | + the system manager's global set of environment variables, inherited via <varname>PassEnvironment=</varname>, |
| 465 | + set by the service manager itself (such as <varname>$NOTIFY_SOCKET</varname> and such), or set by a PAM module |
| 466 | + (in case <varname>PAMName=</varname> is used).</para> |
| 467 | + |
| 468 | + <para> |
| 469 | + See |
| 470 | + <citerefentry project='man-pages'><refentrytitle>environ</refentrytitle><manvolnum>7</manvolnum></citerefentry> |
| 471 | + for details about environment variables.</para></listitem> |
| 472 | + </varlistentry> |
| 473 | + |
450 | 474 | <varlistentry> |
451 | 475 | <term><varname>StandardInput=</varname></term> |
452 | 476 | <listitem><para>Controls where file descriptor 0 (STDIN) of |
@@ -1799,12 +1823,38 @@ CapabilityBoundingSet=~CAP_B CAP_C</programlisting> |
1799 | 1823 | <refsect1> |
1800 | 1824 | <title>Environment variables in spawned processes</title> |
1801 | 1825 |
|
1802 | | - <para>Processes started by the system are executed in a clean |
1803 | | - environment in which select variables listed below are set. System |
1804 | | - processes started by systemd do not inherit variables from PID 1, |
1805 | | - but processes started by user systemd instances inherit all |
1806 | | - environment variables from the user systemd instance. |
1807 | | - </para> |
| 1826 | + <para>Processes started by the service manager are executed with an environment variable block assembled from |
| 1827 | + multiple sources. Processes started by the system service manager generally do not inherit environment variables |
| 1828 | + set for the service manager itself (but this may be altered via <varname>PassEnvironment=</varname>), but processes |
| 1829 | + started by the user service manager instances generally do inherit all environment variables set for the service |
| 1830 | + manager itself.</para> |
| 1831 | + |
| 1832 | + <para>For each invoked process the list of environment variables set is compiled from the following sources:</para> |
| 1833 | + |
| 1834 | + <itemizedlist> |
| 1835 | + <listitem><para>Variables globally configured for the service manager, using the |
| 1836 | + <varname>DefaultEnvironment=</varname> setting in |
| 1837 | + <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>, the kernel command line option <varname>systemd.setenv=</varname> (see |
| 1838 | + <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>) or via |
| 1839 | + <command>systemctl set-environment</command> (see <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>).</para></listitem> |
| 1840 | + |
| 1841 | + <listitem><para>Variables defined by the service manager itself (see the list below)</para></listitem> |
| 1842 | + |
| 1843 | + <listitem><para>Variables set in the service manager's own environment variable block (subject to <varname>PassEnvironment=</varname> for the system service manager)</para></listitem> |
| 1844 | + |
| 1845 | + <listitem><para>Variables set via <varname>Environment=</varname> in the unit file</para></listitem> |
| 1846 | + |
| 1847 | + <listitem><para>Variables read from files specified via <varname>EnvironmentFiles=</varname> in the unit file</para></listitem> |
| 1848 | + |
| 1849 | + <listitem><para>Variables set by any PAM modules in case <varname>PAMName=</varname> is in effect, cf. <citerefentry project='man-pages'><refentrytitle>pam_env</refentrytitle><manvolnum>8</manvolnum></citerefentry></para></listitem> |
| 1850 | + </itemizedlist> |
| 1851 | + |
| 1852 | + <para>If the same environment variables are set by multiple of these sources, the later source — according to the |
| 1853 | + order of the list above — wins. Note that as final step all variables listed in |
| 1854 | + <varname>UnsetEnvironment=</varname> are removed again from the compiled environment variable list, immediately |
| 1855 | + before it is passed to the executed process.</para> |
| 1856 | + |
| 1857 | + <para>The following select environment variables are set by the service manager itself for each invoked process:</para> |
1808 | 1858 |
|
1809 | 1859 | <variablelist class='environment-variables'> |
1810 | 1860 | <varlistentry> |
@@ -2120,18 +2170,6 @@ CapabilityBoundingSet=~CAP_B CAP_C</programlisting> |
2120 | 2170 | </listitem> |
2121 | 2171 | </varlistentry> |
2122 | 2172 | </variablelist> |
2123 | | - |
2124 | | - <para>Additional variables may be configured by the following |
2125 | | - means: for processes spawned in specific units, use the |
2126 | | - <varname>Environment=</varname>, <varname>EnvironmentFile=</varname> |
2127 | | - and <varname>PassEnvironment=</varname> options above; to specify |
2128 | | - variables globally, use <varname>DefaultEnvironment=</varname> |
2129 | | - (see |
2130 | | - <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>) |
2131 | | - or the kernel option <varname>systemd.setenv=</varname> (see |
2132 | | - <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>). |
2133 | | - Additional variables may also be set through PAM, |
2134 | | - cf. <citerefentry project='man-pages'><refentrytitle>pam_env</refentrytitle><manvolnum>8</manvolnum></citerefentry>.</para> |
2135 | 2173 | </refsect1> |
2136 | 2174 |
|
2137 | 2175 | <refsect1> |
|
0 commit comments