I am currently working on a deployment tool that will be configuring environment variables across CentOS7 machines. As it stands, my tool is aware of what variables need to be configured, but is not aware of what services will be using them as those services might not even be installed yet.
So the challenges are:
-
At the point my tool is running, I am unaware of what services are needing what environment variables (and therefore we don't know what
.service
file to put them into) -
Services run as non-interactive non-login as far as I can tell, so the other options of getting a sort of 'global' environment variable don't seem like a solution to this (i.e. profile.d and that sort of thing)
Is there another way to persist these variables without needing to know what service will be referencing them?
Best Answer
In
/etc/systemd/system.conf
, you can useDefaultEnvironment=
to set environment variables passed to all services.You can read about the details in
man systemd-system.conf
.