测试环境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


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值