[systemd-devel] How to source a variable file using systemd
Lennart Poettering
lennart at poettering.net
Tue Oct 27 05:19:07 PDT 2015
On Tue, 27.10.15 16:05, Soumya Koduri (skoduri at redhat.com) wrote:
> Hi,
>
> We have a use-case where in we have to read an environment variable (say
> ${MY_ENV_FILE}) from a file (say /etc/myconfig) and source ${MY_ENV_FILE} to
> read yet another environment variable (say ${MY_ENV_VAR} in our systemd
> service file.
Please use a shell script if you actually want the power of a
shell. Unit files are explicitly designed to be a simple, non-turing
complete language, with only minimal templating, and we have no
intention to change that.
If you want a scripting language, then please go for one, there's
nothing wrong with invoking a shell script from ExecStart= that then
does an "exec" for the real binary as last step.
Of course, I think well written software doesn't require doing this,
and supports good configuration files on its own, but if you have
software that isn't that way, then by all means go ahead and write a
shell script around it.
>
> I first tried out below --
>
> EnvironmentFile=/etc/myconfig
> EnvironmentFile=${MY_ENV_FILE}
> ...
> ...
> ExecStart='/bin/echo ${MY_ENV_VAR}'
env vars are *only* expanded in ExecXYZ= lines. This is because they
are determined at execution time from everything passed in from the
manager, runtime env vars, env vars from the unit file and env vars
from EnvironmentFile=.
Lennart
--
Lennart Poettering, Red Hat
More information about the systemd-devel
mailing list