Systemd Environment and EnvironmentFile not working
Environment
and EnvironmentFile
set the variables, usable by the unit, but like the sh
command, does not export it to child processes. For that, you also need to list it in PassEnvironment
, just as you would with the export
shell command. See the systemd documentation on EnvironmentFile and PassEnvironment
Also, note that the contents of an EnvironmentFile is not a shell script, but key-value pairs that look rather too much like sh, so naming it with a .sh
extension is misleading.
I ran into the same trouble on RHEL 7.3 and found this:
You may then refer to variables set in the
/etc/sysconfig/httpd
file with${FOOBAR}
and$FOOBAR
, in theExecStart
lines (and related lines).
This makes me think that the purpose for Environment
and EnvironmentFile
is not at all what you and I expected (setting environment variables for the process started by the systemd unit), but only applies for the immediate expansion of the ExecStart
line.
Perhaps I'm completely off-base and this is a bug in systemd (I hope so). But I stopped going down the path you are trying and did it another way: In my case I needed to set LD_LIBRARY_PATH
, so I did that via creating /etc/ld.so.conf.d/new_file.conf
and then running ldconfig
. I also attempted to use system-wide variables in /etc/profile.d/new_file.sh
, but apparently setting just LD_LIBRARY_PATH
was enough for this service (mariadb) and so I don't actually know if the variables I was setting in /etc/profile.d/new_file.sh
were functioning.