apiVersion: v1
kind: ConfigMap
metadata:
  name: mysql-mgr-2-cnf
  namespace: edoc2
data:
  mysql-mgr-2.cnf: |
    [mysqld]
    pid-file = /var/run/mysqld/mysqld.pid
    socket = /var/run/mysqld/mysqld.sock
    datadir = /var/lib/mysql
    log-error = /var/lib/mysql/error.log
    secure-file-priv= NULL
    symbolic-links=0
    bind-address=0.0.0.0
    default_authentication_plugin=mysql_native_password
    skip-host-cache
    skip-name-resolve
    sql_mode=NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
    default-storage-engine=INNODB
    character-set-server=utf8mb3
    log_bin_trust_function_creators=1
    performance_schema=ON
    collation-server=utf8_general_ci
    default-time-zone='+8:00'
    log_timestamps=SYSTEM
    server_id=3
    gtid_mode=ON
    enforce_gtid_consistency=ON
    master_info_repository=TABLE     
    relay_log_info_repository=TABLE 
    binlog_checksum=NONE
    log_slave_updates=ON
    log_bin=binlog
    read_only=on
    binlog_format=ROW
    transaction_write_set_extraction = XXHASH64
    report_host='mysql-mgrc-0.mysql-mgrc.edoc2.svc.cluster.local'
    plugin-load = "group_replication.so"
    group_replication_consistency= 'BEFORE_ON_PRIMARY_FAILOVER'
    group_replication_start_on_boot = off
    group_replication_bootstrap_group = off 
    group_replication_group_name="f6b40de0-697d-4a0c-af1c-5748730984ab"
    group_replication_local_address="mysql-mgrc-0.mysql-mgrc.edoc2.svc.cluster.local:33061"
    group_replication_group_seeds="mysql-mgra-0.mysql-mgra.edoc2.svc.cluster.local:33061,mysql-mgrb-0.mysql-mgrb.edoc2.svc.cluster.local:33061,mysql-mgrc-0.mysql-mgrc.edoc2.svc.cluster.local:33061"
    group_replication_ip_whitelist = '0.0.0.0/0'
    group_replication_single_primary_mode=FALSE
    group_replication_single_primary_mode = on
    group_replication_enforce_update_everywhere_checks = off
    group_replication_member_weight = 48
    group_replication_transaction_size_limit=2147483647
    group_replication_unreachable_majority_timeout = 300
    group_replication_autorejoin_tries = 144
    group_replication_flow_control_applier_threshold = 100000
    group_replication_flow_control_certifier_threshold = 100000
    group_replication_flow_control_hold_percent = 10
    group_replication_flow_control_mode = DISABLED
    slave_parallel_type = LOGICAL_CLOCK
    slave_parallel_workers = 8
    slave_preserve_commit_order = 1
    #innodb
    innodb_buffer_pool_size = 4G
    innodb_buffer_pool_instances = 4
    innodb_log_buffer_size = 256M
    innodb_read_io_threads = 8
    innodb_write_io_threads = 8
    innodb_io_capacity=1000
    innodb_io_capacity_max = 10000
    innodb_log_file_size = 512M
    innodb_log_files_in_group = 2
    innodb_log_buffer_size = 32M
    innodb_file_per_table = true
    innodb_flush_log_at_trx_commit=1
    sort_buffer_size = 8M
    join_buffer_size = 8M
    binlog_cache_size = 4M
    thread_cache_size = 32
    bulk_insert_buffer_size = 16M
    read_buffer_size = 2M
    read_rnd_buffer_size = 8M
    sync_binlog=0
    slow_query_log=1
    long_query_time=3
    key_buffer_size=256M
    binlog_expire_logs_seconds=1209600
    lower_case_table_names = 1
    max_connections = 10000
    [client]
    default-character-set=utf8mb3
    [mysql]
    default-character-set = utf8mb3
    [mysql.server]
    default-character-set = utf8mb3
    [mysqld_safe]
    default-character-set = utf8mb3
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: mysql-mgr-2-sh
  namespace: edoc2
