projectName=""; #默认tomcat目录名称,可根据自己需求改成自己的tomcat名称, tomcatName="tomcat7_8080"; #通过直接杀进程停止tomcat,防止热部署导致服务器内存不足,为了让客户端访问不中断,可以对自己的tomcat做负载 echo "停止$tomcatName" ps -ef|grep $tomcatName |grep -v grep|cut -c 9-15|xargs kill -9; echo "停止成功"; #切换到代码目录 cd /opt/code/your_project-git; echo "cd /opt/code/your_project-git"; #打印当前git代码分支 echo "当前分支:" git symbolic-ref --short -q HEAD; echo "拉取最新代码"; #更新代码 git pull; echo "拉取完成"; echo "********************************************************************************"; echo "环境变量为:$1"; #多环境情况下,部署环境可通过变量传递,例如测试1环境、测试2环境 echo "maven编译开始"; mvn clean install -P$1; echo "maven编译完成"; #循环部署项目,不同的项目如果有不同的tomcatName,直接在对应的if中重新指定tomcatName for arg in "[email protected]" do projectName=""; contextName=$arg; if [ "$arg" = "app" ]; then projectName="app"; elif [ "$arg" = "merchant" ]; then projectName="merchant"; elif [ "$arg" = "mgmt" ]; then projectName="mgmt"; tomcatName="tomcat7_8080"; elif [ "$arg" = "job" ]; then projectName="job"; fi if [ "$projectName" != "" ]; then #删除tomcat中对应的项目 echo "删除 /usr/local/tomcat/$tomcatName/webapps/$contextName*"; rm -rf /usr/local/tomcat/$tomcatName/webapps/$contextName*; echo "删除完成"; echo "********************************************************************************"; #复制通过maven打包完成的war到tomcat目录 echo "复制mb-$projectName-web/target/$projectName.war to /usr/local/tomcat/$tomcatName/webapps/$contextName$lang.war"; cp mb-$projectName-web/target/$projectName.war /usr/local/tomcat/$tomcatName/webapps/$contextName$lang.war; echo "复制成功"; echo "********************************************************************************"; fi done #启动tomcat,如果每个项目对应不同的tomcat,则把启动命令放在对应的循环里面的复制项目命令后面 echo "启动$tomcatName"; sh /usr/local/tomcat/$tomcatName/bin/startup.sh; echo "启动成功";
时间: 2024-10-08 07:00:39