Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

how do you implement tomcat status? I did

    ps -aef| grep tomcat |grep -v grep

it shows 2 more proccesses other than the valid tomcat process. is there a better way?

service tomcat status
root      4107     1  1 19:11 ?        00:00:47 /usr/java/latest/bin/java -Djava.util.logging.config.file=/usr/tomcat/conf/ -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/tomcat/endorsed -classpath /usr/tomcat/bin/bootstrap.jar -Dcatalina.base=/usr/tomcat -Dcatalina.home=/usr/tomcat org.apache.catalina.startup.Bootstrap start
root      4620  4376  0 20:11 pts/0    00:00:00 /bin/sh /sbin/service tomcat status
root      4625  4620  0 20:11 pts/0    00:00:00 /bin/bash /etc/init.d/tomcat status

share|improve this question
up vote 1 down vote accepted

I have the following in my init script. It's not perfect! But it does get the job done in the case of a single Tomcat on a box:

isRunning() {
numproc=`ps -ef | grep "java" | grep "catalina" | grep -v "grep" | wc -l`

if [ ${numproc} -gt 0 ]; then
    return 1

return 0
share|improve this answer
This works ok, I suppose I might just grep for something like "org.apache.catalina.startup.Bootstrap start" instead of grepping for java and then following that up with a grep for catalina. Also I usually try to avoid multiple return statements. I would save off the bool to a return var, and then return that just once. – Nathan Powell Feb 9 '11 at 1:50

On startup - you can set an environment variable called CATALINA_PID which should be the name of a file. The tomcat startup scripts will notice that variable and create a file with the pid. Then you can use that to key in on whether tomcat is alive.

    ps -fp `cat $CATALINA_PID`

ps will also exit 0 if the process exists. 1 if it does not which should also be and easier safer.

share|improve this answer
Is the extra "ps" redundant? – Corey S. Feb 9 '11 at 12:49
doh - I fixed the copy - tx – Tim Funk Feb 9 '11 at 13:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.