shell学习脚本-tomcat停止脚本 原

#!/bin/bash
port=$1
tomcat=$2
tomcat_condition_code="$tomcat/bin/tomcat-juli.jar"
${tomcat}/bin/shutdown.sh 2>/dev/null
sleep 5

pids=`netstat -tlnp | grep "$port" | awk '{print $7}' | awk -F '/' '{print $1}'`
if [ ! $pids ]; then
  pids=`ps -ef | grep "$tomcat_condition_code" | grep -v grep | awk '{print $2}'`
fi

for pid in $pids

do
   if [ ${pid} -gt 0 ] 2>/dev/null ; then
         kill ${pid}
         sleep 2
         times = 0
         count=`ps -ax | awk '{ print $1 }' | grep -e "^${pid}$"`
         while [ ${count} == 1 ] 
         do
            sleep 1
            count=`ps -ax | awk '{ print $1 }' | grep -e "^${pid}$"`
            if [ ${count} == 0 ] ;then
            break
            fi
            ((times+=1))
            if [ ${times} -ge 10 ] ;then
               kill -9 ${pid}
               echo "force to stop tomcat"
               break
            fi
         done
   fi
done

echo "${tomcat} has been stoped"

 ./shutdown.sh 8080 /usr/local/apache-tomcat-7.0.70/

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区

领取腾讯云代金券