Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting environment variables for no-login users

I have an RHEL server with tomcat installed. Tomcat runs as a no-login user called tomcat . I have set the required environment variables in /etc/profile.d/myenvvars.sh as

export JRE_HOME=/usr/lib/jvm/jre
export MY_VAR=/usr/share/mydir

The environment variables are set and can be echoed in the terminal using

# echo $MY_VAR
# sudo -u tomcat echo $MY_VAR

However when tomcat starts my environment variable is not recognised by tomcat.

As per this article I found that my environment variables will not be recognised when tomcat starts as tomcat is a no-login user. Therefore I sourced the above file in ~/.bash_profile using

. /etc/profile.d/myenvvars.sh

However, I still have the same issue, the environment variable is not reccognised.

Any help would be appreciated.

like image 644
hoz Avatar asked Apr 08 '16 15:04

hoz


1 Answers

As stated in the article your linked your settings need to be in ~/.bashrc.

There may be a chance that even this is not working... depending on how your tomcat is started.

You could have a custom script for tomcat to make sure it loads the environment variables e.g. something like this

tomcat-start.sh

. /etc/profile.d/myenvvars.sh
tomcat
like image 125
daKmoR Avatar answered Sep 27 '22 20:09

daKmoR