Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAVA_OPTS set in catalina.sh not working for TOMCAT private instance

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

like image 457
user20507 Avatar asked Jul 13 '14 14:07

user20507


3 Answers

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.

like image 163
cst1992 Avatar answered Nov 14 '22 00:11

cst1992


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"*
like image 23
konrad Avatar answered Nov 14 '22 00:11

konrad


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.

like image 42
Olaf Kock Avatar answered Nov 14 '22 01:11

Olaf Kock