Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat 7: "setenv.sh" vs "/etc/default/tomcat7" to update JAVA_OPTS

I wish to update the JAVA_OPTS used by Tomcat 7 to enable JMX monitoring.

When I look at the internet I see 2 primary ways to do it:

  1. Using "setenv.sh" [The popular way]

  2. Update "/etc/default/tomcat7"

Now which is the recommended way to do this? What are the advantages and disadvantages of each?

like image 736
Hari Krishna Ganji Avatar asked Nov 10 '22 04:11

Hari Krishna Ganji


1 Answers

setenv.sh is the recommended way. The advantage is closest path to manipulate. Also whenever you need to deploy multiple apps with different conf you can set each app different setenv.sh.
For example for me I am serving 3 apps: first folder calling serverA pointing in conf by CATALINA_BASE=/var/tomcat/serverA.

Here is a sample code catalina.sh reading all setenv to set memory as their conf.

path:// Enviroment/tomcat/serverA/bin/setenv.sh

#!/bin/sh
JAVA_HOME=/usr/java
JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8
-server
-Xms1256m
-Xmx1256m
-XX:NewSize=256m
-XX:MaxNewSize=256m
-XX:PermSize=256m
-XX:MaxPermSize=256m
-XX:+DisableExplicitGC
-XX:+CMSClassUnloadingEnabled"
CATALINA_HOME=/var/tomcat
CATALINA_BASE=/var/tomcat/serverC
export JAVA_HOME JAVA_OPTS CATALINA_HOME CATALINA_BASE
like image 180
Ali.Mojtehedy Avatar answered Nov 14 '22 21:11

Ali.Mojtehedy