6

I have Tomcat installed as service.

It's CATALINA_HOME and CATALINA_BASE are same:

-Dcatalina.base=/usr/share/tomcat7 -Dcatalina.home=/usr/share/tomcat7

I added setenv.sh script to /usr/share/tomcat7/bin with next lines:

$ cat /usr/share/tomcat7/bin/setenv.sh
#!/usr/bin/env bash

export JAVA_OPTS="-Dcom.sun.management.jmxremote=true \
                  -Dcom.sun.management.jmxremote.port=9090 \
                  -Dcom.sun.management.jmxremote.ssl=false \
                  -Dcom.sun.management.jmxremote.authenticate=false \
                  -Djava.rmi.server.hostname=54.***.***.65"

But still haven't changes in Tomcat's behavior - no new port opened, no new options is ps aux | grep java:

# netstat -anp | grep 9090 | wc -l
0

# ps aux | grep java
tomcat   32063 96.6 23.5 1904000 399872 ?      Sl   09:04   3:07 /usr/lib/jvm/jre/bin/java -Xms512M -Xmx1024M -javaagent:/usr/share/tomcat7/newrelic/newrelic.jar -classpath :/usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar:/usr/share/java/commons-daemon.jar -Dcatalina.base=/usr/share/tomcat7 -Dcatalina.home=/usr/share/tomcat7 -Djava.endorsed.dirs= -Djava.io.tmpdir=/var/cache/tomcat7/temp -Djava.util.logging.config.file=/usr/share/tomcat7/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager org.apache.catalina.startup.Bootstrap start

File owned by tomcat user and have exec bit:

# ls -l /usr/share/tomcat7/bin/setenv.sh
-rwxr-xr-x 1 tomcat tomcat 329 Jun 15 08:52 /usr/share/tomcat7/bin/setenv.sh
setevoy
  • 894
  • 4
  • 15
  • 28
  • Did you find a solution to this problem? If so, please post your answer here, as I am facing a similar issue - setenv.sh is just not being picked up by tomcat7. – nonbeing Nov 19 '15 at 10:43
  • @noumenon Hi. Thanks fore reminder. My solution added as answer. – setevoy Nov 19 '15 at 19:57

3 Answers3

3

The environment variable you should set is called 'CATALINA_OPTS'. Here is an example in the tomcat documentation, which is also related to monitoring: Apache Tomcat 7 - Monitoring and Managing Tomcat

stoeff
  • 480
  • 4
  • 6
  • Thanks, but no: http://stackoverflow.com/questions/11222365/catalina-opts-vs-java-opts-what-is-the-difference – setevoy Jun 15 '15 at 12:30
  • 3
    Where does the tomcat documentation contradict with that stackoverflow question/answer? – stoeff Jun 15 '15 at 20:48
0

According to my blog my solution was set JAVA_OPTS with $CATALINA_HOME/conf/tomcat7.conf, e.g.:

# You can pass some parameters to java here if you wish to
#JAVA_OPTS="-Xminf0.1 -Xmaxf0.3"
JAVA_OPTS="-Xms512M -Xmx1024M -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=9090 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=54.***.***.65"

And result after Tomcat's restart was:

# ps aux | grep java
tomcat    1359 96.6 13.0 1887508 220732 ?      Sl   09:19   0:44 /usr/lib/jvm/jre/bin/java -Xms512M -Xmx1024M -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=9090 -[...]

P.S. Don't forget create copy of you default configuration files. Then grep -r JAVA_OPTS etc/* to find it in # documentation will be more helpful :-)

setevoy
  • 894
  • 4
  • 15
  • 28
  • 1
    Nah, CATALINA_OPTS works better, without bogus errors on shutdown. And my tomcat7 picks up bin/setenv.sh without a problem. – kubanczyk Nov 19 '15 at 21:06
  • 3
    Thanks! The key part of the solution is to use `$CATALINA_HOME/conf/tomcat7.conf` instead of `/usr/share/tomcat7/bin/setenv.sh`. I can finally set any command-line args (or env variables) for Tomcat7. I am using tomcat7 installed from the yum repo on Amazon-Linux, not the tomcat zip from tomcat.apache.org - and apparently this is why setenv.sh is not being picked up. – nonbeing Nov 21 '15 at 02:35
  • @noumenon Glad can help you. Btw - I faced with thus issue also with Tomcat from yum repo for Amazon Linux. – setevoy Nov 21 '15 at 15:47
  • @kubanczyk Are you ready to claim - every "equal" software installations on "equal" operation systems will work in proper way? – setevoy Nov 21 '15 at 15:50
0

Just for reference, but in Tomcat 8.5.38 (didn't check 7 though), my custom setenv.sh was still picked up fine. I like to use this e.g. for setting the $CLASSPATH, which I find more maintenance-friendly and I don't have to adapt Tomcat's own startup files, and it makes my custom changes more visible.

Gregor
  • 101
  • 2