Projectname= "", #默认tomcat目录名称, can be changed to their own tomcat name according to their own needs, tomcatname= "tomcat7_8080", #通过直接杀进程停止tomcat, to prevent hot deployment caused insufficient server memory, To make the client access uninterrupted, you can load echo "Stop $tomcatname" Ps-ef|grep $tomcatName |grep-v grep|cut-c 9-15|xargs kill-9;echo "stop successfully "; #切换到代码目录cd/opt/code/your_project-git;echo" Cd/opt/code/your_project-git "; #打印当前git代码分支echo" Current branch: "Git Symbolic-ref--short-q Head;echo "Pull the latest code"; #更新代码git Pull;echo "pull complete"; echo "****************************************** The "; echo" Environment variable is: $ "; #多环境情况下, the deployment environment can be passed through variables, such as test 1 environment, Test 2 Environment echo" maven compilation start "; mvn Clean Install-p$1;echo "maven compile complete"; #循环部署项目, if different projects have different tomcatname, re-specify tomcatnamefor arg in "[email " directly in the corresponding if 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 "Delete/usr/local/tomcat/$tomcatName/webapps/$contextName *"; rm-rf/usr/local/tomcat/$tomcatName/webapps/$contextName *; echo "Delete Complete"; echo "********************************************************************************"; #复制通过maven打包完成的war到tomcat目录 echo "Copy mb-$projectName-web/target/$projectName. War to/usr/local/tomcat/$tomcatName/w ebapps/$contextName $lang.war "; CP mb-$projectName-web/target/$projectName. war/usr/local/tomcat/$tomcatName/webapps/$contextName $lang.war; echo "Copy succeeded"; echo "********************************************************************************"; fidone# start Tomcat, if each project corresponds to a different tomcat, place the start command behind the Copy Item command in the corresponding loop and echo "Start $tomcatname"; sh/usr/local/tomcat/$tomcatName/ Bin/startup.sh;echo "Start Success";
UBUNTU+TOMCAT, multi-environment, automated deployment scripts, Git+maven+tomcat+ubuntu