[systemd-devel] How to source a variable file using systemd

Soumya Koduri skoduri at redhat.com
Tue Oct 27 03:35:18 PDT 2015


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}


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.


Thanks,
Soumya


More information about the systemd-devel mailing list