<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Oct 27, 2015 at 12:35 PM, Soumya Koduri <span dir="ltr"><<a href="mailto:skoduri@redhat.com" target="_blank">skoduri@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
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.<br>
<br>
I first tried out below --<br>
<br>
EnvironmentFile=/etc/myconfig<br>
EnvironmentFile=${MY_ENV_FILE}<br>
...<br>
...<br>
ExecStart='/bin/echo ${MY_ENV_VAR}'<br>
<br>
<br>
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 -<br>
<br>
EnvironmentFile=/etc/myconfig<br>
....<br>
ExecStart=/bin/bash -c 'source ${MY_ENV_FILE} && echo ${MY_ENV_VAR}'<br>
<br>
<br>
This doesn't throw any warnings but the ${MY_ENV_VAR} is still not read from the ${MY_ENV_FILE}<br></blockquote><div><br></div><div>This would probably work if ${MY_ENV_VAR} was escaped (to let it be processed by bash, not systemd).</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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.<br></blockquote><div><br></div><div>There is no such option in systemd. If you need shellscript-like features, just run a wrapper shell script via ExecStart. </div></div><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">Mantas Mikulėnas <<a href="mailto:grawity@gmail.com" target="_blank">grawity@gmail.com</a>></div></div>
</div></div>