范例:部署ms.sh

#!/bin/bash

export AOS_K8S_PATH=$(cd "$(dirname "$0")"; pwd)

cd $AOS_K8S_PATH

echo AOS_K8S_PATH:=$AOS_K8S_PATH

source $AOS_K8S_PATH/env_ms/env_ms.sh

export AOSSCLOUD_JDK_DEBUG=1

export ACLOUD_K8S_PATCH=$(dirname $AOS_K8S_PATH)

echo ACLOUD_K8S_PATCH:=$ACLOUD_K8S_PATCH

find $AOS_K8S_PATH -name '*.sh'|xargs chmod +x

find $AOS_K8S_PATH/../aos_pvc/ -name '*.sh'|xargs chmod +x

#生成编排文件参数

$AOS_K8S_PATH/bin/gen_all_yml.sh

if [ $# -ge 4 ]

then

    printf "USAGE: ./aos_ms.sh [action] [filename]\n"

    printf "[ ERROR ] 请输入正确的参数,形如: ./aos_ms.sh create 或 ./aos_ms.sh create _base_\n"

    printf "[ ERROR ] Please input correct argument, Example: ./aos_ms.sh create or ./aos_ms.sh create _base_\n"

    exit 2

fi

#首先处理容器的操作参数

if [ $# == 0 ]

then

    printf "EFLOW容器相关的操作如下(EFLOW MS Action List):\n"

    printf "    1-全新部署[create]\n"

    printf "    2-卸载容器[delete]\n"

    printf "    3-重建数据库[rundb]\n"

    printf "    4-设置副本数[replicas]\n"

    printf "    5-全部清除[clear]\n"

    printf "    9-日常巡检[check]\n"

    echo -n "请输入操作编号或命令,如1或create(Input action number or command, Example: 1 or create): "

    read arg_action

    case  $arg_action in

        1) arg_action="create"

        ;;

        2) arg_action="delete"

        ;;

        3) arg_action="rundb"

        ;;

        4) arg_action="replicas"

        ;;

        5) arg_action="clear"

        ;;

        9) arg_action="check"

        ;;

    esac

else

    arg_action=$1

    if  [ $arg_action != "delete" ] && [ $arg_action != "replicas" ] \

        && [ $arg_action != "create" ]  && [ $arg_action != "rundb" ] \

        && [ $arg_action != "clear" ]  && [ $arg_action != "check" ]

    then

        printf "[ ERROR ] 请在第一个参数输入正确的操作,例如deploy, down等!\n"

        printf "[ ERROR ] Please input action right at 1st argument, such as create, delete ...\n"

        exit 2

    fi   

fi

#接着处理编排文件参数

if [ $arg_action = "delete" ] || [ $arg_action = "replicas" ] \

        || [ $arg_action = "create" ]

then

    if [ $# -le 1 ]

        then

            printf "编排文件列表(EFlow MS Compose File List):\n"

            find $AOS_K8S_PATH/yml_out/ -name '*.yml'|sed -e 's/^.*\//    /'|sort

            echo -n "请输入编排文件,支持模糊匹配(Input compose files, support fuzzy matching):"

            read arg_filename

        else

            arg_filename=$2

    fi

    echo "Compose yaml files list:"

    find $AOS_K8S_PATH/yml_out/ -name "*$arg_filename*"|sort| sed -e "s/^/  /"

fi

if [ $arg_action == "replicas"  ]

then

    if [ $# -le 2 ]

    then

        echo -n "请输入修改副本数(Input replicas number):"

        read replicas

    else

        replicas=$3

    fi

    if [ ! $replicas ] || [ -z $replicas ] || [ ! -z ${replicas//[0-9]/} ]

    then

        printf "[ ERROR ] 副本数只能为整数!\n"

        printf "[ ERROR ] Replicas number must be integer!\n"

        exit 2

    fi

fi

if [ $arg_action == "check"  ]

then

    if [ $# -le 1 ]

    then

        printf "eFlow云巡检相关的操作如下(eFlow Cloud Action List):\n"

        printf "    0-全面检查[all]\n"

        printf "    1-系统负载[workload]\n"

        printf "    2-检查主控节点[master]\n"

        printf "    3-检查从节点[node]\n"

        printf "    4-检查卷[pvc]\n"

        echo -n "请输入操作编号或命令,如1或workload(Input action number or command, Example: 1 or workload): "

        read chk_action

        case  $chk_action in

            0) chk_action="all"

            ;;

            1) chk_action="workload"

            ;;

            2) chk_action="master"

            ;;

            3) chk_action="node"

            ;;

            4) chk_action="pvc"

            ;;

        esac

    else

        chk_action=$2 

    fi

