为无登录用户设置环境变量

时间:2022-03-10 11:15:21

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

我有一个安装了tomcat的RHEL服务器。 Tomcat作为一个名为tomcat的无登录用户运行。我在/etc/profile.d/myenvvars.sh中设置了所需的环境变量

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.

但是当tomcat启动时,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

根据这篇文章,我发现当tomcat启动时我的环境变量将无法被识别,因为tomcat是一个非登录用户。因此我在〜/ .bash_profile中使用了上面的文件

. /etc/profile.d/myenvvars.sh

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

但是,我仍然有同样的问题,环境变量没有被重新认识。

Any help would be appreciated.

任何帮助,将不胜感激。

1 个解决方案

#1


1  

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

如文章中所述,您的链接设置需要在〜/ .bashrc中。

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

可能有可能即使这不起作用......取决于你的tomcat如何启动。

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

您可以为tomcat设置一个自定义脚本,以确保它加载环境变量,例如这样的事情

tomcat-start.sh

. /etc/profile.d/myenvvars.sh
tomcat

#1


1  

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

如文章中所述,您的链接设置需要在〜/ .bashrc中。

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

可能有可能即使这不起作用......取决于你的tomcat如何启动。

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

您可以为tomcat设置一个自定义脚本,以确保它加载环境变量,例如这样的事情

tomcat-start.sh

. /etc/profile.d/myenvvars.sh
tomcat