Tomcat进程无法正常stop问题
CentOS使用Catalina.sh 来管理Tomcat运行时,Catalina.sh run 之后产生的tomcat进程会无法使用 Catalina.sh stop -force关闭。如果Catalina.sh的默认内容来配置tomcat服务,/etc/init.d/tomcat stop 也将会失效
查看Catalina.sh文件后找到以下代码,原来需要stop的话,需要CATALINA_PID文件配合。
Catalina.sh 468行
if [ ! -z "$CATALINA_PID" ]; then if [ -f "$CATALINA_PID" ]; then if [ -s "$CATALINA_PID" ]; then kill -0 `cat "$CATALINA_PID"` >/dev/null 2>&1 if [ $? -gt 0 ]; then echo "PID file found but no matching process was found. Stop aborted." exit 1 fi else echo "PID file is empty and has been ignored." fi else echo "\$CATALINA_PID was set but the specified file does not exist. Is Tomcat running? Stop aborted." exit 1 fi fi |
CATALINA_PID的说明内容
Catalina.sh 89行
# CATALINA_PID (Optional) Path of the file which should contains the pid # of the catalina startup java process, when start (fork) is # used |
解决办法就是,在配置Catalina.sh的环境变量时添加 CATALINA_PID 变量
#创建pid文件 touch /usr/local/tomcat/logs/tomcat.pid # 在/etc/init.d/tomcat头部增加环境变量配置 sed -i '1a\. /etc/init.d/functions' /etc/init.d/tomcat sed -i '2a\:' /etc/init.d/tomcat sed -i '3a\JAVA_HOME=/usr/local/jdk' /etc/init.d/tomcat sed -i '4a\CATALINA_BASE=/usr/local/tomcat' /etc/init.d/tomcat sed -i '5a\CATALINA_HOME=/usr/local/tomcat' /etc/init.d/tomcat # 添加PID文件位置 sed -i ‘6a\CATALINA_PID=/usr/local/tomcat/logs/tomcat.pid' /etc/init.d/tomcat |
最后
使用Catalina.sh方式单独运行tomcat时,建议在$CATALINA_HOME/bin下新建setenv.sh方式实现
参考
http://lovesoo.org/tomcat-process-fails-to-stop-problem-solving.html
Recent Comments