Running Tomcat

Creating a Tomcat instance

To set up a Tomcat instance, run /usr/bin/tomcat8-instance-create dirname.

This will create the directory you name, and create a fresh Tomcat instance inside it.

You will have to configure the instance yourself to get it to do what you want.

You can run the server on a lab machine while you're logged into it, or on Grieg if you need to run it long-term or be accessible from outside UNSW.

Using the local Tomcat installation

First up, edit your .profile (and any startup scripts you may use) to set the CATALINA_BASE and CATALINA_HOME environment variables:

export CATALINA_HOME=/usr/share/tomcat8 export CATALINA_BASE=dirname

where dirname is the full path to the tomcat instance you created.

You may need to run source .profile to pick up the changes in your shell (or just log out and in again).

Running Tomcat on a lab machine

  • To start Tomcat, run $CATALINA_HOME/bin/startup.sh
  • You should then be able to access the page from within the CSE network.
  • The URL will be http://hostname:8080/ (eg. http://sitar02:8080/).
  • To stop Tomcat, run $CATALINA_HOME/bin/shutdown.sh.

Running Tomcat on Grieg

If you need your server to run longterm, or work from outside the CSE network, you can run your Tomcat instance on Grieg.

There are a few changes you need to make in order for this to work:

Run under priv srvr

Every user on Grieg gets their own virtual IP, so they can use any port they want.

To make Tomcat bind to the right IP, you need to run priv srvr before launching your startup.sh script.

Keep your instance under /srvr/zID

This isn't strictly required, but the disk access will be faster.

When you run priv srvr for the first time, the directory /srvr/zID/ will be created for you.

This directory is attached directly to Grieg, which makes it a good place to store heavily-accessed files for software running on the server.

Just use a path under /srvr/zID/ for dirname when creating and configring your Tomcat instance.

Modify server.xml

Edit dirname/conf/server.xml as shown below, substituting your own zID for zID throughout.

For access within CSE only

Before After
<Connector port="8080" protocol="HTTP/1.1" ... > <Connector port="8080" protocol="HTTP/1.1" address="zID.srvr" ... >
<Server port="8005" shutdown="SHUTDOWN" ... > <Server port="-1" ... >

Your site will be available on http://zID.srvr:8080/

For access from outside CSE

Before After
<Connector port="8080" protocol="HTTP/1.1" ... > <Connector port="80" protocol="HTTP/1.1" address="zID.srvr" proxyName="zID.srvr.cse.unsw.edu.au" proxyPort="80" ... />
<Server port="8005" shutdown="SHUTDOWN" ... > <Server port="-1" ... >

Your site will be available on http://zID.srvr.cse.unsw.edu.au/

Modified shutdown sequence

You should first specify an appropriate location for $CATALINA_PID, which keeps track of the process ID of the Tomcat process. Having this file around makes it easier to find the process you are running.

To set $CATALINA_PID:

export CATALINA_PID=$CATALINA_BASE/logs/catalina.pid

Note that you can place this anywhere, but it would make sense if you place it somewhere within your Tomcat directory.

Once you have set this value, you can start your server as per normal.

To stop the server without having to manually determine the process ID, create a script somewhere appropriate (I would suggest something like $CATALINA_BASE/bin/force-shutdown.sh) and copy the following lines into the file:

#!/bin/sh # check if file exists and filesize is greater than 0 if [ -s $CATALINA_PID ]; then # check if process is running kill -0 `cat $CATALINA_PID` if [ $? == 0 ]; then # kill Catalina process kill -USR1 `cat $CATALINA_PID` # remove PID file rm $CATALINA_PID else echo Catalina process not running. fi else echo File $CATALINA_PID does not exist fi

Don't forget to change the permissions so that the file is executable.

chmod u+x $CATALINA_BASE/bin/force-shutdown.sh
Last edited by jbc 24/07/2018