linux下tomcat无法关闭,【转】Linux下使用shutdown.sh脚本关闭tomcat无法使得JVM关闭

top

shift + m

查看发现,在tomcat关闭的情况下,有8条java进程在后台运行。产生的原因不明,只是之前做了tomcat内存设置:

JAVA_OPTS="-server -Xms256m -Xmx512m -Xss256K -XX:PermSize=128m -XX:MaxPermSize=256m"

原因慢慢再找

先记录下解决方案、

elif [ "$1" = "stop" ] ; then

shift

SLEEP=5

if [ ! -z "$1" ]; then

echo $1 | grep "[^0-9]" >/dev/null 2>&1

if [ $? -gt 0 ]; then

SLEEP=$1

shift

fi

fi

FORCE=0

if [ "$1" = "-force" ]; then

shift

FORCE=1

fi

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

eval "\"$_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

# stop failed. Shutdown port disabled? Try a normal kill.

if [ $? != 0 ]; then

if [ ! -z "$CATALINA_PID" ]; then

echo "The stop command failed. Attempting to signal the process to stop through OS signal."

kill -15 `cat "$CATALINA_PID"` >/dev/null 2>&1

fi

fi

if [ ! -z "$CATALINA_PID" ]; then

if [ -f "$CATALINA_PID" ]; then

while [ $SLEEP -ge 0 ]; do

kill -0 `cat "$CATALINA_PID"` >/dev/null 2>&1

if [ $? -gt 0 ]; then

rm -f "$CATALINA_PID" >/dev/null 2>&1

if [ $? != 0 ]; then

if [ -w "$CATALINA_PID" ]; then

cat /dev/null > "$CATALINA_PID"

# If Tomcat has stopped don't try and force a stop with an empty PID file

FORCE=0

else

echo "The PID file could not be removed or cleared."

fi

fi

echo "Tomcat stopped."

break

fi

if [ $SLEEP -gt 0 ]; then

sleep 1

fi

if [ $SLEEP -eq 0 ]; then

echo "Tomcat did not stop in time."

if [ $FORCE -eq 0 ]; then

echo "PID file was not removed."

fi

echo "To aid diagnostics a thread dump has been written to standard out."

kill -3 `cat "$CATALINA_PID"`

fi

SLEEP=`expr $SLEEP - 1 `

done

fi

fi

KILL_SLEEP_INTERVAL=5

if [ $FORCE -eq 1 ]; then

if [ -z "$CATALINA_PID" ]; then

echo "Kill failed: \$CATALINA_PID not set"

else

if [ -f "$CATALINA_PID" ]; then

PID=`cat "$CATALINA_PID"`

echo "Killing Tomcat with the PID: $PID"

kill -9 $PID

while [ $KILL_SLEEP_INTERVAL -ge 0 ]; do

kill -0 `cat "$CATALINA_PID"` >/dev/null 2>&1

if [ $? -gt 0 ]; then

rm -f "$CATALINA_PID" >/dev/null 2>&1

if [ $? != 0 ]; then

if [ -w "$CATALINA_PID" ]; then

cat /dev/null > "$CATALINA_PID"

else

echo "The PID file could not be removed."

fi

fi

echo "The Tomcat process has been killed."

break

fi

if [ $KILL_SLEEP_INTERVAL -gt 0 ]; then

sleep 1

fi

KILL_SLEEP_INTERVAL=`expr $KILL_SLEEP_INTERVAL - 1 `

done

if [ $KILL_SLEEP_INTERVAL -lt 0 ]; then

echo "Tomcat has not been killed completely yet. The process might be waiting on some system call or might be UNINTERRUPTIBLE."

fi

fi

fi

fi

# Add by afei on 2016-12-09 start

# find pid of /home/test/tomcat ,then kill force PIDS

echo "Force kill PIDS begin:"

ps -ef | grep /home/test/tomcat | grep -v grep | grep -v catalina.sh | awk '{print $2}' | xargs echo

ps -ef | grep /home/test/tomcat | grep -v grep | grep -v catalina.sh | awk '{print $2}' | xargs kill -9

echo "Force kill PIDS end!"

# Add by afei on 2016-12-09 end

elif [ "$1" = "configtest" ] ; then

通过

ps -ef | grep /home/test/tomcat | grep -v grep | grep -v catalina.sh |awk '{print $2}' | xargs kill -9

关键字匹配进程,然后通过 kill -9 杀掉

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值