[systemd-devel] How to source a variable file using systemd
Mantas Mikulėnas
grawity at gmail.com
Tue Oct 27 03:41:11 PDT 2015
On Tue, Oct 27, 2015 at 12:35 PM, 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.
>
> 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 <grawity at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20151027/79ac9b78/attachment.html>
More information about the systemd-devel
mailing list