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

3

8

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

Einsteinium answered 13/7, 2014 at 14:42 Comment(0)
C
9

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.

Cryptocrystalline answered 18/12, 2015 at 10:21 Comment(2)
you did't tell what the "-server" is doing.Opprobrious
@Opprobrious #199077Cryptocrystalline
I
2

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"*
Inkhorn answered 13/7, 2014 at 14:50 Comment(1)
Can you explain this a bit more? As to why catalina.sh settings are not working?Einsteinium
S
2

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.

Senaidasenalda answered 14/7, 2014 at 10:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.