Running Tomcat

Running Tomcat

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, or on Grieg if you need to run it long-term.

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).

Starting and stopping Tomcat

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

Running a Tomcat instance on Grieg

If you need your server to run longterm, or need your site to be externally-accessible, you can run your Tomcat instance on Grieg.

There are a couple of adjustments you need to make in order for this to work:

Modify server.xml

Edit dirname/conf/server.xml

You need to switch to using port 80 (if you want it externally accessible), add the hostname and disable the shutdown port.

The shutdown port won't bind to the right address, so it's best disabled altogether.

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

(Subsituting zID with your zID.)

Because of this change, the regular script won't work - use the replacement script below.


If you don't need your site to be externally-accessible, just run priv srvr before running

The server will bind to a virtual IP, and be accessible via http://username.srvr:8080/ (eg. http://z1234567.srvr:8080/).

Use username.srvr URLs

  • Internally accessible - any port: http://username.srvr:8080/ (eg. http://z1234567.srvr:8080/).
  • Externally accessible - port 80 only: http://username.srvr:8080/ (eg. http://z1234567.srvr:8080/).
  • Run your server on port 80

    Making server visible from outside the CSE network

    If you would like be able to see your server from outside of the CSE network then you will need to do a few things:

    1. Run Tomcat on Grieg - it's the only machine configured to accept external connections.
    2. Edit your server.xml (under dirname/conf/server.xml):
      • Find Connector port="8080" protocol="HTTP/1.1"
      • Replace with Connector port="80" protocol="HTTP/1.1" address="username.srvr" (substititing your own username)
      • Find Server port="8005" shutdown="SHUTDOWN"
      • Replace with Server port="-1"
    3. Replace the contents of the script above with the following: modify your server.xml file, which lives in the conf folder in your Tomcat installation (e.g. /srvr/foo/apache-tomcat-6.0.32/conf/server.xml). Open the file and make the changes below.

      • Set the address in the Connector tag. Find the following line: Connector port="8080" protocol="HTTP/1.1"
      • Change the port to 80 and add the address of the server:
      • Connector port="80" protocol="HTTP/1.1" address="foo.srvr"
      • Disable the shutdown port as this seems to connect to the wrong IP and there isn't much you can do about it. Find the following line: Server port="8005" shutdown="SHUTDOWN"
      • And replace it with:
      • Server port="-1"
      • Because of this change the regular script will not work properly, so the shutdown sequence will need to be changed. See the Modified shutdown sequence section below.

      Once these changes have been made, you can access the server from within the CSE network at http://foo.srvr/ (the 8080 is no longer required as it is now running on port 80) and from outside the CSE network at As always, substitute your username for foo

      Telling Tomcat the address of proxied requests

      From: the online Tomcat Documentation

      When you are running behind a proxy server (or a web server that is configured to behave like a proxy server), you will sometimes prefer to manage the values returned by these calls.

      In particular, you will generally want the hostname and port number to reflect that specified in the original request, not the one on which the Connector itself is listening.

      You can use the proxyName and proxyPort attributes on the <Connector> element to configure these values.

      <Connector port="80" ... proxyName="" proxyPort="80"/>

      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/

      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/ 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/
      Last edited by jbc 13/07/2018