Tomcat重启脚本

由于近期用jenkin发版的时候,发现其中重启tomcat发布服务功能总是不能正常生效,所以我想在jenkin中调用自己写的一段shell脚本来完成重启tomcat的工作

#!/bin/sh  
CURRENT_TIME=`date "+%Y%m%d%H%M%S"`
TOMCAT_HOME='/home/app/apache-tomcat-7.0.79'  
TOMCAT_WORK=${TOMCAT_HOME}'/work/' 
TOMCAT_WEBPACK=${TOMCAT_HOME}'/webapps/xxx-web*'  
TOMCAT_PATH=${TOMCAT_HOME}'/bin'  
TOMCAT_BACKUP=${TOMCAT_HOME}'/backup/'${CURRENT_TIME}

echo ===========rm tomcat work ================
`rm -rf ${TOMCAT_WORK}`  
echo 'operate restart tomcat: '$TOMCAT_PATH  

pid=`ps aux | grep $TOMCAT_PATH | grep -v grep | grep -v retomcat | awk '{print $2}'`  
echo 'exist pid:'$pid  

if [ -n "$pid" ]  
then  
{  
   echo ===========shutdown================
   `mkdir ${TOMCAT_BACKUP}; mv ${TOMCAT_WEBPACK} ${TOMCAT_BACKUP}`
   $TOMCAT_PATH'/shutdown.sh'  
   sleep 10  
   pid=`ps aux | grep $TOMCAT_PATH | grep -v grep | grep -v retomcat | 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_PATH'/startup.sh'  
 }  
else  
echo ===========startup.sh==============  
$TOMCAT_PATH'/startup.sh'  
  
fi

 

发表评论