I have an Ubuntu 18.04 vm which executes a script via /etc/profile.d
. The script reaches out to an external data source (azure, in this case), pulls down some json, and converts it into environment variables. I was hoping these environment variables would be globally available to users, daemons, systemd, etc. but I'm realizing it's only for login shells. I'm reading that /etc/environment
exists, but is static rather than a script file.
- Running this script in profile.d seems fragile..if the data source is transiently unavailable, that could impact the ability of my VM from booting.
- I had considered having a script append the values to
/etc/environment
, but that feels sketchy and I'm not certain that the env vars will be in scope when systemd runs.
- I was able to configure the particular systemd unit to behave like a login shell using the
-l
flag and that worked...but it is not the only unit or location where this will be required so that doesn't seem maintainable. Also, the external data calls are rate limited to something low...it really should only happen once.
- Similar to 3, I could directly reference the script to set environment variables everywhere I need it, but that has the same pitfalls and is not maintainable.
I'm now just spinning my wheels and am somewhat of a Linux newbie. What is the correct way to dynamically set global variables on startup?