shell 自动部署替换版本和备份
#!/bin/sh
tm=`date "+%Y%m%d-%H:%M"`
home_path=/home/tool_file
web_source=/opt/server/tomcat/webapps
his_version_path=/data/client/his_version/$tm
if [ -f "$home_path/version/client_web.war" ];then
unzip $home_path/version/pics_client_web.war -d $home_path/version/client_web
else
echo 'Package does not exist'
fi
if [ -f "$home_path/version/pics_client_web/WEB-INF/classes/spring-context.xml" ];then
\cp $home_path/config/spring-context.xml $home_path/version/client_web/WEB-INF/classes/spring-context.xml
fi
if [ -f "$home_path/version/jsapi/Config.js" ];then
\cp $home_path/config/Config.js $home_path/version/jsapi/Config.js
fi
for i in {1..5}
do
#count$i=`ps -ef|grep tomcat|grep -v grep|wc -l`
if [ `ps -ef|grep tomcat|grep -v grep|wc -l` -eq 0 ];then
echo 'the process 8080 is not exit'
break
else
ps -ef|grep tomcat|grep -v grep|awk '{print $2}'|xargs kill -9
echo 'Kill the process'
fi
done
mkdir $his_version_path
if [ -d "$his_version_path" ];then
echo 'Backup the last deployed version'
mv $web_source/client_web $his_version_path/
echo 'Deploying a new version'
mv $home_path/version/client_web $web_source
echo 'Start server'
sh $web_source/../bin/startup.sh
rm -rf $home_path/version/*
fi