TOMCAT 关闭报错:Tomcat did not stop in time. PID file was not removed
作者:互联网
背景:执行/shutdown.sh偶尔会报错如下,但是大部分时间还是比较正常的,希望能解决掉它
1,报错信息如下:
[root@ptbin]# ./shutdown.sh
Using CATALINA_BASE: /usr/local/app/apache-tomcat-6.0.37_9300
Using CATALINA_HOME: /usr/local/app/apache-tomcat-6.0.37_9300
Using CATALINA_TMPDIR: /usr/local/app/apache-tomcat-6.0.37_9300/temp
Using JRE_HOME: /usr/lib/jvm/java
Using CLASSPATH: /usr/local/app/apache-tomcat-6.0.37_9300/bin/bootstrap.jar
Using CATALINA_PID: /var/tomcat/9300.pid
Jun 12, 2015 4:55:30 PM org.apache.catalina.startup.Catalina stopServer
SEVERE: Catalina.stop:
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:208)
at org.apache.catalina.startup.Catalina.stopServer(Catalina.java:422)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.catalina.startup.Bootstrap.stopServer(Bootstrap.java:338)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:416)
Tomcat did not stop in time. PID file was not removed.
[root@ptbin]#
<版权所有,文章允许转载,但必须以链接方式注明源地址,否则追究法律责任!>
原博客地址: http://blog.csdn.net/mchdba/article/details/46482499
原作者:黄杉 (mchdba)
2,去看下pid是否存在:
[root@pt~]# ll /var/tomcat/
total 12
-rw-r–r--. 1 root root 5 Jun 12 15:41 9300.pid
[root@pt~]#
tomcat的pid确实存在,与这个pid无关
3,解决办法:
解决办法有多种
3.1 解决办法1:修改java项目的实现方式
可能项目中用到了ScheduledThreadPoolExecutor(可能是未接受stop消息导致的),导致了shutdown命令未能成功。将ScheduledThreadPoolExecutor改成spring的quartz调度就ok了。
3.2 解决办法2,加上-force强行stop掉
在catalina.sh里面
exec “PRGDIR"/"EXECUTABLE” stop -force “$@”
大家查看shutdown.sh的代码:
[root@ptbin]# vim shutdown.sh
PRG="$0"
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`/"$link"
fi
done
PRGDIR=`dirname "$PRG"`
EXECUTABLE=catalina.sh
# Check that target executable exists
if [ ! -x "$PRGDIR"/"$EXECUTABLE" ]; then
echo "Cannot find $PRGDIR/$EXECUTABLE"
echo "The file is absent or does not have execute permission"
echo "This file is needed to run this program"
exit 1
fi
exec "$PRGDIR"/"$EXECUTABLE" stop "$@"
发现并没有echo "Tomcat did not stop in time. PID file was not removed.“的提示信息,那么报错信息肯定不是在shutdown.sh脚本里面,大家看到shutdown.sh最后有引用其它脚本exec "$PRGDIR"/"$EXECUTABLE" stop "$@"来关闭tomcat
,再看到”$EXECUTABLE变量所指向的是catalina.sh,所以问题核心是在catalina.sh里面。
打开catalina.sh发现只有第453行里面有这样提示信息,如下:
433 if [ ! -z "$CATALINA_PID" ]; then
434 if [ -f "$CATALINA_PID" ]; then
435 while [ $SLEEP -ge 0 ]; do
436 kill -0 `cat "$CATALINA_PID"` >/dev/null 2>&1
437 if [ $? -gt 0 ]; then
438 rm -f "$CATALINA_PID" >/dev/null 2>&1
439 if [ $? != 0 ]; then
440 if [ -w "$CATALINA_PID" ]; then
441 cat /dev/null > "$CATALINA_PID"
442 else
443 echo "Tomcat stopped but the PID file could not be removed or cleared."
444 fi
445 fi
446 break
447 fi
448 if [ $SLEEP -gt 0 ]; then
449 sleep 1
450 fi
451 if [ $SLEEP -eq 0 ]; then
452 if [ $FORCE -eq 0 ]; then
453 echo "Tomcat did not stop in time. PID file was not removed."
454 fi
455 fi
456 SLEEP=`expr $SLEEP - 1 `
457 done
458 fi
看到关键代码判断 if [ $FORCE -eq 0 ]; 那么这里就是表明前面执行异常,但是不是force强行停止掉,所以要抛一个exception出来,告诉你没有stop成功。
那么,我们可以在这里设置一个force命令来让tomcat强行stop掉。
[root@ptbin]# vim shutdown.sh
exec "$PRGDIR"/"$EXECUTABLE" stop "$@"
#改成如下
exec "$PRGDIR"/"$EXECUTABLE" stop -force "$@"
#然后再执行shutdown.sh操作,ok,就不会报错,正常执行完毕了。
查看执行结果如下:
[root@ptbin]# ./shutdown.sh
Using CATALINA_BASE: /usr/local/app/apache-tomcat-6.0.37_9300
Using CATALINA_HOME: /usr/local/app/apache-tomcat-6.0.37_9300
Using CATALINA_TMPDIR: /usr/local/app/apache-tomcat-6.0.37_9300/temp
Using JRE_HOME: /usr/lib/jvm/java
Using CLASSPATH: /usr/local/app/apache-tomcat-6.0.37_9300/bin/bootstrap.jar
Using CATALINA_PID: /var/tomcat/9300.pid
[root@ptbin]#
3.3 通过bash -x分析真正的原因
3.3.1 先查看执行报错的时候的bash过程
[root@ptbin]# bash -x catalina.sh stop
+ JAVA_OPTS='-Xms512m -Xmx1024m -Xss1024K -XX:PermSize=256m -XX:MaxPermSize=512m -XX:+PrintGCDetails -Xloggc:/logs/gc/9300.gc'
+ CATALINA_PID=/var/tomcat/9300.pid
+ cygwin=false
+ os400=false
+ darwin=false
+ case "`uname`" in
++ uname
+ PRG=catalina.sh
+ '[' -h catalina.sh ']'
++ dirname catalina.sh
+ PRGDIR=.
+ '[' -z '' ']'
++ cd ./..
++ pwd
+ CATALINA_HOME=/usr/local/app/apache-tomcat-6.0.37_9300
+ '[' -z '' ']'
+ CATALINA_BASE=/usr/local/app/apache-tomcat-6.0.37_9300
+ CLASSPATH=
+ '[' -r /usr/local/app/apache-tomcat-6.0.37_9300/bin/setenv.sh ']'
+ '[' -r /usr/local/app/apache-tomcat-6.0.37_9300/bin/setenv.sh ']'
+ false
+ false
+ false
+ '[' -r /usr/local/app/apache-tomcat-6.0.37_9300/bin/setclasspath.sh ']'
+ BASEDIR=/usr/local/app/apache-tomcat-6.0.37_9300
+ . /usr/local/app/apache-tomcat-6.0.37_9300/bin/setclasspath.sh
++ '[' -z /usr/lib/jvm/java -a -z '' ']'
++ '[' -z /usr/lib/jvm/java -a stop = debug ']'
++ '[' -z '' ']'
++ JRE_HOME=/usr/lib/jvm/java
++ '[' stop = debug ']'
++ '[' -z /usr/local/app/apache-tomcat-6.0.37_9300 ']'
++ '[' '!' -x /usr/local/app/apache-tomcat-6.0.37_9300/bin/setclasspath.sh ']'
++ '[' -z '' ']'
++ JAVA_ENDORSED_DIRS=/usr/local/app/apache-tomcat-6.0.37_9300/endorsed
++ JIKESPATH=
+++ uname -s
++ '[' Linux = Darwin ']'
++ _RUNJAVA=/usr/lib/jvm/java/bin/java
++ '[' false '!=' true ']'
++ _RUNJDB=/usr/lib/jvm/java/bin/jdb
+ '[' -z /usr/local/app/apache-tomcat-6.0.37_9300 ']'
+ '[' '!' -z '' ']'
+ '[' /usr/local/app/apache-tomcat-6.0.37_9300 '!=' /usr/local/app/apache-tomcat-6.0.37_9300 ']'
+ CLASSPATH=/usr/local/app/apache-tomcat-6.0.37_9300/bin/bootstrap.jar
+ '[' -z '' ']'
+ CATALINA_OUT=/usr/local/app/apache-tomcat-6.0.37_9300/logs/catalina.out
+ '[' -z '' ']'
+ CATALINA_TMPDIR=/usr/local/app/apache-tomcat-6.0.37_9300/temp
+ have_tty=0
++ tty
+ '[' /dev/pts/1 '!=' 'not a tty' ']'
+ have_tty=1
+ false
+ '[' -z '' ']'
+ '[' -r /usr/local/app/apache-tomcat-6.0.37_9300/conf/logging.properties ']'
+ LOGGING_CONFIG=-Djava.util.logging.config.file=/usr/local/app/apache-tomcat-6.0.37_9300/conf/logging.properties
+ '[' -z '' ']'
+ LOGGING_MANAGER=-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
+ '[' 1 -eq 1 ']'
+ echo 'Using CATALINA_BASE: /usr/local/app/apache-tomcat-6.0.37_9300'
Using CATALINA_BASE: /usr/local/app/apache-tomcat-6.0.37_9300
+ echo 'Using CATALINA_HOME: /usr/local/app/apache-tomcat-6.0.37_9300'
Using CATALINA_HOME: /usr/local/app/apache-tomcat-6.0.37_9300
+ echo 'Using CATALINA_TMPDIR: /usr/local/app/apache-tomcat-6.0.37_9300/temp'
Using CATALINA_TMPDIR: /usr/local/app/apache-tomcat-6.0.37_9300/temp
+ '[' stop = debug ']'
+ echo 'Using JRE_HOME: /usr/lib/jvm/java'
Using JRE_HOME: /usr/lib/jvm/java
+ echo 'Using CLASSPATH: /usr/local/app/apache-tomcat-6.0.37_9300/bin/bootstrap.jar'
Using CLASSPATH: /usr/local/app/apache-tomcat-6.0.37_9300/bin/bootstrap.jar
+ '[' '!' -z /var/tomcat/9300.pid ']'
+ echo 'Using CATALINA_PID: /var/tomcat/9300.pid'
Using CATALINA_PID: /var/tomcat/9300.pid
+ '[' stop = jpda ']'
+ '[' stop = debug ']'
+ '[' stop = run ']'
+ '[' stop = start ']'
+ '[' stop = stop ']'
+ shift
+ SLEEP=5
+ '[' '!' -z '' ']'
+ FORCE=0
+ '[' '' = -force ']'
+ '[' '!' -z /var/tomcat/9300.pid ']'
+ '[' -f /var/tomcat/9300.pid ']'
+ '[' -s /var/tomcat/9300.pid ']'
++ cat /var/tomcat/9300.pid
+ kill -0 23430
+ '[' 0 -gt 0 ']'
+ echo 0000002
0000002
+ /usr/lib/jvm/java/bin/java -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms512m -Xmx1024m -Xss1024K -XX:PermSize=256m -XX:MaxPermSize=512m -XX:+PrintGCDetails -Xloggc:/logs/gc/9300.gc -Djava.endorsed.dirs=/usr/local/app/apache-tomcat-6.0.37_9300/endorsed -classpath /usr/local/app/apache-tomcat-6.0.37_9300/bin/bootstrap.jar -Dcatalina.base=/usr/local/app/apache-tomcat-6.0.37_9300 -Dcatalina.home=/usr/local/app/apache-tomcat-6.0.37_9300 -Djava.io.tmpdir=/usr/local/app/apache-tomcat-6.0.37_9300/temp org.apache.catalina.startup.Bootstrap stop
Jun 13, 2015 9:27:51 AM org.apache.catalina.startup.Catalina stopServer
SEVERE: Catalina.stop:
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:208)
at org.apache.catalina.startup.Catalina.stopServer(Catalina.java:422)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.catalina.startup.Bootstrap.stopServer(Bootstrap.java:338)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:416)
+ echo 0000003
0000003
+ '[' '!' -z /var/tomcat/9300.pid ']'
+ echo CATALINA_PID:/var/tomcat/9300.pid
CATALINA_PID:/var/tomcat/9300.pid
+ '[' -f /var/tomcat/9300.pid ']'
+ '[' 5 -ge 0 ']'
++ cat /var/tomcat/9300.pid
+ kill -0 23430
+ '[' 0 -gt 0 ']'
+ '[' 5 -gt 0 ']'
+ sleep 1
+ '[' 5 -eq 0 ']'
++ expr 5 - 1
+ SLEEP=4
+ '[' 4 -ge 0 ']'
++ cat /var/tomcat/9300.pid
+ kill -0 23430
+ '[' 0 -gt 0 ']'
+ '[' 4 -gt 0 ']'
+ sleep 1
+ '[' 4 -eq 0 ']'
++ expr 4 - 1
+ SLEEP=3
+ '[' 3 -ge 0 ']'
++ cat /var/tomcat/9300.pid
+ kill -0 23430
+ '[' 0 -gt 0 ']'
+ '[' 3 -gt 0 ']'
+ sleep 1
+ '[' 3 -eq 0 ']'
++ expr 3 - 1
+ SLEEP=2
+ '[' 2 -ge 0 ']'
++ cat /var/tomcat/9300.pid
+ kill -0 23430
+ '[' 0 -gt 0 ']'
+ '[' 2 -gt 0 ']'
+ sleep 1
+ '[' 2 -eq 0 ']'
++ expr 2 - 1
+ SLEEP=1
+ '[' 1 -ge 0 ']'
++ cat /var/tomcat/9300.pid
+ kill -0 23430
+ '[' 0 -gt 0 ']'
+ '[' 1 -gt 0 ']'
+ sleep 1
+ '[' 1 -eq 0 ']'
++ expr 1 - 1
+ SLEEP=0
+ '[' 0 -ge 0 ']'
++ cat /var/tomcat/9300.pid
+ kill -0 23430
+ '[' 0 -gt 0 ']'
+ '[' 0 -gt 0 ']'
+ '[' 0 -eq 0 ']'
+ '[' 0 -eq 0 ']'
+ echo 'Tomcat did not stop in time. PID file was not removed.'
Tomcat did not stop in time. PID file was not removed.
++ expr 0 - 1
+ SLEEP=-1
+ '[' -1 -ge 0 ']'
+ '[' 0 -eq 1 ']'
[root@ptbin]#
通过设置echo提示信息,找到报错执行语句,大家看到报错的真正原因是在于执行这一句:
/usr/lib/jvm/java/bin/java -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms512m -Xmx1024m -Xss1024K -XX:PermSize=256m -XX:MaxPermSize=512m -XX:+PrintGCDetails -Xloggc:/logs/gc/9300.gc -Djava.endorsed.dirs=/usr/local/app/apache-tomcat-6.0.37_9300/endorsed -classpath /usr/local/app/apache-tomcat-6.0.37_9300/bin/bootstrap.jar -Dcatalina.base=/usr/local/app/apache-tomcat-6.0.37_9300 -Dcatalina.home=/usr/local/app/apache-tomcat-6.0.37_9300 -Djava.io.tmpdir=/usr/local/app/apache-tomcat-6.0.37_9300/temp org.apache.catalina.startup.Bootstrap stop后报错。
对于catalina.sh里面的就是这一句:
echo "0000002"
"$_RUNJAVA" $LOGGING_MANAGER $JAVA_OPTS \
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
-Dcatalina.base="$CATALINA_BASE" \
-Dcatalina.home="$CATALINA_HOME" \
-Djava.io.tmpdir="$CATALINA_TMPDIR" \
org.apache.catalina.startup.Bootstrap "$@" stop
echo "0000003"
3.3.2 再次等5分钟,再bash -x看执行详细过程:
[root@ptbin]# bash -x catalina.sh stop
+ JAVA_OPTS='-Xms512m -Xmx1024m -Xss1024K -XX:PermSize=256m -XX:MaxPermSize=512m -XX:+PrintGCDetails -Xloggc:/logs/gc/9300.gc'
+ CATALINA_PID=/var/tomcat/9300.pid
+ cygwin=false
+ os400=false
+ darwin=false
+ case "`uname`" in
++ uname
+ PRG=catalina.sh
+ '[' -h catalina.sh ']'
++ dirname catalina.sh
+ PRGDIR=.
+ '[' -z '' ']'
++ cd ./..
++ pwd
+ CATALINA_HOME=/usr/local/app/apache-tomcat-6.0.37_9300
+ '[' -z '' ']'
+ CATALINA_BASE=/usr/local/app/apache-tomcat-6.0.37_9300
+ CLASSPATH=
+ '[' -r /usr/local/app/apache-tomcat-6.0.37_9300/bin/setenv.sh ']'
+ '[' -r /usr/local/app/apache-tomcat-6.0.37_9300/bin/setenv.sh ']'
+ false
+ false
+ false
+ '[' -r /usr/local/app/apache-tomcat-6.0.37_9300/bin/setclasspath.sh ']'
+ BASEDIR=/usr/local/app/apache-tomcat-6.0.37_9300
+ . /usr/local/app/apache-tomcat-6.0.37_9300/bin/setclasspath.sh
++ '[' -z /usr/lib/jvm/java -a -z '' ']'
++ '[' -z /usr/lib/jvm/java -a stop = debug ']'
++ '[' -z '' ']'
++ JRE_HOME=/usr/lib/jvm/java
++ '[' stop = debug ']'
++ '[' -z /usr/local/app/apache-tomcat-6.0.37_9300 ']'
++ '[' '!' -x /usr/local/app/apache-tomcat-6.0.37_9300/bin/setclasspath.sh ']'
++ '[' -z '' ']'
++ JAVA_ENDORSED_DIRS=/usr/local/app/apache-tomcat-6.0.37_9300/endorsed
++ JIKESPATH=
+++ uname -s
++ '[' Linux = Darwin ']'
++ _RUNJAVA=/usr/lib/jvm/java/bin/java
++ '[' false '!=' true ']'
++ _RUNJDB=/usr/lib/jvm/java/bin/jdb
+ '[' -z /usr/local/app/apache-tomcat-6.0.37_9300 ']'
+ '[' '!' -z '' ']'
+ '[' /usr/local/app/apache-tomcat-6.0.37_9300 '!=' /usr/local/app/apache-tomcat-6.0.37_9300 ']'
+ CLASSPATH=/usr/local/app/apache-tomcat-6.0.37_9300/bin/bootstrap.jar
+ '[' -z '' ']'
+ CATALINA_OUT=/usr/local/app/apache-tomcat-6.0.37_9300/logs/catalina.out
+ '[' -z '' ']'
+ CATALINA_TMPDIR=/usr/local/app/apache-tomcat-6.0.37_9300/temp
+ have_tty=0
++ tty
+ '[' /dev/pts/1 '!=' 'not a tty' ']'
+ have_tty=1
+ false
+ '[' -z '' ']'
+ '[' -r /usr/local/app/apache-tomcat-6.0.37_9300/conf/logging.properties ']'
+ LOGGING_CONFIG=-Djava.util.logging.config.file=/usr/local/app/apache-tomcat-6.0.37_9300/conf/logging.properties
+ '[' -z '' ']'
+ LOGGING_MANAGER=-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
+ '[' 1 -eq 1 ']'
+ echo 'Using CATALINA_BASE: /usr/local/app/apache-tomcat-6.0.37_9300'
Using CATALINA_BASE: /usr/local/app/apache-tomcat-6.0.37_9300
+ echo 'Using CATALINA_HOME: /usr/local/app/apache-tomcat-6.0.37_9300'
Using CATALINA_HOME: /usr/local/app/apache-tomcat-6.0.37_9300
+ echo 'Using CATALINA_TMPDIR: /usr/local/app/apache-tomcat-6.0.37_9300/temp'
Using CATALINA_TMPDIR: /usr/local/app/apache-tomcat-6.0.37_9300/temp
+ '[' stop = debug ']'
+ echo 'Using JRE_HOME: /usr/lib/jvm/java'
Using JRE_HOME: /usr/lib/jvm/java
+ echo 'Using CLASSPATH: /usr/local/app/apache-tomcat-6.0.37_9300/bin/bootstrap.jar'
Using CLASSPATH: /usr/local/app/apache-tomcat-6.0.37_9300/bin/bootstrap.jar
+ '[' '!' -z /var/tomcat/9300.pid ']'
+ echo 'Using CATALINA_PID: /var/tomcat/9300.pid'
Using CATALINA_PID: /var/tomcat/9300.pid
+ '[' stop = jpda ']'
+ '[' stop = debug ']'
+ '[' stop = run ']'
+ '[' stop = start ']'
+ '[' stop = stop ']'
+ shift
+ SLEEP=5
+ '[' '!' -z '' ']'
+ FORCE=0
+ '[' '' = -force ']'
+ '[' '!' -z /var/tomcat/9300.pid ']'
+ '[' -f /var/tomcat/9300.pid ']'
+ '[' -s /var/tomcat/9300.pid ']'
++ cat /var/tomcat/9300.pid
+ kill -0 23685
+ '[' 0 -gt 0 ']'
+ echo 0000002
0000002
+ /usr/lib/jvm/java/bin/java -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms512m -Xmx1024m -Xss1024K -XX:PermSize=256m -XX:MaxPermSize=512m -XX:+PrintGCDetails -Xloggc:/logs/gc/9300.gc -Djava.endorsed.dirs=/usr/local/app/apache-tomcat-6.0.37_9300/endorsed -classpath /usr/local/app/apache-tomcat-6.0.37_9300/bin/bootstrap.jar -Dcatalina.base=/usr/local/app/apache-tomcat-6.0.37_9300 -Dcatalina.home=/usr/local/app/apache-tomcat-6.0.37_9300 -Djava.io.tmpdir=/usr/local/app/apache-tomcat-6.0.37_9300/temp org.apache.catalina.startup.Bootstrap stop
+ echo 0000003
0000003
+ '[' '!' -z /var/tomcat/9300.pid ']'
+ echo CATALINA_PID:/var/tomcat/9300.pid
CATALINA_PID:/var/tomcat/9300.pid
+ '[' -f /var/tomcat/9300.pid ']'
+ '[' 5 -ge 0 ']'
++ cat /var/tomcat/9300.pid
+ kill -0 23685
+ '[' 0 -gt 0 ']'
+ '[' 5 -gt 0 ']'
+ sleep 1
+ '[' 5 -eq 0 ']'
++ expr 5 - 1
+ SLEEP=4
+ '[' 4 -ge 0 ']'
++ cat /var/tomcat/9300.pid
+ kill -0 23685
+ '[' 0 -gt 0 ']'
+ '[' 4 -gt 0 ']'
+ sleep 1
+ '[' 4 -eq 0 ']'
++ expr 4 - 1
+ SLEEP=3
+ '[' 3 -ge 0 ']'
++ cat /var/tomcat/9300.pid
+ kill -0 23685
+ '[' 0 -gt 0 ']'
+ '[' 3 -gt 0 ']'
+ sleep 1
+ '[' 3 -eq 0 ']'
++ expr 3 - 1
+ SLEEP=2
+ '[' 2 -ge 0 ']'
++ cat /var/tomcat/9300.pid
+ kill -0 23685
+ '[' 0 -gt 0 ']'
+ '[' 2 -gt 0 ']'
+ sleep 1
+ '[' 2 -eq 0 ']'
++ expr 2 - 1
+ SLEEP=1
+ '[' 1 -ge 0 ']'
++ cat /var/tomcat/9300.pid
+ kill -0 23685
+ '[' 1 -gt 0 ']'
+ rm -f /var/tomcat/9300.pid
+ '[' 0 '!=' 0 ']'
+ break
+ '[' 0 -eq 1 ']'
对比下3.3.1代码报错的代码以及bash执行结果命令,
"$_RUNJAVA" $LOGGING_MANAGER $JAVA_OPTS \
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
-Dcatalina.base="$CATALINA_BASE" \
-Dcatalina.home="$CATALINA_HOME" \
-Djava.io.tmpdir="$CATALINA_TMPDIR" \
org.apache.catalina.startup.Bootstrap "$@" stop
的执行结果都是一样的,没有差别,所以就是说问题在于执行catalina.sh stop的时机问题,那么这个时机不对,就会造成stop失败。在经过几次测试后,发现在以下几种情况会造成tomcat类似的错误:
(1)是由于tomcat还没有启动完成的时候,你去执行shutdown.sh会报错,这个时候不允许stop,会报错。
(2)当tomcat上的web工程正在执行一项任务的时候,tomcat会等待不允许你stop也会保错的。
(3)其它未知原因。
4,解决办法
4.1 加上-force参数,再启动后关闭,就不会报错
[root@ptbin]# ./shutdown.sh
Using CATALINA_BASE: /usr/local/app/apache-tomcat-6.0.37_9300
Using CATALINA_HOME: /usr/local/app/apache-tomcat-6.0.37_9300
Using CATALINA_TMPDIR: /usr/local/app/apache-tomcat-6.0.37_9300/temp
Using JRE_HOME: /usr/lib/jvm/java
Using CLASSPATH: /usr/local/app/apache-tomcat-6.0.37_9300/bin/bootstrap.jar
Using CATALINA_PID: /var/tomcat/9300.pid
[root@ptbin]#
4.2 等待一会再shutdown.sh等tomcat里面web工程执行完的时候,没有新请求了,shutdown就ok了。
[root@ptbin]# ./shutdown.sh
Using CATALINA_BASE: /usr/local/app/apache-tomcat-6.0.37_9300
Using CATALINA_HOME: /usr/local/app/apache-tomcat-6.0.37_9300
Using CATALINA_TMPDIR: /usr/local/app/apache-tomcat-6.0.37_9300/temp
Using JRE_HOME: /usr/lib/jvm/java
Using CLASSPATH: /usr/local/app/apache-tomcat-6.0.37_9300/bin/bootstrap.jar
Using CATALINA_PID: /var/tomcat/9300.pid
[root@ptbin]#
标签:Tomcat,tomcat,app,37,报错,usr,file,apache,9300 来源: https://blog.csdn.net/csdnhsh/article/details/94232305