Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

how do you implement tomcat status? I did

status(){
    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/logging.properties -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 -Djava.io.tmpdir=/usr/tomcat/temp 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

2 Answers 2

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
fi

return 0
}
share|improve this answer
1  
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.

status(){
    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

 
discard

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.