MSC服务器-主从检测脚本-check_server_state.sh

时间:2022-03-02 01:55:11

说明:

发现keepalived会在凌晨自动进行主从切换,导致msc相关进程运行不稳定;

通过运行check_server_state.sh,及时终止/启动相关进程;

所有脚本使用supervisord进行管理;

使用smon管理supervisor

#!/bin/bash

msc_vip="10.108.144.6"
check_log="/var/log/sunlight/check_server_state.log"

check_vip=$(ip addr | grep $msc_vip | wc -l)

function print_date()
{
  echo `date "+%Y/%m/%d %H:%M:%S"`
}

while true
do
echo "-------------------------------------------------------------"
#master
if [ $check_vip -eq 1 ];then
  echo "[ info ] $(print_date) Server is in master state......"

  check_gslb=$(ps -ef | grep "gslb_server" | grep -v grep | wc -l)
  echo "[ info ] $(print_date) check_gslb number : $check_gslb"
  if [ $check_gslb -lt 1 ];then
    /usr/local/sunlight/cdn/gslb/bin/startup.sh
  fi

  check_gnm=$(ps -ef | grep "gnm_server" | grep -v grep | wc -l)
  echo "[ info ] $(print_date) check_gnm number : $check_gnm"
  if [ $check_gnm -lt 1 ];then
    /usr/local/sunlight/cdn/gnm/bin/startup.sh
  fi

  check_nm=$(ps -ef | grep -E "\bnm_server" | grep -v grep | wc -l)
  echo "[ info ] $(print_date) check_nm number : $check_nm"
  if [ $check_nm -lt 1 ];then
    /usr/local/sunlight/cdn/nm/bin/startup.sh
  fi

  check_vms=$(ps -ef | grep vms_server | grep -v grep | wc -l)
  echo "[ info ] $(print_date) check_vms number : $check_vms"
  if [ $check_vms -lt 1 ];then
    /usr/local/sunlight/cdn/vms/bin/startup.sh
  fi

fi

#slave
if [ $check_vip -ne 1 ];then
  echo "[ info ] $(print_date) Server is in slave state......"

  check_gslb=$(ps -ef | grep "gslb_server" | grep -v grep | wc -l)
  echo "[ info ] $(print_date) check_gslb number : $check_gslb"
  if [ $check_gslb -gt 0 ];then
    /usr/local/sunlight/cdn/gslb/bin/shutdown.sh
  fi

  check_gnm=$(ps -ef | grep "gnm_server" | grep -v grep | wc -l)
  echo "[ info ] $(print_date) check_gnm number : $check_gnm"
  if [ $check_gnm -gt 0 ];then
    /usr/local/sunlight/cdn/gnm/bin/shutdown.sh
  fi

  check_nm=$(ps -ef | grep -E "\bnm_server" | grep -v grep | wc -l)
  echo "[ info ] $(print_date) check_nm number : $check_nm"
  if [ $check_nm -gt 0 ];then
    /usr/local/sunlight/cdn/nm/bin/shutdown.sh
  fi

fi
sleep 60
done