On Tue, Oct 27, 2015 at 12:35 PM, Soumya Koduri <skod...@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.
>
> I first tried out below --
>
> EnvironmentFile=/etc/myconfig
> EnvironmentFile=${MY_ENV_FILE}
> ...
> ...
> ExecStart='/bin/echo ${MY_ENV_VAR}'
>
>
> But this gave an error saying that EnvironmentFile can take only absolute
> paths. So instead I tried to find a work around and get the behavior using
> the bash script as below -
>
> EnvironmentFile=/etc/myconfig
> ....
> ExecStart=/bin/bash -c 'source ${MY_ENV_FILE} && echo ${MY_ENV_VAR}'
>
>
> This doesn't throw any warnings but the ${MY_ENV_VAR} is still not read
> from the ${MY_ENV_FILE}
>

This would probably work if ${MY_ENV_VAR} was escaped (to let it be
processed by bash, not systemd).


> Kindly let me know what is the best way to read Environment variables from
> a file whose path is not fixed but yet another variable.
>

There is no such option in systemd. If you need shellscript-like features,
just run a wrapper shell script via ExecStart.


-- 
Mantas Mikulėnas <graw...@gmail.com>
_______________________________________________
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to