[systemd-devel] Pass environment variables down to systemd-service in container
Lennart Poettering
lennart at poettering.net
Thu Jun 18 11:07:50 PDT 2015
On Tue, 16.06.15 17:49, Peter Paule (systemd-devel at fedux.org) wrote:
> Excerpts from Lennart Poettering's message of 2015-06-15 00:32:09 +0200:
> >
> > Nope, we deliberately clean up the env block we pass to services.
> >
>
> Mmmh, would it possible to add some kind of a whitelist for environment
> variables to the systemd- and/or service.unit-configuration for
> variables which are passed on to services? Maybe something like
> http://httpd.apache.org/docs/2.2/mod/mod_env.html#passenv.
>
> This would make things a lot of easier when containers are used with
> systemd as process supervisor. At least for Ruby on Rails or other
> software which makes use of environment variables for configuration.
>
> This way I can build a single image I can use in different environments
> just by setting environment files. Does that make sense to you?
>
> Outer Service Units
> # Service 1
> ExecStart="docker run -e RAILS_ENV=production -e DATABASE_URL="postgresql://localhost/app_production centos-rails"
>
> # Service 2
> ExecStart="docker run -e RAILS_ENV=staging -e DATABASE_URL="postgresql://localhost/app_staging centos-rails"
>
> Inner Service Units (Example)
> PassEnv="RAILS_ENV"
> ExecStart="RAILS_ENV=${RAILS_ENV} /srv/app/bin/rails"
I'd be willing to add a setting called PassEnvironment= that takes a
list of env vars to import from PID1's env block.
Happy to take a patch, also added to TODO list, so that we don't forget.
Lennart
--
Lennart Poettering, Red Hat
More information about the systemd-devel
mailing list