Tomcat – service tomcat status

tomcat

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

Best Answer

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
}
Related Topic