tomcat重启脚本

脚本如下(带参数):

注意bash变量赋值左右不能有空格

#!/bin/sh

# 定义tomcat目录和appname
tomcat_dir=$1
app_name=$2

# 删除app目录
`rm -rf $tomcat_dir/webapps/$app_name
`
# 执行重启
pid=`ps aux | grep $tomcat_dir | grep -v grep | grep -v $0 | awk '{print $2}'`
echo 'exist pid:'$pid

if [ -n "$pid" ]
then
{
   echo ===========shutdown================
   $tomcat_dir'/bin/shutdown.sh'
   sleep 2
   pid=`ps aux | grep $tomcat_dir | grep -v grep | grep -v $0 | awk '{print $2}'`
   if [ -n "$pid" ]
   then
    {
      sleep 2
      echo ========kill tomcat begin==============
      echo $pid
      kill -9 $pid
      echo ========kill tomcat end==============
    }
   fi
   sleep 2
   echo ===========startup.sh==============
   $tomcat_dir'/bin/startup.sh'
 }
else
echo ===========startup.sh==============
$tomcat_dir'/bin/startup.sh'
fi

另一个版本:

#!/bin/bash


stop() {
sh /apps/tomcat/apache-tomcat/bin/shutdown.sh

sleep 3
NAME='java'
echo $NAME
ID=`ps -ef | grep "$NAME" | grep tomcat| grep -v "$0" | grep -v "grep" | awk '{print $2}'`
echo $ID
echo "---------------"
for id in $ID
do
kill -9 $id
echo "killed $id"
done
echo "---------------"


}

start() {


sh /apps/tomcat/apache-tomcat/bin/startup.sh


}


case $1 in

start|stop)
$1

;;
restart)

stop
start
;;

*)

echo "start|stop|restart!"
;;
esac

 

参考:

https://blog.csdn.net/SJZYLC/article/details/45030265

posted @ 2022-01-24 18:16  豆浆D  阅读(167)  评论(0编辑  收藏  举报