running tomcat 6 & 7

When you are in a position that you have several versions of OpenClinica running at the same time, this might be problematic, because some run on tomcat6, but others must run on tomcat7. Let's say you use apache2 as front-end and you have an OpenClinica 3.1.4 instance running as oc314 and an OpenClinica 3.6 instance, running as oc36. And oc314 is deployed by tomcat6 and oc36 by tomcat7.

hold on, not so quick: 6 & 7?

Yes, you can have different versions of tomcat on the same server. When you have a "normal" tomcat6 installation, you will have installed jdk 1.6 and "java" will refer to that. But if you run on top of that a normal installation of jdk1.7 in for example /usr/lib/jvm/jdk1.7.0_51 and then a normal installation of tomcat7, you can use jdk1.7 by referring to it in setenv.sh by adding the line export JAVA_HOME="/usr/lib/jvm/jdk1.7.0_51".
You probably know that tomcat uses ports for communication and for shutdown and by default these are for http 8080, for ajp 8009 and for shutdown 8005. If you used these for tomcat6, you must use other ports for tomcat7, and you do this in server.xml, for example http 8081, ajp 8010 and shutdown 8006.
To summarize this all:

filetomcat6tomcat7
bin/setenv.shexport JAVA_HOME="/usr/lib/jvm/java-6-openjdk"export JAVA_HOME="/usr/lib/jvm/jdk1.7.0_51"
conf/server.xml<Server port="8005" shutdown="SHUTDOWN"><Server port="8006" shutdown="SHUTDOWN">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" / /> <Connector port="8010" protocol="AJP/1.3" redirectPort="8443" / />
/etc/init.d/tomcat or tomcat7SHUTDOWN_PORT=`netstat -vatn|grep LISTEN|grep 8005|wc -l` SHUTDOWN_PORT=`netstat -vatn|grep LISTEN|grep 8006|wc -l`

As you can see we have two ways of communicating with tomcat: via 8080/8081 or via AJP. With this second method the request is first handled by apache and then routed to tomcat. Because we now have two tomcats, we must specify who does what through which channel.
We define the two channels in /etc/apache2/workers.properties:

$ps=/
worker.list=tomcat6,tomcat7

worker.tomcat6.port=8009
worker.tomcat6.host=localhost
worker.tomcat6.type=ajp13

worker.tomcat7.port=8010
worker.tomcat7.host=localhost
worker.tomcat7.type=ajp13

Who does what is defined by the JKMount directive. For example:

<VirtualHost 212.224.84.235:80>
  JKMount /oc314*           tomcat6
  JKMount /manager-tomcat6* tomcat6
  JKMount /oc36*            tomcat7
  JKMount /manager-tomcat7* tomcat7

  ServerName tds-training.com
  ServerAlias *.tds-training.com
  
  etc.

OK, more tips?

While we're editing all this, why not make our OpenClinica a bit safer. We can do three things: close the http-port for the two tomcats, rename the manager-app and undeploy the examples . Closing the http-ports is done by commenting out in server.xml the part about port 8080/8081, like this:

<!--
<Connector executor="tomcatThreadPool"
           port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />
-->

Now rename /opt/tomcat/webapps/manager to /opt/tomcat/webapps/manager-tomcat6 and likewise, rename /opt/tomcat7/webapps/manager to /opt/tomcat7/webapps/manager-tomcat7

Now start your two tomcats and browse to http://tds-training.com/manager-tomcat6/html and http://tds-training.com/manager-tomcat7/html and undeploy examples.

Other how-to-pages can be found here.

this page was last reviewed August 2015