測試環境tomcat重啓腳本

測試環境的tomcat重啓和清除temp,work目錄以及logs目錄下的日誌是功能測試人員的一個很煩人的日常工作,即機械又耗時(重複次數多了之後)。所以寫了該腳本用於tomcat的重啓以及緩存、日誌目錄的清空,最後一步根據實際情況選擇是否打印catalina.out日誌以及是否需要修改時間爲制定時間。只需要配置tomcat_name變量爲需要執行操作的tomcat目錄即可。
該腳本也曾被用於我們的jenkins持續集成平臺中部署程序完成後的tomcat重啓

腳本見下:

#!/bin/sh
#
#2015-10-22
#andre.yang
#This script is used to commemorate my forever boss Pufan


tomcat_name=/home/tomcat_eomobi_S2S
tomcat_dir=`dirname $0`
if [ -d $tomcat_name'/temp/' ]


then


tempPath= $tomcat_name'/temp/'


else


tempPath=''


fi


workPath=$tomcat_name'/work/'
logPath=$tomcat_name'/logs/catalina.out'
delelogPath=$tomcat_name'/logs/'


pid0=`ps -ef|grep "java"|grep $tomcat_name|awk '{print $2}'`


#if tomcat is not run ,start it
if [ "$pid0" = "" ] 


then


{


echo "tomcat is not run"


if [ -d "$tempPath" ]


then


rm -rf "$tempPath"


echo "**********************dele temp ******************"


fi


if [ -d "$tempPath"  ]


then


echo "**********************dele temp faild******************"


else


echo "**********************dele temp success******************"


fi


if [ -d "$workPath" ]


then


echo "**********************dele work******************"


rm -rf "$workPath"


fi


if [ -d "$workPath" ]


then


echo "**********************dele work faild******************"


else


echo "**********************dele work success****************"


fi


echo "**********************start tomcat******************"


echo -n "chance date :  "


read date


sudo date -s $date


cd $tomcat_name


./bin/startup.sh


sleep 2
#print log
echo -n "is or not print log:y/n:  "


read return


if [ $return = y ] 


then


tail -f $logPath -n -500


else


echo "**********************tomcat restart success********************"


fi


}


else


{
#print pid and shutdown tomcat
echo pid is $pid0 


ps -ef|grep $tomcat_name|grep -v grep|cut -c 9-15|xargs kill -9


#check tomcat's status and return result
pid1=`ps -ef|grep "java"|grep $tomcat_name|awk '{print $2}'`


if [ "$pid1" = "" ] 


then


echo "kill sucess!"


if [ -d "$tempPath" ]


then


rm -rf "$tempPath"


echo "**********************dele temp ******************"


fi


if [ -d "$tempPath"  ]


then


echo "**********************dele temp faild******************"


else


echo "**********************dele temp success******************"


fi




if [ -d "$workPath" ]


then


rm -rf "$workPath"


echo "**********************dele work ******************"


fi


if [ -d "$workPath" ]


then


echo "**********************dele work faild******************"


else


echo "**********************dele work success****************"


fi


cd $tomcat_dir
#check temp's dir and delte it


echo -n "chanle date :  "


read date


sudo date -s $date






cd $tomcat_name


./bin/startup.sh


else
{


echo pid is $pid1 
echo "kill faild";


}


fi


sleep 2
#print log
echo -n "is or not print log:y/n:  "


read return


if [ $return = y ] 


then


tail -f $logPath -n -500


else


echo "**********************tomcat restart success********************"


fi
}


fi


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章