Tomcat: What Can Go Wrong?

Is Your Server Up?

The answer to this question can be found with this Unix command:

-bash-4.1$ ps -ef | grep dimacdon
dimacdon  7348     1  0 Feb19 ?        00:00:56 /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java -Djava.util.logging.config.file=/u/dimacdon/apache-tomcat-7.0.35/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/u/dimacdon/apache-tomcat-7.0.35/endorsed -classpath /u/dimacdon/apache-tomcat-7.0.35/bin/bootstrap.jar:/u/dimacdon/apache-tomcat-7.0.35/bin/tomcat-juli.jar -Dcatalina.base=/u/dimacdon/apache-tomcat-7.0.35 -Dcatalina.home=/u/dimacdon/apache-tomcat-7.0.35 -Djava.io.tmpdir=/u/dimacdon/apache-tomcat-7.0.35/temp org.apache.catalina.startup.Bootstrap start
dgerman  19581 17907  0 11:31 pts/273  00:00:00 grep dimacdon
-bash-4.1$ ps -ef | grep krismock
dgerman  19943 17907  0 11:31 pts/273  00:00:00 grep krismock
-bash-4.1$ whoami
dgerman
-bash-4.1$
In this example we see Dimas's server is up, but Krista's isn't.

That long line will show up wrapped around on your screen.

You can check if anybody server's running just by using that person's username.

What Is Your Server's Process ID?

Take a look at the output above: Dimas's server has a process ID of 7348.

It is the number to the left of 1. It's listed in the second column, after the owner's username.

-bash-4.1$ ps -ef | grep hartz
hartzogc 17410     1  0 Feb18 ?        00:01:40 /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java -Djava.util.logging.config.file=/u/hartzogc/apache-tomcat-7.0.35/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/u/hartzogc/apache-tomcat-7.0.35/endorsed -classpath /u/hartzogc/apache-tomcat-7.0.35/bin/bootstrap.jar:/u/hartzogc/apache-tomcat-7.0.35/bin/tomcat-juli.jar -Dcatalina.base=/u/hartzogc/apache-tomcat-7.0.35 -Dcatalina.home=/u/hartzogc/apache-tomcat-7.0.35 -Djava.io.tmpdir=/u/hartzogc/apache-tomcat-7.0.35/temp org.apache.catalina.startup.Bootstrap start
dgerman  28425 17907  0 11:40 pts/273  00:00:00 grep hartz
-bash-4.1$
Connor's server has a process ID of 17410. Who's Connor?
-bash-4.1$ finger hartzogc
Login: hartzogc                         Name: Connor Hartzog
Directory: /u/hartzogc                  Shell: /bin/bash
Last login Thu Feb 19 17:02 (EST) on pts/275 from 156-56-133-56.dhcp-bl.indiana.edu
No mail.
No Plan.
-bash-4.1$
How Do You Stop Your Server?

If all is set properly the command is:

$CATALINA_HOME/bin/shutdown.sh
Then check (as above) to convince yourself it went away.

What If It Doesn't Want to Stop?

First, wait a little, give it some time.

If you're sure it really doesn't want to go away you can kill the process:

kill 7348
The command above would try to stop Dimas's server process.

It will only work for Dimas since he is the owner of the process.

What If It Really Doesn't Want to Go Away?

If you're sure kill doesn't work you can try:

kill -9 7348
How Could That Even Happen? (What Not To Do.)

Trying to start your server if it's already running is something to avoid.

It works the same with your car: don't try to start it if it's already running.

You might damage it. Start the car only when it's not running.

Likewise if you start your Tomcat when it's running already you might turn it into a zombie.

If you start your Tomcat when it's running already it will try to take away resources from itself.

The two (or more if you keep running the start command) will soon deadlock each other.

Some other lightweight servers are immune to this problem but Tomcat and MySQL are heavyweights.

We don't do any MySQL here but I wanted to let you know Tomcat is in good company.

How Do You Start Your Server?

