#!/bin/bash
Port="8080"
BaseDir=/opt/build/workspace/www.why.cn/svn/target/why/
ConfigDir=/opt/build/workspace/www.why.cn/svn/configs
>/root/scripts/info.log
>/tmp/outprint-${Port}.log
rsync -vzrtopgl --delete --exclude .svn $ConfigDir/log4j.properties /opt/tomcat-8080/webapps/why/WEB-INF/classes/log4j.properties
rsync -vzrtopgl --delete --exclude .svn $ConfigDir/pro.properties /opt/tomcat-8080/webapps/why/WEB-INF/classes/pro.properties
rsync -vzrtopgl --delete --exclude .svn $ConfigDir/jdbc.properties /opt/tomcat-8080/webapps/why/WEB-INF/classes/jdbc.properties
rsync -vzrtopgl --delete --exclude .svn $ConfigDir/web.xml /opt/tomcat-8080/webapps/why/WEB-INF/web.xml
rsync -vzrtopgl --delete --exclude .svn $ConfigDir/common.js /opt/tomcat-8080/webapps/why/STATIC/js/common.js
rsync -vzrtopgl --delete --exclude pro.properties --exclude jdbc.properties --exclude log4j.properties --exclude web.xml --exclude common.js ${BaseDir} /opt/tomcat-8080/webapps/why/
[ $? -ne 0 ] && {
rm -rf $BaseDir/*
echo "发布失败,请检查!!"
pkill tail
exit 2
}
/usr/sbin/tomcat-8080 restart;tail -f /opt/tomcat-8080/logs/catalina.out >>/tmp/outprint-${Port}.log &
times=0
while true;do
#定义通过curl命令获取网页状态码的个数
crul_num=`curl -Is http://192.168.5.116:8080/frontIndex/index.do --connect-timeout 5 -m 5|head -n1|awk '{print $2}'|wc -l`
#当返回值个数为0且经过20s时间后就判断此次发布失败,打开网页超时,直接退出。
[ ${crul_num} -eq 0 -a $times -eq 20 ] && {
echo "tomcat-${Port}: 项目已经发布,但网页打开超时,不能继续,请检查!!" >>/root/scripts/info.log
cat /root/scripts/info.log
echo -e "\n\n\n\n###################错误日志如下##################\n\n\n\n"
sleep 2
tail -n 500 /tmp/outprint-${Port}.log
pkill tail
exit 2
}
#定义了当获取网页状态码为0数的话就将时间增加1秒,直到上面的等于20就退出。
[ ${crul_num} -eq 0 ] && {
let times++
sleep 1
continue
}
#从上面可获知状态码个数不为0,现在定义状态码的值是否为200,不为200就直接退出.
crul_flags=`curl -Is http://192.168.5.116:8080/frontIndex/index.do|head -n1|awk '{print $2}'`
[ ${crul_flags} -ne 200 ]&&{
echo "tomcat-${Port}: 项目已经发布,但网页打开超时,不能继续,请检查!!" >>/root/scripts/info.log
cat /root/scripts/info.log
echo -e "\n\n\n\n###################错误日志如下##################\n\n\n\n"
sleep 2
tail -n 500 /tmp/outprint-${Port}.log
pkill tail
exit 3
}
#通过上面的判断,页面可以正常打开,发布正常,现将实例添加到nginx并重新加载。
echo "tomcat-${Port}: 发布成功!!" >>/root/scripts/info.log
break
done
#rm -rf $BaseDir/*
pkill tail
cat /root/scripts/info.log