![How to make an Environment Variable available to Systemd Services](https://linux22.com/image/1487219/How%20to%20make%20an%20Environment%20Variable%20available%20to%20Systemd%20Services.png)
I have a script in /etc/profile.d/setenv.sh
which sets the value for JAVA_HOME
so that $JAVA_HOME
will be available system-wide:
# echo "export JAVA_HOME=/usr/java/jdk1.8.0_74" > /etc/profile.d/setenv.sh
When I login to shell I can write echo $JAVA_HOME
and I see the path properly, but the service that is started with Systemd does not see that variable.
How can I have that environment variable visible to Systemd services?
答案1
From the man page for systemd-system.conf
This is refering to the file located at /etc/systemd/system.conf
on my box. It is probably where yours is too
You can put some options in there. The one you want would look something like
DefaultEnvironment="VAR1=word1 word2" VAR2=word3 "VAR3=word 5 6"
There is a commented out blank prototype in the system.conf
installed on my system. Change that to add your environment defintiton