In which file Tomcat Java Memory options are saved - java

I want to change memory configuration of Tomcat. I know it can be done at
Start > Apache Tomcat > Configure Tomcat > Java Tab] as can be seen below
and specifying options like
-Xms512m
-Xmx1024m
-XX:MaxPermSize=512m
-XX:MaxHeapFreeRatio=70
there.
However this program group is created if I install Tomcat from an executable. I have installed Tomcat by simply extracting the zip which does not create Program group. So now where can I specify this information

With regards to the question of where Tomcat's memory options are saved when using the service version, on my machine at least they can be found in the Windows Registry at:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\Tomcat-6\Parameters\Java
Initial memory and Maximum memory are recorded against the JvmMs and JvmMx values, while the options text is recorded against the Options value.
The Tomcat-6 portion of the address on mine is, I believe, based on the identifier I gave to the service (i.e. within the service manager Tomcat is named "Apache Tomcat 6.0 Tomcat-6"), and you may not need to go through Wow6432Node depending on whether you're using 32-bit or 64-bit Tomcat.
I'm assuming here that they haven't made any dramatic changes in where this information is stored in versions of Tomcat more recent than Tomcat 6.

Ohkay while digging inside Tomcat I found some information in one of its txt files (point 3.4) and online:
Apart from CATALINA_HOME (which is set to apache-tomcat-x.x.x directory, for e.g. C:\Program Files\Apache Software Foundation\apache-tomcat-7.0.41) and CATALINA_BASE (optional, defaults to CATALINA_HOME), all environment variables can
be specified in the setenv script. The script is placed either into
CATALINA_BASE/bin or into CATALINA_HOME/bin directory and is named
setenv.bat (on Windows) or setenv.sh (on *nix). The file has to be
readable.
By default the setenv script file is absent. If the script file is present
both in CATALINA_BASE and in CATALINA_HOME, the one in CATALINA_BASE is
preferred.
For example, to configure the JRE_HOME and CATALINA_PID variables you can
create the following script file:
On Windows, %CATALINA_BASE%\bin\setenv.bat:
set "JRE_HOME=%ProgramFiles%\Java\jre6"
exit /b 0
On *nix, $CATALINA_BASE/bin/setenv.sh:
JRE_HOME=/usr/java/latest
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
To set Java options for memory allocation for web app, add something like following (as per memory requirements of your application) to the same file
set JAVA_OPTS="-Xms256m -Xmx512m"
The CATALINA_HOME and CATALINA_BASE variables cannot be configured in the
setenv script, because they are used to locate that file.
All the environment variables described here and the setenv script are
used only if you use the standard scripts to launch Tomcat. For example, if
you have installed Tomcat as a service on Windows, the service wrapper
launches Java directly and does not use the script files.

Related

Increase memory size of Apache Tomcat Windows Service for a Java application created by an executable file

