Just a quick post that I hope might benefit others. If you have been developing web applications on Tomcat for a while you have likely come the two error messages mentioned in the title.
Unfortunately by default, Tomcat won't provide you with any details about the cause of the error. Infact it wont even tell you which filter or listener is failing. This can be big problem in applications of significant size that have many filters and listeners configured. Fortunately there is a solution. In your webapplication's WEB-INF/classes folder you can create a logging.properties file with the following contents
org.apache.catalina.core.ContainerBase.[Catalina].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].handlers = java.util.logging.ConsoleHandler
Now you will be presented with the stacktrace
To find the exact Tomcat version / release use
the script version.sh which, e.g., in Ubuntu 12.04 is located in:
/usr/share/tomcat7/bin/version.sh
$ diff /var/lib/tomcat7/conf/logging.properties /var/lib/tomcat7/conf/logging.properties.orig
41,42c41,42
< org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = FINE
< org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
---
> org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO
> org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.FileHandler
And here are the original and the
modified logging.properties files.
<Resource name="jdbc/postgres/silly-test-database"
auth="Container"
type="javax.sql.DataSource"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/radoverview"
username="radoverview-user" password="radoverview-user-pass"
factory="org.apache.commons.dbcp.BasicDataSourceFactory"
maxActive="2" maxIdle="0" maxWait="-1"/>
Whereas the default DataSource factory in Tomcat7 is org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactoryand is sometimes distributed in the tomcat-dbcp.jar. E.g.:
radacer@radacer ~]$ jar tvf apache-tomcat-7.0.68/lib/tomcat-dbcp.jar | grep -i BasicDataSourceFactory 8176 Mon Feb 08 22:27:06 EET 2016 org/apache/tomcat/dbcp/dbcp/BasicDataSourceFactory.classTo solve this problem it is necessary that either:
scp /usr/share/tomcat7/lib/commons-dbcp.jar radacer@172.17.12.56:~/apache-tomcat-7.0.68/lib/
scp /usr/share/tomcat7/lib/commons-pool.jar radacer@172.17.12.56:~/apache-tomcat-7.0.68/lib/
(in the above example, Tomcat7 was installed in user space in the target machine).
#/bin/env bash
find ~/apache-tomcat-7.0.57/logs -mtime +7 -print0 | xargs -r -0 rm -rf
... and schedule it from Cron.
.
/var/lib/tomcat7/conf/tomcat-users.xml
jinfo program to attach to Tomcat (given its PID).
Among other things, the Tomcat's memory model will be diplayed with the following:
$ sudo jinfo 1752 | grep arch.data.model
Attaching to process ID 1752, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.80-b11
sun.arch.data.model = 32
Also, the maximum Heap size configured (alongside other JVM options):
$ sudo jinfo 1752 | grep -A6 VM\ Flags
Attaching to process ID 1752, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.80-b11
VM Flags:
-Djava.util.logging.config.file=/var/lib/tomcat7/conf/logging.properties -Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/share/tomcat7/endorsed -Dcatalina.base=/var/lib/tomcat7 -Dcatalina.home=/usr/share/tomcat7 -Djava.io.tmpdir=/tmp/tomcat7-tomcat7-tmp
-XX:PermSize<size> - Set initial PermGen Size.
-XX:MaxPermSize<size> - Set the maximum PermGen Size.
In my Ubuntu 14.04 system with Tomcat 7.0, the $CATALINA_HOME/bin/startup.sh script
invokes the catalina.sh file which in turns contains the following code:
if [ -r "$CATALINA_BASE/bin/setenv.sh" ]; then
. "$CATALINA_BASE/bin/setenv.sh"
elif [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then
. "$CATALINA_HOME/bin/setenv.sh"
… which basically sources the setenv.sh file (if such exists).
$ pwd
/home/voops/apache-tomcat-7.0.57/bin
voops@esavo00:~/apache-tomcat-7.0.57/bin#
$ cat setenv.sh
export JAVA_OPTS="-Dfile.encoding=UTF-8 -Xms512m -Xmx2024m -XX:PermSize=128m -XX:MaxPermSize=512m"
$ netstat -anp | grep 8080 | grep LISTEN
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 26123/java
Additional confirmation of the pid:
$ ps -ef | grep tomcat | grep -v grep
voops 26123 1 3 12:49 pts/0 00:00:16 /usr/local/jdk1.7.0_67/bin/java -Djava.util.logging.config.file=/home/voops/apache-tomcat-7.0.57/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/home/voops/apache-tomcat-7.0.57/endorsed -classpath /home/voops/apache-tomcat-7.0.57/bin/bootstrap.jar:/home/voops/apache-tomcat-7.0.57/bin/tomcat-juli.jar -Dcatalina.base=/home/voops/apache-tomcat-7.0.57 -Dcatalina.home=/home/voops/apache-tomcat-7.0.57 -Djava.io.tmpdir=/home/voops/apache-tomcat-7.0.57/temp org.apache.catalina.startup.Bootstrap start
web.xml of the manager application (for instance it could be under /tomcat7/webapps/manager/WEB-INF/web.xml)
$ mkdir -p ~/downloads && cd ~/downloads
$ wget http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.57/bin/apache-tomcat-7.0.57.tar.gz
$ cd
$ whoami
voops
$ cp downloads/apache-tomcat-7.0.57.tar.gz .
$ tar xvfz apache-tomcat-7.0.57.tar.gz
$ echo $CATALINA_HOME
/home/voops/apache-tomcat-7.0.57
---%<---------------------------------------------------------
$ tail -f /home/voops/apache-tomcat-7.0.57/logs/catalina.err
Cannot open PID file /var/run/jsvc.pid, PID is 12504
Service exit with a return value of 255
Cannot open PID file /var/run/jsvc.pid, PID is 13918
Service exit with a return value of 255
Cannot open PID file /var/run/jsvc.pid, PID is 14260
Service exit with a return value of 255
Switching umask back to 002 from 077
Cannot open PID file /var/run/jsvc.pid, PID is 31946
Service exit with a return value of 255
--------------------------------------------------------->%---
... so in the end I am just using scripts $CATALINA_HOME/bin/startup.sh and
shutdown.sh to start and stop Tomcat (which seem to work just fine regardless)
and is not clear to me what was the purpose of this script.
$ $CATALINA_HOME/bin/startup.sh
Using CATALINA_BASE: /home/voops/apache-tomcat-7.0.57
Using CATALINA_HOME: /home/voops/apache-tomcat-7.0.57
Using CATALINA_TMPDIR: /home/voops/apache-tomcat-7.0.57/temp
Using JRE_HOME: /usr/local/jdk1.7.0_67
Using CLASSPATH: /home/voops/apache-tomcat-7.0.57/bin/bootstrap.jar:/home/voops/apache-tomcat-7.0.57/bin/tomcat-juli.jar
Tomcat started.
$ cat /home/voops/apache-tomcat-7.0.57/conf/tomcat-users.xml | tail -6
<!-- below 3 lines added by MP@2014.12.02 -->
<role rolename="manager-gui"/>
<role rolename="manager"/>
<role rolename="admin"/>
<user username="admin" password="admin" roles="admin,manager,manager-gui"/>
</tomcat-users>
$ echo $JAVA_HOME
/usr/local/jdk1.7.0_67
Whether that was really indispensable or not I did not verify.
$ whereis tomcat7
tomcat7: /etc/tomcat7 /usr/share/tomcat7
$ find /usr/share/tomcat7 | grep catalina.jar
/usr/share/tomcat7/lib/catalina.jar
$ java -cp /usr/share/tomcat7/lib/catalina.jar org.apache.catalina.util.ServerInfo
Server version: Apache Tomcat/7.0.26
Server built: Apr 1 2013 08:32:04
Server number: 7.0.26.0
OS Name: Linux
OS Version: 3.2.0-70-generic-pae
Architecture: i386
JVM Version: 1.7.0_60-b19
JVM Vendor: Oracle Corporation
/var/lib/tomcat7
/usr/share/tomcat7
/etc/tomcat7
cd /usr/share/tomcat7/bin/
There, make sure the file setenv.sh has the following content (create the file if it doesn't already exist):
$ cat setenv.sh
CATALINA_OPTS="$CATALINA_OPTS -server -Xms256m -Xmx1024m
The reasoning is explained in file catalina.sh.
/etc/init.d/tomcat7:
# mperdikeas change section 2013-11-09-start
#JDK_DIRS="/usr/lib/jvm/default-java ${OPENJDKS} /usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-6-sun"
JDK_DIRS="/usr/lib/jvm/java-7-oracle /usr/lib/jvm/default-java ${OPENJDKS} /usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-6-sun"
# mperdikeas change section 2013-11-09-end
sudo apt-get install tomcat7
sudo /etc/init.d/tomcat7 [start|stop|restart]
tail -f /var/log/tomcat7/catalina.outThe following may be useful too:
tail -f /var/log/tomcat7/localhost.2013-11-02.log
sudo apt-get install tomcat7-admin... and then you have to edit file 'tomcat-users.xml':
sudo emacs -nw /var/lib/tomcat7/conf/tomcat-users.xml... and add the following:
<role rolename="manager-gui"/>
<role rolename="admin"/>
<user username="admin" password="admin" roles="admin,manager-gui"/>
... the admin front-end is then available at localhost:8080/manager