你怎么实现tomcat状态? 我做了
状态(){
ps -aef | grep tomcat | grep -v grep
}
它显示除了有效的tomcat进程以外的两个进程。 有没有更好的办法?
服务tomcat状态 根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 /服务tomcat状态 root 4625 4620 0 20:11 pts / 0 00:00:00 / bin / bash /etc/init.d/tomcat status
我的初始化脚本中有以下内容。 这不完美! 但是它确实可以在一个盒子上的单个Tomcat的情况下完成工作:
isRunning() { numproc=`ps -ef | grep "java" | grep "catalina" | grep -v "grep" | wc -l` if [ ${numproc} -gt 0 ]; then return 1 fi return 0 }
在启动时 – 您可以设置一个名为CATALINA_PID的环境variables,它应该是文件的名称。 tomcat启动脚本会注意到这个variables,并用pid创build一个文件。 那么你可以使用它来键入tomcat是否还活着。
状态(){
ps -fp`cat $ CATALINA_PID`
}
如果进程存在,ps也将退出0。 1,如果它不应该也更容易,更安全。