We have a legacy Java web application which we deploy to a Windows Server 2012 machine using an executable file and need to increase its memory pool size, since we get a lot of Out of memory exceptions.
It creates its own folders on Program Files including tomcat bin folder and a Windows service named "Apache Tomcat servicename" which is basically Tomcat version 6 but when I try to edit its Java options through tomcat6w.exe it says that this service is not installed on the system.
Is there a way to change the tomcat service being used by the application to a tomcat service installed from http://tomcat.apache.org/
Or maybe edit the service.bat (or any other file?) when creating the executable to hardcode the memory pool size there?
There is a line in service.bat like below:
"%EXECUTABLE%" //US//%SERVICE_NAME% ++JvmOptions "-Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties" --JvmMs 128 --JvmMx 256
Your Tomcat will have two exe files, Tomcat6.exe and Tomcat6w.exe
Suppose your service name is 'MyService' as shown in 'Windows Services', now rename Tomcat6w.exe as MyServicew.exe (notice that there is a 'w' also in the file name).
Now double click this MyServicew.exe, and a intuitive UI is presented for you to Monkey around with the service arguments.
All the best!
The solution was to edit the Tomcat RAM usage through Registry by running regedit, browsing to:
HKEY_LOCAL_MACHINE > SOFTWARE > Wow6432Node > ApacheSoftwareFoundation >
Procrun 2.0 > apache-tomcat > Parameters > Java
and editing following values:
JvmMs REG_DWORD 0x00000800 (2048)
JvmMx REG_DWORD 0x00001000 (4096)
The above applies when Tomcat is installed as a Windows Service and through a custom executable file and there is no access to its configuration through the tomcatxw.exe manager.
Increase these parameters in service.bat file
--JvmMs 128 --JvmMx 256 to --JvmMs 1024 --JvmMx 2048
It seems like you did not installed Tomcat with JSS installer. You could use tomcat6w if you have installed Tomcat using JSS Installer.
At this point, you need to follow these steps:
Run the shortcut located under Start Menu > All Programs > Apache Tomcat x > Configure Tomcat
Under the Java tab, make any adjustments for memory pool.
Save changes by clicking Apply.
Restart Tomcat.
Try this
Go to windows registry and find directory
HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Procrun 2.0\htfty\Parameters\Java
You can see the parameters JvmMs and JvmMx over there. Change them to desired values and restart service.
There sould be a file named catalina.bat ( setenv.bat in apache tomcat 7+ ) in the bin directory of tomcat installation. You can add your options to CATALINA_OPS and after restarting tomcat they should be applied. For checking if there applied use jvisualvm (it shows you what options are set for your jvm) .

Want to allocate more memory to Tomcat but catalina.sh is missing

I am running a Tomcat8 server on linux (RedHat). The machine it runs on has a total of 15GB Ram of which i want to allocate 11GB to the tomcat server. Currently it only has 3.3GB avaialable for use.
I have openjdk 64 bit installed.
I am trying to set CATALINA_OPTS to -Xms512M -Xmx11g and the JAVA_OPTS to -d64 -Xms256m -Xmx12g.
I found several how-to's saying something about a setenv.sh or catalina.sh both of which I cannot find: neither under tomcat8/bin, catalina_home or catalina_base which both point to /root.
So how do I increase available memory for my Tomcat server?
Thanks!
It seems that catalina.sh is either no longer existent in the latest tomcat release or it has something to do with the fact that i am using a amazon vm and they have some kind of modified tomcat8 distribution what i would doubt.
Solution:
under usr/share/tomcat8/conf/ there is a tomcat8.conf file.
Adding the row JAVA_OPTS="-Xms1g -Xmx12g" did the trick.
UPDATE:
Please check the comments below this post
In distributions such as RedHat the standard Tomcat structure is dispersed in different locations and the main catalina.sh is indeed not present.
There are two configuration files you may find. Assuming Tomcat 8, you'll find:
/etc/tomcat8/tomcat8.conf - this is the master file
/etc/sysconfig/tomcat8 - this is per service file which inherits from the above.
This split is designed so that you can have multiple Tomcat instances running which share some settings and have distinct settings for the 1st/2nd/3rd instance.
If you want to change the location of the software, for example, normally this would be shared so you would change /etc/tomcat8/tomcat8.conf, but if you want to change command line arguments (to pass context to a Tomcat instance) or change memory of the particular instance, you'd use /etc/sysconfig/tomcat8. You second instance of tomcat could be named tomcat8b in which case its configuration file would be /etc/sysconfig/tomcat8b.
If you have no intention of running a second instance, then change either file.
catalina.sh is under tomcat/bin

Set Java / Tomcat heap size (Xmx) without modifying catalina.sh