data:
  mysql-shell-2.sh: |
    #!/bin/bash
    if [ -f /var/lib/mysql/running ];then
        sleep 35
        MYSQL_REPL_USER=`echo $MYSQL_REPL_USER`
        MYSQL_REPL_PASSWORD=`echo ${MYSQL_REPL_PASSWORD}`
    else
        sleep 35
        MYSQL_REPL_USER=`echo $MYSQL_REPL_USER`
        MYSQL_REPL_PASSWORD=`echo ${MYSQL_REPL_PASSWORD}`
        mysql -e "set sql_log_bin=0;flush privileges;"
        mysql -e "set sql_log_bin=0;create user '$MYSQL_REPL_USER'@'%' identified by '$MYSQL_REPL_PASSWORD';flush privileges;"
        mysql -e "set sql_log_bin=0;GRANT ALL ON *.* TO 'repl'@'%' WITH GRANT OPTION;flush privileges;"
        mysql -e "set sql_log_bin=0;grant replication slave on *.* to 'repl'@'%';flush privileges;"
        mysql -e "set sql_log_bin=0;ALTER USER '$MYSQL_REPL_USER'@'%' IDENTIFIED BY '$MYSQL_REPL_PASSWORD';flush privileges;"
        mysql -e "set sql_log_bin=0;create user 'root'@'%' identified by '$MYSQL_ROOT_PASSWORD';"
        mysql -e "set sql_log_bin=0;GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION;"
        mysql -e "set sql_log_bin=0;alter user 'root'@'localhost' identified by '$MYSQL_ROOT_PASSWORD';flush privileges;"
        touch /var/lib/mysql/running
    fi
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: mysql-2-sh
  namespace: edoc2
