码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-09-13 22:06:24      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:

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

# Please define the absolute path of tomcat instance
THIS_TC_INSTANCE=/home/tomcat/tomcat8_jdk8_1
THIS_APP_MODULE=throne-commons

df -h
echo ‘‘
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 running
else
  echo Shutting down Tomcat at ${THIS_TC_INSTANCE}
  ${THIS_TC_INSTANCE}/bin/shutdown.sh
  sleep 5
fi

pid=`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 down
else
  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 9
fi

echo ‘‘
echo Removing old deployments
rm -f ${THIS_TC_INSTANCE}/webapps/${THIS_APP_MODULE}.war
rm -rf ${THIS_TC_INSTANCE}/webapps/${THIS_APP_MODULE}
echo Copying new deployments
echo ‘‘
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的脚本

标签:

原文地址:http://www.cnblogs.com/milton/p/5869736.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!