Most people seem to suggest setting the Java/Tomcat heap memory size for Tomcat6 by editing the /usr/share/tomcat6/bin/catalina.sh file, and adding something like:
# Set specific memory requirements for Tomcat6 (for server with ~512MB RAM).
CATALINA_OPTS="$CATALINA_OPTS -server -Xms128m -Xmx256m"
I am trying to build an Ansible playbook to configure a Tomcat-based server on Ubuntu, and it doesn't seem to me like having an entire custom catalina.sh file would be ideal—is there some other configuration file or local settings file/system used by Tomcat and/or Java to get the Xms and Xmx values?
Or... do most people use a custom catalina.sh file, and I'm just making a mountain out of a molehill?
Tomcat reads setenv.sh from bin directory for these extra settings. setenv.sh doesn't come with tomcat but you can create one for you and set CATALINA_OPTS in that.
Using JAVA_OPTS to set memory is not suggested by Tomcat because it applies to both startup and shutdown.
If you are launching via the "catalina.sh" script (directly or indirectly), then you have two options:
Modify ("hack"!) the script as suggested.
Find where the script is being invoked, and ensuring that CATALINA_OPTS is set to include the "-mx" option ... and exported ...
The latter is probably "cleaner", but there is no simple, one-size-fits-all way to get that variable set and exported. If you are launching Tomcat as a service, it depends on how your distro has wrapped Tomcat.
[Am I] just making a mountain out of a molehill?
It depends. If you are just doing this on a non-production platform, then Yes. If you are trying to build a production system that will continue to work over package upgrades and upgrades in your distro version, then No. (In the latter case, it is worth figuring out the best way to do this for your particular distro.)
For clarity: I used this in a setenv.sh script that goes in tomcat/bin. I can verify that it works for Ansible or my own install scripts:
CATALINA_OPTS="$CATALINA_OPTS -server -Xms512m -Xmx2048m"
Note that this worked for Tomcat 8 but should work for Tomcat 7 too.

Tomcat 7 setenv.sh is not found

