3

I wish to run TOMCAT with my current user's permissions, not the root's environment variables.

vagrant@dev:~/Workspace/eurekastreams$ echo $JAVA_OPTS
-Xmx1024m -XX:MaxPermSize=128m -Dlog.home=/home/vagrant/Workspace/software/

I tried, vagrant$>sudo -E /etc/init.d/tomcat7 start.

However, my software is not logging to the /home/vagrant/Workspace/software directory, which means, I believe, that the JAVA_OPTS environment variable was not set.

Am I understanding sudo -E correctly that it will perform a command with env vars of the current user?

4

4 回答 4

6

来自man sudo

-E, --preserve-env
Indicates to the security policy that the user wishes to preserve their existing 
environment variables. The security policy may return an error if the user does 
not have permission to preserve the environment.

因此,是的,-E将使用当前环境变量执行命令。

于 2017-01-31T10:36:29.417 回答
1

除非您在 sudo 中使用 -u 参数,否则它将以 root 身份运行您的命令。这个怎么样:

sudo -u yourusername -l /etc/init.d/tomcat7 start

-u 用户名:以指定用户身份运行命令 -l:使其成为登录 shell,读取启动脚本,例如 .bashrc,我认为这是您设置环境变量的地方。

于 2012-12-12T20:44:42.337 回答
0

关于什么:

JAVA_OPTS=$JAVA_OPTS sudo -E /etc/init.d/tomcat7 start

证明:

~/Desktop> X=foo sudo bash
 # echo $X

 # exit
exit
~/Desktop> X=foo sudo -E bash
 # echo $X
foo
 # exit
exit
~/Desktop>
于 2012-08-20T13:52:39.443 回答
0

我认为这/etc/init.d/tomcat7只是一个启动脚本,而不是 tomcat 二进制文件本身,所以 sudo 没有任何意义。您应该编辑此脚本,或者例如将它的另一个副本安装到类似的位置/home/$USER/bin/并从那里启动它。

于 2012-08-20T16:47:17.330 回答