setenv.sh in an individual tomcat catalina base

ziggy picture ziggy · Nov 9, 2010 · Viewed 17.1k times · Source

At the moment i have several catalina bases configured with the following directories,

conf logs server webapps work

The bin, lib and common directories are all still in $CATALINA_HOME.

I now need to add a setenv.sh file in the bin directory but i dont want it to be used by all the catalina bases. To do this i am thinking of adding a bin diretory on the catalina_base that i want to pick up the setenv.sh file. The bin directory will only contain the setenv.sh file and nothing else. Everything else will still be in $CATALINA_HOME/bin/ (ie. startup.sh catalina.sh shutdown.sh etc)

Are there any side effects to doing this? Can tomcat use both $CATALINA_BASE/bin/ and $CATALINA_HOME/bin during startup?

Answer

bartosz.r picture bartosz.r · Nov 24, 2010

I have not tested how it behaves if you provide a bin with setenv.sh. But this is my way of configuring many tomcat applications running different instances from one CATALINA_HOME.

If you have that configuration, then you probably have your own startup script that does run catalina.sh. with options JAVA_HOME, CATALINA_HOME, CATALINA_BASE, and probably CATALINA_PID.

So whatever you need to change or to add in setenv.sh, just change in your own startup script. Or create your setenv.sh that will be called at the beggining of your start script. And put this in your own bin directory.

I assume it is linux (in windows it will be similar). So you can have a few applicaitons, lets call them APP1, APP2. Both have: bin conf logs server webapps work. the directory structure can be:

/apps/APP1
   bin
      start.sh
      stop.sh
   conf
   logs
   server
   webapps
   work
/apps/APP2
   bin
      start.sh
      stop.sh
   conf
   logs
   server
   webapps
   work
/opt/apache-tomcat-xxx
   all the standard tomcat files...
/opt/java-1.6
   all the standard java files...

And in start.sh for APP1 you can set: JAVA_HOME, CATALINA_HOME, CATALINA_BASE, and probably CATALINA_PID, CATALINA_OPTS.

export JAVA_HOME=/opt/java-1.6
export CATALINA_HOME=/opt/apache-tomcat-xxx
export CATALINA_BASE=/apps/APP1
export CATALINA_PID=${CATALINA_BASE}/temp/app1.pid.file
export CATALINA_OPTS=-Dmy.fancy.variable=hello

${CATALINA_HOME}/bin/catalina.sh start

Stop will be almost the same. You only need to change start to stop. next step will be to move variable definitions to some file, let's say config.ini and then you have to source this file in start.sh and also in stop.sh. In windows, you need to change export to set. In different shells (if not bash) you need to follow the instructions.