You know this already:

  • if your given ports are available, and
  • if your server is not already running, then
  • start the server with $CATALINA_HOME/bin/startup.sh

As a reminder, NEVER try to start the server if it's already running.

How Do You Restart Your Server?

To restart the server:

  • Make sure it's running. (Check with ps).
  • Stop the server (using one of the methods discussed above).
  • Make sure it's down. (Check again with ps as shown).
  • Start it with the command $CATALINA_HOME/bin/startup.sh
  • Check that it's up (again, using the ps command).

What If Something (Else) Goes Wrong?

The server writes a number of log files in

$CATALINA_HOME/logs
If something goes wrong it's going to be documented in real time in one of those files.

How Do You Check Ports' Availability?

I give you ports and list them so we can all be on the same page.

Anyone can use any of the available ports (on purpose, or by mistake).

To check if the ports assigned to you are available try this:

netstat -a | grep 8346
Here's how it works for me:
-bash-4.1$ netstat -a | grep 8346
tcp        0      0 *:8346                      *:*                         LISTEN
unix  2      [ ]         STREAM     CONNECTED     3325834653
-bash-4.1$ netstat -a | grep 13651
tcp        0      0 *:13651                     *:*                         LISTEN
-bash-4.1$ netstat -a | grep 13652
tcp        0      0 localhost:13652             *:*                         LISTEN
-bash-4.1$ netstat -a | grep 13653
tcp        0      0 *:13653                     *:*                         LISTEN
-bash-4.1$ netstat -a | grep 13649
-bash-4.1$
You see that 8346 is not available (I am using it).

Also ports 13651 and 13652 are taken (by Patrick Gibbons, as they should).

Port 13653 is also not available (Scott Goodwin is using it, as he should).

But we see that port 13649 is not being used at the moment.

That is one of Caleb's ports and once he starts using it it will become unavailable to the rest of us (as it should).

But currently 13649 is clearly not being used. So someone (else) could grab it and use it (by mistake or on purpose).

Where Is My Server's Home Page?

Your server's original homepage is at:

$CATALINA_HOME/webapps/ROOT/index.jsp
You may or may not be able to change this page (also it's very complicated). We will discuss that later.

What we did in lab was to define a (new) file:

$CATALINA_HOME/webapps/ROOT/index.html
This file did not exist at first but once we create it it becomes the default home page.

Is There a Map of All Server's Files?

Absolutely, we described that at the end of the lab.

Here's another map:

$CATALINA_HOME --+-- webapps --+-- squash --+-- WEB-INF --+-- classes --+-- One.java
                 |             |            |             |
                 |             |            |             +-- lib 
                 |             |            |             | 
                 |             |            |             +--- web.xml
                 |             |            |
                 |             |            +-- one.html
                 |             |            |
                 |             |            +-- index.html
                 |             | 
                 |             +-- ROOT --+-- WEB-INF ... 
                 +-- bin                  | 
                 |                        +-- index.html 
                 +-- conf                 
                 |                         
                 +-- logs
                 |
                 ... 
We'll go over this a little bit later in lab.

Do I Need to Become Server Manager?

Yes, there is such a role, and you can give it to yourself.

I'll go over this in class a bit later.

Essentially you modify tomcat-users.xml and give yourself a name and a password.

Then you have access to your servers contexts and can better administer your server.

What If I Still Have Problems?

Go see Adrian (dgerman@indiana.edu). He'll fix whatever you're struggling with.

Make appointment here or e-mail him for a (more) convenient time.

What Unix Commands Have Been Mentioned Above?

Here's a quick (and incomplete) list:

  • netstat
  • ps
  • grep
  • | (not really a command, the Unix pipe)
  • ls
  • pwd
  • hostname
  • whoami
  • clear
  • man
  • mkdir

I'll post links to where you can read about these.

What is the IU Knowledge Base?

A really cool thing originally started by IU CSCI grad student John Nienart.

What Now?

Take a break. Feel good. Listen to a song. (I like this one.)


Updated by © Adrian German for C212/A592 and H212 - Spring 2015