zoukankan      html  css  js  c++  java
  • Jenkins 灰度

    Jenkins 灰度

     

     

     

    #!/bin/bash
    DATE=`date +%Y-%m-%d_%H-%M-%S`
    METHOD=$1
    BRANCH=$2
    GROUP_LIST=$3
    
    function IP_list(){
      if [[ ${GROUP_LIST} == "GROUP1" ]];then
         Server_IP="192.168.88.12"
         echo ${Server_IP}
         #ssh sdn@192.168.88.12 ""echo disable  server linux38-web-80/192.168.88.13" |sudo socat stdio /run/haproxy/admin.sock"
      elif [[ ${GROUP_LIST} == "GROUP2" ]];then
         Server_IP="192.168.88.13"
         echo ${Server_IP}
         #ssh sdn@192.168.88.12 ""echo enable  server linux38-web-80/192.168.88.12" |sudo socat stdio /run/haproxy/admin.sock"
      elif [[ ${GROUP_LIST} == "GROUP3" ]];then
         Server_IP="192.168.88.12 192.168.88.13"
         echo ${Server_IP}
      fi
    }
    
    function clone_code(){
      rm -rf /var/lib/jenkins/workspace/test
      cd /var/lib/jenkins/workspace/
      git clone -b ${BRANCH} git@192.168.88.10:root/test.git
    }
    
    function scanner_code(){
      echo "cd /var/lib/jenkins/workspace/test && /usr/local/sonarscanner/bin/sonar-scanner" 
    }
    
    function make_zip(){
      cd /var/lib/jenkins/workspace/test && zip -r app1.zip ./*
    }
    
    function node_down(){
      for node in ${Server_IP};do
        ssh sdn@192.168.88.12 "echo "disable server linux38-web-80/${node}" |sudo socat stdio   /run/haproxy/admin.sock"
        echo "${node} 从负载均衡下线成功"
      done
    }
    
    function scp_zipfile(){
      for node in ${Server_IP};do
        scp /var/lib/jenkins/workspace/test/app1.zip  sdn@${node}:/data/tomcat/tomcat_appdir/app1-${DATE}.zip
        ssh sdn@${node} "unzip /data/tomcat/tomcat_appdir/app1-${DATE}.zip -d /data/tomcat/tomcat_webdir/app1-${DATE} && sudo rm -rf /var/lib/tomcat8/webapps/ROOT && sudo ln -sv /data/tomcat/tomcat_webdir/app1-${DATE}/ROOT /var/lib/tomcat8/webapps/"
        
      done
    }
    
    function stop_tomcat(){
      for node in ${Server_IP};do
        echo "${node} 开始停止tomcat"
        ssh sdn@${node}   "sudo /etc/init.d/tomcat8 stop"
        echo "${node} tomcat停止成功"
      done
    }
    
    function start_tomcat(){
      for node in ${Server_IP};do
        ssh sdn@${node}   "sudo /etc/init.d/tomcat8 start"
        #sleep 5
      done
    }
    
    function web_test(){
      sleep 20
      for node in ${Server_IP};do
        NUM=`curl -s  -I -m 10 -o /dev/null  -w %{http_code}  http://${node}:8080/index.html`
        if [[ ${NUM} -eq 200 ]];then
           echo "${node} 测试通过,即将添加到负载"
           add_node ${node}
        else
           echo "${node} 测试失败,请检查该服务器是否成功启动tomcat"
        fi
      done
    }
    
    function add_node(){
       node=$1
       ssh sdn@192.168.88.12 ""echo enable  server linux38-web-80/${node}" |sudo socat stdio /run/haproxy/admin.sock"
       echo "${node} 部署完毕,请进行代码测试!"
    #   echo ${node},"----->"
    #    if [[ ${GROUP_LIST} == "online-all" ]];then
    #      ssh sdn@192.168.88.12 ""echo enable  server myapp/192.168.88.13" | socat stdio /run/haproxy/admin.sock"
          #ssh root@172.31.0.104 ""echo enable  server myapp/172.31.0.105" | socat stdio /run/haproxy/admin.sock"     
    #    fi
        ##########################################
    #    if [ ${node} == "192.168.88.13" ];then
    #       echo "192.168.88.12 部署完毕,请进行代码测试!"
    #    else
    #      ssh root@192.168.88.12 ""echo enable  server linux38-web-80/${node}" | socat stdio /run/haproxy/admin.sock"
          #ssh root@172.31.0.104 ""echo enable  server linux38-web-80/${node}" | socat stdio /run/haproxy/admin.sock"
    #    fi
    }
    
    function rollback_last_version(){
      for node in ${Server_IP};do
       NOW_VERSION=`ssh sdn@${node} ""ls -l  -rt /var/lib/tomcat8/webapps/ |  awk -F"->" '{print $2}'  | tail -n1|awk -F'ROOT' '{print $1}'""`
       NOW_VERSION=`basename ${NOW_VERSION}`
       echo $NOW_VERSION
       NAME=`ssh  sdn@${node}  ""ls  -l  -rt  /data/tomcat/tomcat_webdir/ | grep -B 1  ${NOW_VERSION} |  head -n1 | awk '{print $9}'""`
       ssh sdn@${node} "sudo rm -rf /var/lib/tomcat8/webapps/ROOT && sudo ln -sv  /data/tomcat/tomcat_webdir/${NAME}/ROOT /var/lib/tomcat8/webapps/"
      done 
    }
    
    main(){
       case $1  in
          deploy)
            IP_list;        
            clone_code;
            scanner_code;
            make_zip;
            node_down;
            stop_tomcat;
            scp_zipfile;
            start_tomcat;
            web_test;
             ;;
           rollback_last_version)
            IP_list;
            echo ${Server_IP}
            node_down;
            stop_tomcat;
            rollback_last_version;
            start_tomcat;
            web_test;
             ;;
        esac
    }
    
    main $1 $2 $3
    deploy-test.sh

    https://www.cnblogs.com/xiao987334176/p/13074198.html

  • 相关阅读:
    【常用】source insight常用设置及快捷键
    【Linux学习】配置环境:实现【VirtualBox + ubuntu】+【开启ssh服务】+【putty远程连接到虚拟机】
    javascript:区别浏览器
    linux 之centos6.3 安装中文输入法
    前端优化(静态资源)
    javascript 学习心得!
    编程总结
    2019年春季学期第二周作业
    HTTP could not register URL http://+:8000/testservice/. Your process does not have access rights to this namespace 解决方案
    [原]ASP.NET MVC 3 Razor + jqGrid 示例
  • 原文地址:https://www.cnblogs.com/hanwei666/p/13206532.html
Copyright © 2011-2022 走看看