首页 > 代码库 > 用于部署war并重启Tomcat的脚本

用于部署war并重启Tomcat的脚本

只需要定义两个变量, 一个是目标tomcat实例的目录, 另一个是war包的名称

# Please define the absolute path of tomcat instanceTHIS_TC_INSTANCE=/home/tomcat/tomcat8_jdk8_1THIS_APP_MODULE=throne-commonsdf -hecho ‘‘pid=`ps -ef|grep ${THIS_TC_INSTANCE}|grep -v grep|grep java|awk {print $2}`if [ -z $pid ] ; then  echo Tomcat ${THIS_TC_INSTANCE} is not runningelse  echo Shutting down Tomcat at ${THIS_TC_INSTANCE}  ${THIS_TC_INSTANCE}/bin/shutdown.sh  sleep 5fipid=`ps -ef|grep ${THIS_TC_INSTANCE}|grep -v grep|grep java|awk {print $2}`if [ -z $pid ] ; then  echo Tomcat ${THIS_TC_INSTANCE} has been shut downelse  echo Tomcat ${THIS_TC_INSTANCE} didnot exit normally, now killing the PID:${pid}  ps -ef|grep ${THIS_TC_INSTANCE}|grep -v grep|grep java|awk {print $2}|xargs kill -s 9fiecho ‘‘echo Removing old deploymentsrm -f ${THIS_TC_INSTANCE}/webapps/${THIS_APP_MODULE}.warrm -rf ${THIS_TC_INSTANCE}/webapps/${THIS_APP_MODULE}echo Copying new deploymentsecho ‘‘cp -f /home/tomcat/builds/${THIS_APP_MODULE}.war ${THIS_TC_INSTANCE}/webapps/echo Startup tomcat${THIS_TC_INSTANCE}/bin/startup.sh

对应的Jenkins Pipeline配置

node {   // Mark the code checkout stage....   stage Checkout   sh "mkdir -p throne-commons-impl"   dir(throne-commons-impl) {     git branch: master, credentialsId: 859dde85-5e0c-4ab3-8fd1-d31c96d4cae4, url: git@192.168.255.109:yhc/throne-commons-impl.git   }   env.JAVA_HOME="${tool ‘jdk1.8.0_101‘}"   sh $JAVA_HOME/bin/java -version   def mvnHome = tool apache-maven-3.3.9   stage Build   dir(throne-commons-impl) {     sh "${mvnHome}/bin/mvn -s /home/tomcat/files/settings.xml clean package -Dmaven.test.skip=true -Pthrone_qa -e"   }   stage Publish   sshagent([594d69cf-fd5e-45ea-8ab0-c94db218017a]) {      sh ssh -p 22 tomcat@192.168.255.107 \df -h\‘‘      sh scp throne-commons-impl/target/throne-commons.war tomcat@192.168.255.107:/home/tomcat/builds/      sh ssh -p 22 tomcat@192.168.255.107 \/home/tomcat/scripts/deploy_t8_j8_1_commons.sh\‘‘   }}

 

用于部署war并重启Tomcat的脚本