[systemd-devel] systemd-nspawn --setenv=SOMETHING=other: What is that for?

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Sat Oct 24 15:40:41 PDT 2015


On Sat, Oct 24, 2015 at 11:05:50PM +0200, Tobias Hunger wrote:
> Hi Systemd List!
> 
> I have been trying today to pass some information into a container I
> set up with systemd-nspawn, using --setenv=SOMEVAR=foo. That works, I
> see SOMEVAR in /proc/1/environ of the container.
> 
> So far so good.
> 
> Now I want to use that information to configure a service, so I add a
> script that does the necessary configuration as a ExecStartPre-step to
> a service file. This script takes the environment variables and puts
> them into a configuration file for the service.
> 
> Unfortunately systemd does sanitize the environment before that script
> is started. That is actually a good thing that saved my hide before,
> but how can I make systemd export the necessary variable to that one
> unit that needs it this one time?
> 
> The documentation on Environment in the service unit states that there
> is no variable expansion going on. And just as documented
> 
> Environment=SOMEVAR
> 
> does not work. Neither does
> 
> Environment="SOMEVAR=$SOMEVAR"
> 
> At least there is no surprise there.
> 
> DefaultEnvironment in system.conf does export this variable to
> everybody. Do I need to do that?
> 
> The documentation on DefaultEnvironment also makes no mention of
> passing variables already set in PID1 on to other processes. It seems
> to be about adding new variables, just as Environment and
> EnvironmentFile in the service units.
> 
> Any idea how I can run trigger a script that see SOMEVAR as seen by PID1?
There is not built-in support for that.

You can always look at /proc/1/environ from privileged processes, or add
a generator script to create the units you need from that file.

Zbyszek


More information about the systemd-devel mailing list