bm-cdn管理脚本

bm-cdn管理脚本

[root@ansible-server-xxxtyt shell]# cat xxxtyt_cdn_management.sh 
#!/bin/bash
# Author : royoy
# Date   : 07/2019
# LMod   : 10/2019
# Desc   : check,open,close cdn for xxxtyt

salt_bin="/bin/salt"
front_nodeG_name="front_web"
cdn_conf="/data/shell/cdn_config/cdn_domainName.property"
cdn_opt="$1"
domainName="${2:-`awk -F= '/^domainName.*=/{print $2;exit}' $cdn_conf`}"

##检查需要的配置文件是否存在
if [ ! -s $cdn_conf ];then echo "$cdn_conf not exist";exit 11;fi

exec_module(){
        ## 1.同步生产cdn域名到本地$cdn_conf,以保持$cdn_conf配置里的域名和生产一致
        /data/shell/cdn_config/rsync_domainName_to_local.sh || exit $?

        ## 检查当前cdn域名开启或关闭状态功能模块
        [ "x$1" = "xcheck_cdn" ] && {
                /data/shell/cdn_config/check_cdn_stat.sh || exit $?

        ## 开启和关闭cdn功能模块
        } || {
                ## 2.同步生产var.php到本台机器
                /data/shell/cdn_config/get_config_to_local.sh &>/dev/null || exit 25

                ## 3.根据选项判断,修改为开启或关闭cdn的功能
                /data/shell/cdn_config/cdn_open_close.sh "$1" "$domainName" &>/dev/null || exit 39

                ## 4.同步'开启或关闭cdn功能'后的var.php配置文件到生产节点组(可以根据需要修改节点组,默认为4台前台web)
                /data/shell/cdn_config/push_config_to_product.sh &>/dev/null && {
                        font -d "域名为: [" -cyan "$domainName" -reset "] 的生产 CDN : " -green "已`[ ${#1} -eq 8 ] && font "开启" || font "关闭"`" -reset -n
                } || exit 36
        }
}

# Interactive mode
while [[ $# -eq 0 ]]
do
        stty erase ^H
        font "Please input an option for CDN of xxxtyt: (c|check) ( o|open ) ( d|close ) ( q|e|quit|exit )" -n
        read OPTARG
        case $OPTARG in
                check|c)
                        exec_module "check_cdn"
                        ;;
                open|o)
                        exec_module "open_cdn"
                        ;;
                close|d)
                        exec_module "close_cdn"
                        ;;
                exit|quit|q|e)
                        exit
        esac
done

# Auto mode
[[ "check_cdn open_cdn close_cdn" =~ "$cdn_opt" ]] && exec_module "$cdn_opt"


以上脚本用到的cdn域名属性配置文件
cat cdn_domainName.property 
##Don't delete the file
domainName=img.longgaoyun.com