废话不多说直接上脚本,也可以直接下载原脚本文件
#!/bin/bash#Time
log_time=`date +[%Y-%m-%d]%H:%M:%S`
###manual_properties###
project_name=demo
tomcat_basehome=/var/apache-tomcat-7.0.79_81
tomcat_port=80
shell_environment=/bin/bash
war_Dir=/var/${project_name}/temp
war_Name=${project_name}.war
source_dir=/var/code/${project_name}
docBase=${project_name}
###manual_properties###
#update server environment
echo "********************************** ${log_time}
*************************************"
#compile code
cd ${source_dir}
git pull
mvn clean
mvn compile
mvn package -DskipTests=true
cd target
#build check funcation
echo "check tomcat status..."
check_tomcat_status(){
netstat -ant|grep ${tomcat_port} > /dev/null
t=$?
if [ $t -eq 0 ]; then
echo "tomcat is running....port is ${tomcat_port}"
echo "shutdown tomcat....."
echo ">>>>>>>shutdown tomcat begin<<<<<<<<"
${shell_environment} ${tomcat_basehome}/bin/shutdown.sh
echo ">>>>>>>shutdown tomcat end <<<<<<<<"
sleep 5
elif [ $t -ne 0 ];then
echo "tomcat is poweroff"
${shell_environment} ${tomcat_basehome}/bin/shutdown.sh
sleep 5
fi
}
#check tomcat status invoke function
check_tomcat_status
#kill current proc
kill -9 $(ps -aef | grep catalina | grep ${tomcat_basehome} | grep -v grep | awk '{print
$2}')
#copy new
#rm -rf ${source_dir}/target/${docBase}/*
cp -v -r ${source_dir}/target/${docBase}/ ${tomcat_basehome}/webapps/
#reboot tomcat
echo " >>>>>>> rebooting tomcat begin <<<<<<<<"
${shell_environment} ${tomcat_basehome}/bin/startup.sh
echo " >>>>>>> rebooting tomcat end <<<<<<<<"
echo "the log you can read in canalina.out"
echo "************************ deploy war package into container Successlly
**********************************"