I downloaded and extracted the apache-tomcat-7.0. As per the instructions in the RUNNING.txt (%CATALINA_BASE%/RUNNING.txt), it should set the JRE_HOME in the "setenv.sh" file.
Where is this file located ? Documentation said, it would be in CATALINA_HOME/bin directory. However this file is not present there.
Documentation does mention about the absence of setenv.(sh|bat) file:
(3.4) Using the "setenv" script (optional, recommended)
Apart from CATALINA_HOME and CATALINA_BASE, all environment variables can
be specified in the "setenv" script. The script is placed either into
CATALINA_BASE/bin or into CATALINA_HOME/bin directory and is named
setenv.bat (on Windows) or setenv.sh (on *nix). The file has to be
readable.
By default the setenv script file is absent. If the script file is present
both in CATALINA_BASE and in CATALINA_HOME, the one in CATALINA_BASE is
preferred
For example, to configure the JRE_HOME and CATALINA_PID variables you can
create the following script file:
On Windows, %CATALINA_BASE%\bin\setenv.bat:
set "JRE_HOME=%ProgramFiles%\Java\jre6"
exit /b 0
On *nix, $CATALINA_BASE/bin/setenv.sh:
JRE_HOME=/usr/java/latest
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
http://tomcat.apache.org/tomcat-7.0-doc/RUNNING.txt
Just create one yourself; it isn't part of the distribution. It's not that hard. For your case, simply add
JRE_HOME=/path/to/your/java/installation
to the file and make it executable (chmod 755 setenv.sh).
You can also add other options (e.g. -Xmx) if necessary.
If you don't find the "setenv.sh" or "setenv.bat" in bin folder of tomcat, follow the following setps:
Create new file in bin folder of tomcat.
Rename it to setenv.sh for linux user or setenv.bat for windows user
Now you can set multiple thing into this file:
Setting JRE_HOME
For linux user
JRE_HOME=/path/to/jre/jre6
For Windows user
set JAVA_HOME=C:\Path\to\jre\jdk6
Setting JAVA_OPTS
For linux user
JAVA_OPTS="$JAVA_OPTS -Xms512m -Xmx512m -DFOOBAR_CONFIGURATION_FILE=file:///C:/foobar.properties"
For windows user
set "JAVA_OPTS=%JAVA_OPTS% -Xms512m -Xmx512m -DFOOBAR_CONFIGURATION_FILE=file:///D:\foobar.properties"
Restart tomcat after setting variables.
That's it.
User Mindas' answer is completely correct: it is necessary to create the setenv.sh file in either the CATALINA_HOME or CATALINA_BASE directory, as the comment in the catalina.sh file indicates.
However, there is a "chicken and egg" problem wherein Tomcat must guess the location of the CATALINA_HOME/bin/ directory in the case where the CATALINA_HOME environment variable is not set.
I have encountered this situation on a Ubuntu server where fortunately Tomcat guesses the CATALINA_HOME/bin/ directory correctly. For a single-user environment where customization of Tomcat for different users isn't necessary, it seems that setting the JAVA_HOME or JRE_HOME environment variable in the catalina.sh script would be a solution to the "chicken and egg" problem.
In my case, I downloaded Tomcat for Windows. It also came with Linux shell scripts, so I created a 'setenv.sh' and tried to run it from Windows Subsystem for Linux, but got the above error. The issue was that the non-binary shell scripts were formatted for Windows, and Linux didn't know how to run them. After converting them to Linux format, it was able to recognize and run the scripts. Try this to convert from Windows to Linux:
dos2unix $CATALINA_HOME/bin/*.sh

How to pass a system property to a web application hosted in Tomcat 7 running as a Windows Service?

There are numerous places on the Internet, suggesting that it is easily achieved by any (or all) of the following methods:
through CATALINA_OPTS
through JAVA_OPTS
through TOMCAT_OPTS
by placing the set statements in the setenv.bat file inside the tomcat's bin folder
My problem, is that I have tried all of the above and my web application still does not see my system property!
Here is what I am doing:
Stop tomcat7 service
set CATALINA_OPTS=-Dabc.def=true in the system environment
set JAVA_OPTS=-Dabc.def=true in the system environment
set TOMCAT_OPTS=-Dabc.def=true in the system environment
put all of the above into c:\Program Files\Apache Software Foundation\Tomcat 7.0\bin\setenv.bat (seems totally redundant, but just in case)
Start tomcat7 service
Inspect the environment of the tomcat7 process using the Process Explorer tool - the environment is correct, I do see both CATALINA_OPTS and JAVA_OPTS and TOMCAT_OPTS equal to -Dabc.def=true
run my web app, which is a simple servlet dumping all the system properties to the response stream - abc.def is not amongst them
Please, put me out of my misery and tell me how to do it.
For the Tomcat service, startup settings are stored in the registry under Options key at:
HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Procrun 2.0\Tomcat<X>\Parameters\Java
(substitute appropriate Tomcat version where needed).
Edit:
On 64-bit Windows, the registry key is:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\Tomcat<X>\Parameters\Java
even if Tomcat is running under a 64-bit JVM.
I know this post is almost 9 years old but thought someone might find this useful.
Although #prunge and #mark answers were very accurate and following their logic I was able to add system properties to my tomcat 7 instance running on Windows, there is an easier way.
In the installation directory of Tomcat there is an exe you can run called
%INSTALL_DIRECTORY%\bin\tomcat7w.exe
This opens up a Tomcat properties windows where you can control the service i.e. start and stop tomcat and there is a tab (Java) that allows you to set the Java properties as well
Scroll to the end of that panel under "Java Options" and add your system properties
-Dpropertyname=value
Then navigate back to the General tab and restart tomcat
I have tested this and my grails app now can see my properties. I use the following Groovy code to get the property out
System.properties.getProperty("propertyname")
Adding the system properties in the Windows registry showed up in this window as well so its one and the same thing, just this application seems to me to be slightly more convenient.
Hope this helps someone else

Categories

Resources