Systemd Environment and EnvironmentFile not working

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 the ExecStart 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.

Leave a Comment