博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
脚本发布
阅读量:6543 次
发布时间:2019-06-24

本文共 5734 字,大约阅读时间需要 19 分钟。

一、前言

因为使用Jenkins自动部署有很多未知问题,自己写脚本来部署也是可以的。

 

二、实现过程

创建脚本o2o-erp-order-dsc.sh和o2o-erp-order_all.sh

#!/bin/bashsource /etc/profileprofileName="local_dev"projectTag="60049-o2o-erp-order-dsc"svn update /data/code/trunk/java/microservice/o2o-erp-order/shell/o2o-erp-order_all.shsh /data/code/trunk/java/microservice/o2o-erp-order/shell/o2o-erp-order_all.sh "${profileName}" "${projectTag}"

 

#!/bin/bashsource /etc/profileexport M2_HOME=/data/apache-maven-3.0.3export M2=$M2_HOME/binexport MAVEN_OPTS="-Xms256m -Xmx512m"export PATH=$M2:$PATH:echo -e "\n\n profile name:$1 \n"if [ $# == 2 ] ; then    startProject="$2"    echo -e "start project :$startProject \n\n"ficd /data/code/trunk/java/common/o2o-common && svn update . && mvn clean install -Dmaven.test.skip=trueif [ $? -eq 0 ];then echo "mvn install o2o-common success!";else echo "mvn install o2o-common fail!";exit $?;ficd /data/code/trunk/java/microservice/o2o-basis-data && svn update . && mvn clean install -Dmaven.test.skip=trueif [ $? -eq 0 ];then echo "mvn install o2o-basis-data success!";else echo "mvn install o2o-basis-data fail!";exit $?;ficd /data/code/trunk/java/microservice/o2o-erp-order && svn update . && mvn clean install -Dmaven.test.skip=trueif [ $? -eq 0 ];then echo "mvn install o2o-erp-order success!";else echo "mvn install o2o-erp-order fail!";exit $?;fi# 如果传递了第二个参数,那么只启动指定的项目======================if [ $# == 2 ] ; then    kill -9 `netstat -nlp | grep "${startProject%%-*}" | awk '{print $7}'|awk -F/ '{print $1}'`    # start o2o-erp-order- 某个project    cd /data/code/trunk/java/microservice/o2o-erp-order/"${startProject#*-}" && mvn clean package  -Dmaven.test.skip=true -P"$1"    if [ $? -eq 0 ];then echo "mvn package ${startProject#*-} success!";else echo "mvn package ${startProject#*-} fail!";exit $?;fi    rm -rf /data/webservers/"${startProject}"/webapps/*    cp -r /data/code/trunk/java/microservice/o2o-erp-order/"${startProject#*-}"/target/"${startProject#*-}".war /data/webservers/"${startProject}"/webapps/ROOT.war    sh /data/webservers/"${startProject}"/bin/catalina.sh start    tail -f /data/webservers/"${startProject}"/logs/catalina.out    break;fi# 如果传递了第二个参数,那么只启动指定的项目======================# 启动全部项目===========================================# start o2o-erp-order-dsccd /data/code/trunk/java/microservice/o2o-erp-order/o2o-erp-order-dsc && mvn clean package  -Dmaven.test.skip=true -P"$1"if [ $? -eq 0 ];then echo "mvn package o2o-erp-order-dsc success!";else echo "mvn package o2o-erp-order-dsc fail!";exit $?;fikill -9 `netstat -nlp | grep 60049 | awk '{print $7}'|awk -F/ '{print $1}'`rm -rf /data/webservers/60049-o2o-erp-order-dsc/webapps/*cp -r /data/code/trunk/java/microservice/o2o-erp-order/o2o-erp-order-dsc/target/o2o-erp-order-dsc.war /data/webservers/60049-o2o-erp-order-dsc/webapps/ROOT.warsh /data/webservers/60049-o2o-erp-order-dsc/bin/catalina.sh starttail -f /data/webservers/60049-o2o-erp-order-dsc/logs/catalina.out# start o2o-erp-order-webcd /data/code/trunk/java/microservice/o2o-erp-order/o2o-erp-order-web && mvn clean package  -Dmaven.test.skip=true -P"$1"if [ $? -eq 0 ];then echo "mvn package o2o-erp-order-web success!";else echo "mvn package o2o-erp-order-web fail!";exit $?;fikill -9 `netstat -nlp | grep 60149 | awk '{print $7}'|awk -F/ '{print $1}'`rm -rf /data/webservers/60149-o2o-erp-order-web/webapps/*cp -r /data/code/trunk/java/microservice/o2o-erp-order/o2o-erp-order-web/target/o2o-erp-order-web.war /data/webservers/60149-o2o-erp-order-web/webapps/ROOT.warsh /data/webservers/60149-o2o-erp-order-web/bin/catalina.sh starttail -f /data/webservers/60149-o2o-erp-order-web/logs/catalina.out# start o2o-erp-order-jobcd /data/code/trunk/java/microservice/o2o-erp-order/o2o-erp-order-job && mvn clean package  -Dmaven.test.skip=true -P"$1"if [ $? -eq 0 ];then echo "mvn package o2o-erp-order-job success!";else echo "mvn package o2o-erp-order-job fail!";exit $?;fikill -9 `netstat -nlp | grep 60249 | awk '{print $7}'|awk -F/ '{print $1}'`rm -rf /data/webservers/60249-o2o-erp-order-job/webapps/*cp -r /data/code/trunk/java/microservice/o2o-erp-order/o2o-erp-order-job/target/o2o-erp-order-job.war /data/webservers/60249-o2o-erp-order-job/webapps/ROOT.warsh /data/webservers/60249-o2o-erp-order-job/bin/catalina.sh starttail -f /data/webservers/60249-o2o-erp-order-job/logs/catalina.outecho -e "\n\nall package ok, test Tomcat...\n\n"# judge is start ok======================================================# curl -X GET --header 'Accept: text/plain' 'http://localhost:60149/health.do'# /usr/bin/wget -S --spider --tries=3 --timeout=3 http://localhost:60149/health.docluster="localhost:60049|o2o-erp-order-dsc localhost:60149|o2o-erp-order-web localhost:60249|o2o-erp-order-job"serviceCount=0  # 服务数量successCount=0  # 启动成功的服务数量for server in $clusterdo    let serviceCount++    echo "$server"|while IFS="|" read f1 f2    do       tryCount=1 # 重试次数       host="$f1"       serviceName="$f2"        while [ $tryCount -le 10 ]; do            result=`/usr/bin/wget -S --spider --tries=3 --timeout=3 http://$host/health.do 2>&1 | grep HTTP/1.1 | awk '{print $2}'`            if [ "$result" = "200" ]            then                echo -e "\nTomcat $host [$serviceName] Running OK..."                let successCount++                break            else                echo -e ".\c"                let tryCount++                sleep 5            fi            if [ $tryCount -gt 10 ]            then                echo "Tomcat $host [$serviceName] Running Test more than 20 times. Tomcat maybe start fail !"                break;            fi        done    donedoneecho -e "all process finish. Success: $successCount, Total Process: $serviceCount\n"exit

 

转载于:https://www.cnblogs.com/kesimin/p/8493370.html

你可能感兴趣的文章
一个超棒的jQuery通知栏插件 - jBar
查看>>
分享17个漂亮的电子商务网站
查看>>
JavaScript实用手册
查看>>
dpkg参数
查看>>
AS3!INT
查看>>
简述思科、华为交换机型号字母代表的意思
查看>>
memcache--mysql测试
查看>>
拷贝构造函数、拷贝函数、析构函数
查看>>
实战CGLib系列之proxy篇(一):方法拦截MethodInterceptor
查看>>
php 字符串截取
查看>>
ttcn-3
查看>>
00.java虚拟机的基本结构概念
查看>>
深入浅出 ES6:ES6 与 Babel - Broccoli 的联用
查看>>
ThreadLocal使用出现的问题
查看>>
关于十六进制和八进制负数的问题
查看>>
连接池并发的实现原理
查看>>
创建Pch预编译文件
查看>>
阿里云Centos配置iptables防火墙
查看>>
UML类图几种关系的总结
查看>>
PHP面试题汇总
查看>>