• 脚本发布


    一、前言

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

    二、实现过程

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

    #!/bin/bash
    source /etc/profile
    
    profileName="local_dev"
    
    projectTag="60049-o2o-erp-order-dsc"
    
    svn update /data/code/trunk/java/microservice/o2o-erp-order/shell/o2o-erp-order_all.sh
    
    sh /data/code/trunk/java/microservice/o2o-erp-order/shell/o2o-erp-order_all.sh "${profileName}" "${projectTag}"
    #!/bin/bash
    source /etc/profile
    
    export M2_HOME=/data/apache-maven-3.0.3
    export M2=$M2_HOME/bin
    export MAVEN_OPTS="-Xms256m -Xmx512m"
    export PATH=$M2:$PATH:
    
    echo -e "
    
     profile name:$1 
    "
    if [ $# == 2 ] ; then
        startProject="$2"
        echo -e "start project :$startProject 
    
    "
    fi
    
    cd /data/code/trunk/java/common/o2o-common && svn update . && mvn clean install -Dmaven.test.skip=true
    if [ $? -eq 0 ];then echo "mvn install o2o-common success!";else echo "mvn install o2o-common fail!";exit $?;fi
    
    cd /data/code/trunk/java/microservice/o2o-basis-data && svn update . && mvn clean install -Dmaven.test.skip=true
    if [ $? -eq 0 ];then echo "mvn install o2o-basis-data success!";else echo "mvn install o2o-basis-data fail!";exit $?;fi
    
    
    cd /data/code/trunk/java/microservice/o2o-erp-order && svn update . && mvn clean install -Dmaven.test.skip=true
    if [ $? -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-dsc
    cd /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 $?;fi
    
    kill -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.war
    sh /data/webservers/60049-o2o-erp-order-dsc/bin/catalina.sh start
    tail -f /data/webservers/60049-o2o-erp-order-dsc/logs/catalina.out
    
    # start o2o-erp-order-web
    cd /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 $?;fi
    
    kill -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.war
    sh /data/webservers/60149-o2o-erp-order-web/bin/catalina.sh start
    tail -f /data/webservers/60149-o2o-erp-order-web/logs/catalina.out
    
    
    # start o2o-erp-order-job
    cd /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 $?;fi
    
    kill -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.war
    sh /data/webservers/60249-o2o-erp-order-job/bin/catalina.sh start
    tail -f /data/webservers/60249-o2o-erp-order-job/logs/catalina.out
    
    echo -e "
    
    all package ok, test Tomcat...
    
    "
    
    # 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.do
    
    cluster="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 $cluster
    do
        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 "
    Tomcat $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
        done
    done
    
    echo -e "all process finish. Success: $successCount, Total Process: $serviceCount
    "
    exit

    作者:Kero小柯
    出处:http://www.cnblogs.com/kesimin/
    本文版权归作者和博客园共有,欢迎转载,但必需注明出处,并且在文章页面明显位置给出原文连接。

  • 相关阅读:
    SynchronousQueue、LinkedBlockingQueue、ArrayBlockingQueue性能测试
    JDK源码分析—— ArrayBlockingQueue 和 LinkedBlockingQueue
    ArrayBlockingQueue和LinkedBlockingQueue的区别
    Net处理html页面元素工具类(HtmlAgilityPack.dll)的使用
    WebView混合开发
    对付"反盗链"
    通过代码来操作SQLite的示例
    System.Data.SQLite未能加载文件或程序集
    Using SQLXML Bulk Load in the .NET Environment
    Asynchronous Programming Using Delegates使用委托进行异步编程
  • 原文地址:https://www.cnblogs.com/kesimin/p/8493370.html
Copyright © 2020-2023  润新知