测试环境自动部署:抓取war包,备份,替换配置文件,部署到tomcat下并重启

#!/bin/sh

appname="webproject"
warname="webproject.war"

port=8000

#get the newly package
wget -r -nH -nv --level=0 --cut-dirs=8 xxxxxxxxxxxxxxx --user getprod --password getprod

 releasedir="/home/auser/project/project_release"
 outdir="/home/auser/project/project_release/output"

 tom_bin="/home/auser/project/apache-tomcat-6.0.37/bin"
 appdir="/home/auser/project/apache/htdocs"

# kill the pid which was running on the port
pid=`netstat -tlnp | grep ${port} | awk '{print $7}' | awk -F "/" '{print $1}'`

if [ ! -z $pid ];then
        kill -9 $pid
        echo "process${pid} was killed!"
fi

#0. bakup the newly release package,copy to outputdir
mv ${releasedir}/${warname} ${outdir}/${warname}

#1. unzip the new version war package
rm -rf $appdir/${appname}

unzip  ${outdir}/${warname} -d ${outdir}/${appname}
	echo "unzip finished........"

#2. replace settings file to output/app/WEB-INF/classes
cd ${outdir}/projectnew_option;sh -x replaceCONF.sh 
	echo "deployoption.sh run ok.........."

#3. move output/app/ to /home/work/apache/htdocs/app/
mv ${outdir}/${appname} ${appdir}/${appname}
	echo "app dir moving finished........."

#4. backup output/app.war 
mv ${outdir}/${warname}  ${outdir}/${warname}`date +%Y%m%d%H%M%S`
	echo "new version war package backup finished......"

#5. start the tomcat,and checking
export JAVA_HOME=/home/auser/project/jdk1.6.0_07
export CLASSPATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH


cd $tom_bin;sh -x startup.sh
sleep 3

npid=`netstat -tlnp | grep ${port} | awk '{print $7}' | awk -F "/" '{print $1}'`
while [ -z $npid ]
do
	sleep 2
        cd ${tom_bin};sh -x startup.sh
	npid=`netstat -tlnp | grep ${port} | awk '{print $7}' | awk -F "/" '{print $1}'`
done
        echo "It's ok,the port is ${port},and pid is ${npid},Tomcat path ${tom_bin}"

你可能感兴趣的:(tomcat,自动部署)