data:
  mysql2.sh: |
    #!/bin/bash
    localhost=mysql-mgrc-0.mysql-mgrc.edoc2.svc.cluster.local
    hostname=mysql-mgrc-0.mysql-mgrc.edoc2.svc.cluster.local
    mysql0=mysql-mgra-0.mysql-mgra.edoc2.svc.cluster.local
    mysql1=mysql-mgrb-0.mysql-mgrb.edoc2.svc.cluster.local
    mysql2=mysql-mgrc-0.mysql-mgrc.edoc2.svc.cluster.local
    exec_sql() {
      mysql -u${MYSQL_REPL_USER} -p${MYSQL_REPL_PASSWORD} -h${1} -N -e "$2" 2>/dev/null
    }
    while true;do
        if exec_sql ${localhost} "SELECT 1" ; then
            break
        fi
        echo "wait for mysql start"
        sleep 3
    done
    boot_sql() {
        mysql -u$MYSQL_REPL_USER -p$MYSQL_REPL_PASSWORD -e "SET GLOBAL group_replication_bootstrap_group=ON;"
        mysql -u$MYSQL_REPL_USER -p$MYSQL_REPL_PASSWORD -e "START GROUP_REPLICATION;"
        mysql -u$MYSQL_REPL_USER -p$MYSQL_REPL_PASSWORD -e "SET GLOBAL group_replication_bootstrap_group=OFF;"
    }
    restart_sql() {
        mysql -u$MYSQL_REPL_USER -p$MYSQL_REPL_PASSWORD -e "CHANGE MASTER TO MASTER_USER='${MYSQL_REPL_USER}', MASTER_PASSWORD='${MYSQL_REPL_PASSWORD}' FOR CHANNEL 'group_replication_recovery';"
        mysql -u$MYSQL_REPL_USER -p$MYSQL_REPL_PASSWORD -e "start group_replication;"
    }
    start_group_replication() {
        if exec_sql ${mysql0} "SELECT * from performance_schema.replication_group_members" |grep "ONLINE" &> /dev/null || exec_sql ${mysql1} "SELECT * from performance_schema.replication_group_members" |grep "ONLINE" &> /dev/null ;then
            restart_sql && echo "Settings replication recovery complete."
        else
            TMPFILE=$(mktemp) || exit 1
            for H in ${mysql0} ${mysql1} ${mysql2}
            do
                exec_sql $H "SELECT * from database_info.replication_info where member_role=0 order by be_primary_date desc limit 1" >> ${TMPFILE}
            done
            LAST_HOST=$(sort -r -t ' ' -k 3 ${TMPFILE} | head -n 1  |  awk '{print $1}') && rm -f ${TMPFILE}
            if [ "$LAST_HOST" = "${hostname}" ];then
                boot_sql && echo "The current node is the last primary node.Start group replication success."
            else
                while true;do
                    if exec_sql ${mysql0} "SELECT * from performance_schema.replication_group_members" |grep "ONLINE" &> /dev/null || exec_sql ${mysql1} "SELECT * from performance_schema.replication_group_members" |grep "ONLINE" &> /dev/null ;then
                        echo "Last primary node is ${LAST_HOST}.Set replication recovery."
                        restart_sql && break
                    else
                        echo "Wait last primary node ${LAST_HOST} start..."
                        sleep 5
                        continue
                    fi
                done
            fi
        fi
    }
    first_start_group_replication() {
        #exec_sql localhost "${boot_sql}"
        #sleep 5
        #exec_sql localhost "${init_replication_tb_sql}"
        while true;do
            if exec_sql ${mysql0} "SELECT * from performance_schema.replication_group_members" |grep "ONLINE" &> /dev/null ;then
                restart_sql
                break
            else
                echo "Wait ${mysql0} start."
                sleep 5
                continue
            fi
        done
    }
    check_self_status(){
        exec_sql ${localhost} "SELECT * FROM performance_schema.replication_group_members" |grep ${hostname} | awk '{print $5}'
    }
    main() {
        if exec_sql ${localhost} "select * from database_info.replication_info" &>/dev/null ;then
            start_group_replication
            for ((i=0;i<=5;i++))
            do
                if [ $(check_self_status) = "ONLINE" ];then
                    break
                else
                    sleep 15
                    start_group_replication
                fi
            done
        else
            first_start_group_replication
        fi
        exec /opt/mysql_config/generate_last_time.sh &> /dev/null &
    }
    check_group_replication(){
        while true;do
            sleep 60
            ONLINE_NUM=$("${mysqlcon[@]}" -e 'SELECT * FROM performance_schema.replication_group_members' |grep "ONLINE" 2> /dev/null | wc -l)
            if [ ${ONLINE_NUM} -lt 2 ];then
                "${mysqlcon[@]}" -e 'SET GLOBAL super_read_only=ON;' 
            else
                if [ $(${mysqlcon[@]} -e "show variables like 'super_read_only'\G" 2> /dev/null|grep Value|awk '{print $2}') = "ON" ];then
                    "${mysqlcon[@]}" -e 'SET GLOBAL super_read_only=OFF;SET GLOBAL read_only=OFF;'
                fi
            fi
        done
    }
    main
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: generate-2-sh
  namespace: edoc2
data:
  generate_last_time.sh: |
    #!/bin/bash
    localhost=mysql-mgrc-0.mysql-mgrc.edoc2.svc.cluster.local
    mysql0=mysql-mgra-0.mysql-mgra.edoc2.svc.cluster.local
    mysql1=mysql-mgrb-0.mysql-mgrb.edoc2.svc.cluster.local
    mysql2=mysql-mgrc-0.mysql-mgrc.edoc2.svc.cluster.local
    exec_sql() {
      mysql -u${MYSQL_REPL_USER} -p${MYSQL_REPL_PASSWORD} -h${1} -N -e "$2" 2>/dev/null
    }
    update_replication_info=
    read -r -d '' update_replication_info <<-EOSQL
        replace into database_info.replication_info values ("${mysql0}",0,"$(date +%s%3N)" )
    EOSQL
    while true;do
        HOST=mysql-mgrc-0.mysql-mgrc.edoc2.svc.cluster.local
        IsPri=$(exec_sql ${localhost} "SELECT CONCAT(MEMBER_ROLE,MEMBER_STATE) FROM performance_schema.replication_group_members where MEMBER_HOST='${HOST}'")
        PriNode=$(exec_sql ${localhost} "select MEMBER_HOST from performance_schema.replication_group_members where MEMBER_ROLE='PRIMARY'")
        if [ "$IsPri" = "PRIMARYONLINE" ] && [ "$(exec_sql ${localhost} "show variables like 'read_only'" | awk '{print $2}')"  = "OFF" ] ;then
            update_replication_info=
            read -r -d '' update_replication_info <<-EOSQL
                replace into database_info.replication_info values ("$HOST",0,"$(date +%s%3N)" )
    EOSQL
        else
            update_replication_info=
            read -r -d '' update_replication_info <<-EOSQL
                replace into database_info.replication_info values ("$HOST",1,"" )
    EOSQL
        fi
        exec_sql $PriNode "$update_replication_info"
        sleep 1
    done
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: mgr-2-check
  namespace: edoc2