fi

#正常编排动作处理

if [ $arg_action == "delete" ]

then

    $AOS_K8S_PATH/bin/clear_k8s.sh $arg_filename

elif [ $arg_action == "replicas"  ]

then

    find $AOS_K8S_PATH/yml_out/ -name "*$arg_filename*"|xargs sed -i "s/replicas: .*/replicas: $replicas/g"

    $AOS_K8S_PATH/../aos_pvc/aos_pvc.sh create

    kubectl scale --replicas=$replicas statefulset $arg_filename

    exit 0

elif [ $arg_action == "clear"  ]

then

    $AOS_K8S_PATH/bin/clear_k8s.sh

    exit 0

elif [ $arg_action == "check"  ]

then

    $AOS_K8S_PATH/bin/aos_check.sh $chk_action

    exit 0

elif [ $arg_action == "create"  ]

then

    $AOS_K8S_PATH/bin/clear_k8s.sh $arg_filename

    $AOS_K8S_PATH/../aos_pvc/aos_pvc.sh create

    find $AOS_K8S_PATH/yml_out/ -type f -name "*$arg_filename*"|sort| sed -e "s/^/kubectl create -f/"|bash

    mysql_deployed=$(find $AOS_K8S_PATH/yml_out/ -type f -name "*$arg_filename*"|grep mysql|wc -l)

    if [ $mysql_deployed == "1" ]

    then   

        tenantRunning=$(kubectl get pod tenant1-0|grep Running|wc -l)

        while [ $tenantRunning -ne 1 ]

        do

          echo 'Waitting tenant service ...'

          sleep 2s

          tenantRunning=$(kubectl get pod tenant1-0|grep Running|wc -l)

        done

        kubectl get pods -o wide|grep tenant|grep Running|head -1|awk '{print "kubectl exec -i "$1" /ums-server/utils/dbtool/run.sh"}'

        kubectl get pods -o wide|grep tenant|grep Running|head -1|awk '{print "kubectl exec -i "$1" /ums-server/utils/dbtool/run.sh"}'|bash

    fi

elif [ $arg_action == "rundb"  ]

then

    $AOS_K8S_PATH/../aos_pvc/aos_pvc.sh create

    find $AOS_K8S_PATH/yml_out/ -type f -name "*tenant*"|sort| sed -e "s/^/kubectl create -f/"|bash

    tenantRunning=$(kubectl get pod tenant1-0|grep Running|wc -l)

    while [ $tenantRunning -ne 1 ]

    do

      echo 'Waitting tenant service ...'

      sleep 2s

      tenantRunning=$(kubectl get pod tenant1-0|grep Running|wc -l)

    done

    kubectl get pods -o wide|grep tenant|grep Running|head -1|awk '{print "kubectl exec -i "$1" /ums-server/utils/dbtool/run.sh"}'

    kubectl get pods -o wide|grep tenant|grep Running|head -1|awk '{print "kubectl exec -i "$1" /ums-server/utils/dbtool/run.sh"}'|bash

    exit 0

    #kubectl get pods -o wide|grep tenant|grep Running|head -1|awk -e '{print "kubectl exec -i "$1" /ums-server/utils/dbtool/run.sh"}'|bash

fi

echo "-----------Finish Composing Service----------------"

#更新数据库中服务信息

$AOS_K8S_PATH/bin/insert_msinfo.sh

#刷新nignx缓存

$AOS_K8S_PATH/bin/refresh_nginx.sh

#创建快捷目录访问

$AOS_K8S_PATH/bin/create_link.sh

#测试登录页面是否正常

$AOS_K8S_PATH/bin/login_test.sh

echo "-----------All Finish Successfully-------------------"

你可能感兴趣的:(范例:部署ms.sh)