研究了一下午,写这个脚本。这里做个备份。
#!/bin/bash#functionsfunction mavenProject(){ echo "maven 开始编译项目"; mvn clean package -Dmaven.test.skip=true;}function startTomcat(){ local DATE=`date '+%Y-%m-%d-%H-%M-%S'` local DIR="/data/www/logisticscenter" rm -rf ${DIR}/logs/* rm -rf ${DIR}/work/* rm -rf ${DIR}/temp/* rm -rf ${DIR}/conf/Catalina/ mv ${DIR}/meizu_web/logisticscenter.war ${DIR}/backup/logisticscenter.${DATE}.war; cp /data/work/logisticscenter/web/target/logisticscenter.web*.war ${DIR}/meizu_web/logisticscenter.war; if [ ! $? ];then echo "maven编译失败,请查看 maven日志做处理"; exit; fi; ${DIR}/bin/startup.sh; echo "等待20秒"; sleep 20s; local SuccInfo=`grep '信息: Server startup in' ${DIR}/logs/catalina.out | sed -n '1p'` if [ -n "${SuccInfo}" ];then echo "tomcat 启动成功"; else echo "tomcat 启动失败,请检查 tomcat配置或者 maven 编译失败"; fi;}#executemavenProject;PidNum=`ps -ef | grep logisticscenter | wc -l`;if [ ${PidNum} -eq 1 ];then echo "tomcat 已关闭";else PID=`ps -ef | grep logisticscenter | sed -n '1p' | awk -F " " '{print $2}'`; kill -9 ${PID}; if [ ! $? ];then echo "关闭 tomcat 失败,请手动关闭"; exit; fi;fi;echo "tomcat 关闭成功";startTomcat;