data:
  mysql_status_check.sh: |
    #!/bin/bash
    localhost=mysql-mgrc-0.mysql-mgrc.edoc2.svc.cluster.local
    mysqlcon=( mysql -h${localhost} -u${MYSQL_REPL_USER} -p${MYSQL_REPL_PASSWORD} )
    ONLINE_NUM=$(${mysqlcon[@]} -Ne 'SELECT * FROM performance_schema.replication_group_members;' 2> /dev/null |awk '{print $5}'|grep -E "ONLINE|RECOVERING" | wc -l)
    if [ "$(${mysqlcon[@]} -e 'SELECT * FROM performance_schema.replication_group_members;' 2> /dev/null |grep ${localhost} | awk '{print $5$6}')" = "ONLINEPRIMARY" ] && [ $(${mysqlcon[@]} -e "show variables like 'read_only'\G" 2> /dev/null|grep Value|awk '{print $2}') = "OFF" ] && [ $ONLINE_NUM -ge 2 ];then
        /bin/echo -e "HTTP/1.1 200 OK\r\n"
    else
        /bin/echo -e "HTTP/1.1 503 Service Unavailable\r\n"
    fi
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: mgr-2-slowquery
  namespace: edoc2
data:
  slow_query.sh: |
    #!/bin/bash
    localhost=mysql-mgrc-0.mysql-mgrc.edoc2.svc.cluster.local
    getApiInfo() {
        category=$1
        getApiValue=$(curl -s http://${APM:=apm}/api/systemconfig/getMySQLSwitch | jq ".data.${category}" | sed 's/"//g')
    }
    changeSlowSet() {
        getApiInfo mySQLLongTimeValue
        slowLongTimeValueSet=${getApiValue}
        mysqlcon="mysql -h${localhost} -u${MYSQL_REPL_USER} -p${MYSQL_REPL_PASSWORD} "
        slowLongTimeValue=$(${mysqlcon} -N -e 'SHOW VARIABLES LIKE "long_query_time";' | awk '{print $2}')
        if [ $(awk -v num1=${slowLongTimeValue} -v num2=${slowLongTimeValueSet} 'BEGIN{print(num1!=num2)?"0":"1"}') -eq 0 ];then
          ${mysqlcon} -N -e "SET GLOBAL long_query_time=${slowLongTimeValueSet};"
          echo "Modify the value of long_query_time. Before is ${slowLongTimeValue}.Set is ${slowLongTimeValueSet}."
        fi
    }
    slowQueryColl() {
        HOSTNAME="mysql-mgrc-0.mysql-mgrc.edoc2.svc.cluster.local"
        USER='anemometer'
        PASSWORD='anemometer@edoc2'
        ANEMOMETER_SERVER=anemometer
        MYSQLDIR=/var/lib/mysql
        SLOW_LOG_NAME=${HOSTNAME}-slow.log
        SLOW_LOG=${MYSQLDIR}/${SLOW_LOG_NAME}
        SLOW_LOG_BAK=${MYSQLDIR}/${SLOW_LOG_NAME}.bak
        DATE="`date "+%Y-%m-%d %H:%M"`"
        pt-query-digest --user=${USER} --password=${PASSWORD}  \
                        --review h=${ANEMOMETER_SERVER},D=slow_query_log,t=global_query_review  \
                        --history h=${ANEMOMETER_SERVER},D=slow_query_log,t=global_query_review_history  \
                        --no-report --limit=0%  --filter=" \$event->{Bytes} = length(\$event->{arg}) and \$event->{hostname}=\"${HOSTNAME}\"" ${SLOW_LOG}
        echo "###############################$DATE###################################" >> $SLOW_LOG_BAK
        cat $SLOW_LOG >> $SLOW_LOG_BAK
        :> $SLOW_LOG
    }
    while true
    do
        getApiInfo mySQLSwitch
        slowSwitch=${getApiValue}
        getApiInfo mySQLTimeSpan
        slowTimeSpan=${getApiValue}
        if [ -z $slowSwitch -a -z $slowTimeSpan ]; then
            sleep 30
        else
            if [ x"${slowSwitch}" == x"1" ]; then
                sleep ${slowTimeSpan}
                changeSlowSet
                slowQueryColl
            fi
        fi
    done
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: xtrabackup-sh2
  namespace: edoc2
data:
  xtrabackup.sh: |
    #!/bin/bash
    #This mysql backup scripts.
    sleep 120
    start_conn() {
        PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
        export PATH
        set -u
        dir="/dbbackup"
        user=`echo $MYSQL_REPL_USER`
        pass=`echo ${MYSQL_REPL_PASSWORD}`
        logfile="${dir}/xtra.log"
        HOST="middle-proxy"
        USE_MEM="1024m"
        IOPS=60
        HOSTNAME=`cat /etc/hosts | grep mysql | awk -F " " '{print $2}'`
        if [ ! -d $dir ]; then
            mkdir -p $dir
        fi
        database_type=$(exec_sql "SELECT CASE WHEN COUNT(PLUGIN_STATUS)=0 THEN 'standalone' \
            WHEN PLUGIN_STATUS='ACTIVE' THEN 'cluster'  END AS deploy_mode \
            FROM  INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME = 'group_replication';")
    }
    exec_sql() {
        mysql -u$user -p$pass -h$HOST -N -e "$1"
    }
    insert_result() {
        exec_sql "INSERT INTO database_info.backup_info VALUES ('',\"$1\", \"${HOSTNAME}\", \"$2\", \"$3\",\"$4\" , \"$5\", \"$6\")"
    }
    full_backup() {
        fulldir=`date +%Y-%m-%d-%H:%M:%S`-base
        cd $dir
        mkdir $fulldir
        echo "Full Backup Start Time: `date "+%Y-%m-%d %H:%M:%S"`" > $logfile
        echo "=============================" >> $logfile
        backup_time=$(echo $fulldir| awk -F'-base' '{print $1}'  | sed 's/-/ /3')
        backup_start=$(date +%s)
        xtrabackup  --throttle=$IOPS --use-memory=$USE_MEM \
        --user=$user --password=$pass --backup --extra-lsndir=$dir \
        --stream=xbstream --target-dir=$dir/$fulldir 2>>$logfile | gzip - > $dir/$fulldir/${fulldir}.gz
        RETVAL=$?
        backup_end=$(date +%s)
        backup_spend=$((backup_end - backup_start))
        backup_size=$(du -sh $dir/$fulldir | awk '{print $1}' )
            if [[ $RETVAL == 0 ]] && [[ `tail -50 "${logfile}" | egrep -ic "\berror\b|\bfailed\b"` == 0 ]]; then
                echo "" >> $logfile
                echo "=============================" >> $logfile
                echo "Full Backup Sucess!!: `date`" >> $logfile
                insert_result "$backup_time" full $database_type $backup_spend sucess $backup_size
                return 0
            else
                echo "" >> $logfile
                echo "=============================" >> $logfile
                echo "Full Backup Failed!!: `date`" >> $logfile
                insert_result "$backup_time" full $database_type 0 failed 0
                return 1
            fi
    }
    incremental() {
        cd ${dir}
        incdir=`date +%Y-%m-%d-%H:%M:%S`-inc
        mkdir $incdir
        LAST_CHECKPOINT=`awk '/to_lsn/{print $3}' ${dir}/xtrabackup_checkpoints 2>/dev/null`
        if [ ! -e "${dir}/xtrabackup_checkpoints" ]; then
            echo "error: xtrabackup_checkpoints does not exist!!" > $logfile
            exit 1
        fi
        echo "Incremental Backup Start Time: `date "+%Y-%m-%d %H:%M:%S"`" > $logfile
        echo "=============================" >> $logfile
        backup_time=$(echo $incdir | awk -F'-inc' '{print $1}' | sed 's/-/ /3')
        backup_start=$(date +%s)
        xtrabackup  --throttle=$IOPS --use-memory=$USE_MEM \
        --user=$user --password=$pass --backup --incremental-lsn=$LAST_CHECKPOINT --extra-lsndir=$dir/$incdir \
        --stream=xbstream --target-dir=$dir/$incdir 2>$logfile | gzip - > $dir/$incdir/${incdir}.gz
        RETVAL=$?
        backup_end=$(date +%s)
        backup_spend=$((backup_end - backup_start))
        backup_size=$(du -sh $dir/$incdir | awk '{print $1}' )
        if [[ $RETVAL == 0 ]] && [[ `tail -50 "${logfile}" | egrep -ic "\berror\b|\bfailed\b"` == 0 ]]; then
            rm -f ${dir}/xtrabackup_* && mv ${dir}/${incdir}/xtrabackup_* ${dir}/
            echo "MySql Incremental Backup Success: $(date)" >> $logfile
            insert_result "$backup_time" incremental $database_type $backup_spend sucess $backup_size
        else
            echo "MySql Incremental Backup Failure: $(date)" >> $logfile
            insert_result "$backup_time" incremental $database_type 0 failed 0
        fi
    }
    # Create record database and table
    record_database_and_table() {
        exec_sql "CREATE DATABASE IF NOT EXISTS database_info;"
        exec_sql "CREATE TABLE IF NOT EXISTS database_info.backup_info( \
            id INT AUTO_INCREMENT, \
            backup_time datetime, \
            backup_host VARCHAR(20), \
            backup_type set('full','incremental','logic-back'),\
            database_type set('standalone','cluster','ms'), \
            backup_spend INT(20), \
            backup_result VARCHAR(10), \
            backup_size VARCHAR(40), \
            PRIMARY KEY (id) \
           ) ENGINE=InnoDB ;"
    }
    start_backup(){
        record_database_and_table
        if [ `date +%u` -eq 1  ]; then
            full_backup
            if [ $? -eq 0 ];then
                find $dir -maxdepth 1 -type d -mtime +14 -exec rm -rf {} \;
            fi
        else
            if [ ! "$(find $dir/* -type d -mmin -1500)" ]; then
                full_backup
            else
                incremental
            fi
        fi
    }
    cluster_back(){
        db_role=$(exec_sql "select MEMBER_ROLE  from performance_schema.replication_group_members where MEMBER_HOST=\"${HOSTNAME}\"")
        if [ "$db_role" = "PRIMARY" ]; then
            start_backup
        else
            echo "The database role is slave,no backup."
        fi
    }
    main() {
        if [ "$database_type" = "standalone" ]; then
            start_backup
        elif [ "$database_type" = "cluster" ];then
            cluster_back
        else
            db_read_only=$(exec_sql "show variables like 'read_only'")
            if [ "${db_read_only}" == "OFF" ]; then
                start_backup
            fi
        fi
    }
    while true;do
        sleep 5
        curTime=$(date "+%H%M")
        if [ "$curTime" == "0010" ];then
            start_conn
            sleep 1
            echo $curTime
            main
        else
            echo "not exec"
        fi
        sleep 40
    done
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: mgr-health-sh2
  namespace: edoc2
data:
  mgrhealth2.sh: |
    #!/bin/bash
    mysqlserver="mysql-mgrc-0.mysql-mgrc.edoc2.svc.cluster.local"
    status=`mysql -h${mysqlserver} -u${MYSQL_REPL_USER} -p${MYSQL_REPL_PASSWORD} -Ne 'SELECT * FROM performance_schema.replication_group_members;' | grep mysql-mgrc-0.mysql-mgrc.edoc2.svc.cluster.local | awk -F " " '{print $5}'`
    rm -rf /opt/mgr_health-c.txt
    if [ "${status}" == "ONLINE" ] || [ "${status}" == "RECOVERY" ] || [ "${status}" == "RECOVERING" ];then
        echo "0" > /opt/mgr_health-c.txt
    else
        rm -rf /opt/mgr_health-c.txt
    fi
    cat /opt/mgr_health-c.txt
