5

I have placed JVM options via JAVA_OPTS in catalina.sh in the catalina base. However, the system doesn't pick those options--I am trying to pass profiling information to set paths for project properties and logging files. I have to set the options in setenv.sh in the private instance's bin. Even the echo command that I put in catalina.sh to view the JAVA_OPTS doesn't get printed-defaults like CATALINA_BASE,etc. do get printed. Is catalina.sh even being processed?

At the end of the day, my system works fine with setenv.sh. I am curious as to why JAVA_OPTS are not being picked up from catalina.sh.

I am using Ubuntu 12.04 with TOMCAT 7 installed and JDK 1.7.

Thanks

user20507
  • 63
  • 1
  • 1
  • 5

3 Answers3

8

You are not supposed to edit the catalina.sh file - it states so in that file. Instead, to set your environmental variables, create a setenv.sh file in the same directory where catalina.sh is (called CATALINA_BASE/bin) and write your code in it.

I had to set the JAVA_OPTS variable myself, and I created the bin/setenv.sh file, set it to executable chmod +x bin/setenv.sh and wrote in it:

JAVA_OPTS="$JAVA_OPTS -Xms128m -Xmx512m -server"

which set my initial allocated memory to 128 and max memory to 512 MB. And it was working.

cst1992
  • 2,429
  • 21
  • 36
1

please edit: /etc/default/tomcat7 or /etc/default/{user_who_runs_tomcat}

e.g.:

*JAVA_OPTS="-Djava.awt.headless=true -Xmx2G -XX:+UseConcMarkSweepGC -server -XX:MaxPermSize=384m"*
JJD
  • 44,755
  • 49
  • 183
  • 309
konrad
  • 59
  • 4
1

catalina.sh has a lot of conditionals - it happened to me more than once that I edited the wrong position, or one that was overwritten later in that file. setenv.sh works fine, and that's exactly what it's there for: Imagine you're installing a tomcat update - this will overwrite your catalina.sh. However, tomcat never comes with setenv.sh, thus it won't overwrite your changes.

Further, you might want to define CATALINA_OPTS instead of JAVA_OPTS: Those are the options that are used to start tomcat. If part of your configuration is JAVA_OPTS="-Xmx16G -Xms16G", you'd allocate 16G heap space when you try to shut down tomcat: The shutdown process spawns a JVM with the JAVA_OPTS parameters as well. Only the startup process spawns with the CATALINA_OPTS environment (in addition to JAVA_OPTS), thus that's most likely what you want to configure/tune, otherwise you risk not being able to stop tomcat due to ridiculous memory requirements of shutdown.sh.

Olaf Kock
  • 43,342
  • 7
  • 54
  • 84