Tomcat: What Can Go Wrong? Is Your Server Up? The answer to this question can be found with this Unix command: In this example we see Dimas's server is up, but Krista's isn't.-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$ 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
It is the number to the left of
Connor's server has a process ID of 17410. Who's Connor?-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$ How Do You Stop Your Server?-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$ If all is set properly the command is: Then check (as above) to convince yourself it went away.$CATALINA_HOME/bin/shutdown.sh 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: The command above would try to stop Dimas's server process.kill 7348 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 How Could That Even Happen? (What Not To Do.)kill -9 7348 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:
As a reminder, NEVER try to start the server if it's already running. How Do You Restart Your Server? To restart the server:
What If Something (Else) Goes Wrong? The server writes a number of log files in If something goes wrong it's going to be documented in real time in one of those files.$CATALINA_HOME/logs 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:
Here's how it works for me:netstat -a | grep 8346 You see that-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$ 8346 is not available (I am using it).
Also ports
Port
But we see that port 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 Where Is My Server's Home Page? Your server's original homepage is at: You may or may not be able to change this page (also it's very complicated). We will discuss that later.$CATALINA_HOME/webapps/ROOT/index.jsp What we did in lab was to define a (new) file: This file did not exist at first but once we create it it becomes the default home page.$CATALINA_HOME/webapps/ROOT/index.html Is There a Map of All Server's Files? Absolutely, we described that at the end of the lab. Here's another map:
We'll go over this a little bit later in lab.$CATALINA_HOME --+-- webapps --+-- squash --+-- WEB-INF --+-- classes --+-- One.java | | | | | | | +-- lib | | | | | | | +--- web.xml | | | | | +-- one.html | | | | | +-- index.html | | | +-- ROOT --+-- WEB-INF ... +-- bin | | +-- index.html +-- conf | +-- logs | ... 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 Then you have access to your servers contexts and can better administer your server. What If I Still Have Problems?
Go see Adrian (
Make appointment What Unix Commands Have Been Mentioned Above? Here's a quick (and incomplete) list:
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 |