Tomcat – Pass environment variable through to another user when being run as sudo

rhel5sudotomcat

I am installing Tomcat on a RHEL5 machine, and am having some trouble starting it, because JAVA_HOME isn't set. Tomcat is being started using

sudo /sbin/service tomcat start

and runs under the user tomcat. When I am logged in as myself or as the root user, JAVA_HOME is properly set (using /etc/profile.d/java.sh). I am guessing that this isn't being properly passed through by sudo.

Can someone point me in the direction of the change I need to make to get this variable either passed through by sudo or picked up by the tomcat user? I believe there are a number of ways.

Thanks in advance

Rich

Best Answer

One way to do it is to add JAVA_HOME to the tomcat start up script, which should be in /etc/init.d