云盒所有服务检查

#!/bin/bash
# 20180819
#云盒服务检查脚本

result_num=0
nginx_ssl="/xdfapp/server/nginx/conf/ssl"
gru_ssl="/xdfapp/apps/gru-absolute/conf/spearssl"
local_ip=`ip a |grep "scope global" |grep "enp2s0" |awk '{print $2}' |sed 's/\/.*//g'`

#ngin 服务检查
netstat -ntpl |grep -E ":11443" |grep LISTEN |grep nginx > /dev/null
[ $? -ne 0 ] && echo "1.nginx 服务未启动,请检查" && result_num=$[$result_num+1]
[ ! -d $nginx_ssl ] && echo "nginx 服务不支持 https,请检查" && result_num=$[$result_num+1]

#长连接服务检查
netstat -ntpl |grep -E ":30000" |grep LISTEN |grep java > /dev/null
[ $? -ne 0 ] && echo "2.长连接服务未启动,请检查" && result_num=$[$result_num+1]
grep -a monitor /xdfapp/logs/gru-absolute/server-info.log |grep gru-version |grep '7\.0' > /dev/null
[ $? -ne 0 ] && echo "gru-absolute 不是7.0版本,请检查" && result_num=$[$result_num+1]
if [ ! -d $gru_ssl ];then
  echo "长连接服务不支持https,请检查" && result_num=$[$result_num+1]
fi

#redis 服务检查
netstat -ntpl |grep -E ":6379" |grep redis > /dev/null
[ $? -ne 0 ] && echo "3.redis 服务未启动,请检查" && result_num=$[$result_num+1]

#dns 服务检查
dns_ip=`cat  /etc/dnsrecord.txt |awk '{print $1}' |head -1`
[ ${local_ip} != ${dns_ip} ] && echo "4./etc/dnsrecord.txt中的ip 和云盒ip 不一致,请检查" && result_num=$[$result_num+1]
grep $local_ip /etc/dnsmasq.conf > /dev/null
[ $? -ne 0 ] && echo "/etc/dnsmasq.conf 中的ip 和云盒ip 不一致,请检查" && result_num=$[$result_num+1]
netstat -ntpl |grep -E ":53|LISTEN" |grep dnsmasq > /dev/null
[ $? -ne 0 ] && echo "dns服务未启动,请检查" && result_num=$[$result_num+1]

#乐播服务检查
if [ -e /xdfapp/data/version/lebo ];then
  echo "乐播版本为:`cat   /xdfapp/data/version/lebo` OK"
else
  if [ -e /xdfapp/data/lebo_version ];then
    echo "乐播版本为:`cat /xdfapp/data/lebo_version`"
  else
    echo "乐播版本文件不存在,请检查"
  fi
fi
grep start_lebo.sh /var/spool/cron/crontabs/okay > /dev/null
[ $? -ne 0 ] && echo "5.乐播监控未启动,请检查" && result_num=$[$result_num+1]

#启动项服务检查是否有重复项
con_num=`cat /etc/rc.local | grep -v '#' |sort|uniq -c |awk '$1!=1{print $0}'|wc -l`
repeat_str=`cat /etc/rc.local | grep -v '#' |sort|uniq -c |awk '$1!=1{print $0}'`
if [ ${con_num} -ne 0 ];then
  result_num=$[$result_num+1] && echo "6.开机启动项有重复项,重复项为 ${repeat_str} 请检查"
fi

#开机启动项服务检查
start_str=`cat /etc/rc.local | grep -v '#' |sort|uniq -c`
echo $start_str |grep "gru-absolute" > /dev/null
[ $? -ne 0 ] && echo "长连接服务没有开启自启动,请检查" && result_num=$[$result_num+1]
echo $start_str |grep "change_route.sh" > /dev/null
[ $? -ne 0 ] && echo "路由脚本没有开启自启动,请检查" && result_num=$[$result_num+1]
echo $start_str |grep "startup_nginx.sh" > /dev/null
[ $? -ne 0 ] && echo "nginx没有开启自启动,请检查" && result_num=$[$result_num+1]
echo $start_str |grep "dnsmasq" > /dev/null
[ $? -ne 0 ] && echo "dnsmasq没有开启自启动,请检查" && result_num=$[$result_num+1]
echo $start_str |grep "supervisord" > /dev/null
[ $? -ne 0 ] && echo "supervisord没有开启自启动,请检查" && result_num=$[$result_num+1]
echo $start_str |grep "agent" > /dev/null
[ $? -ne 0 ] && echo "agent没有开启自启动,请检查" && result_num=$[$result_num+1]
echo $start_str |grep "cswitch" > /dev/null
[ $? -ne 0 ] && echo "cswitch没有开启自启动,请检查" && result_num=$[$result_num+1]

#计划任务服务检查是否有重复项
cron_start_str=`cat /var/spool/cron/crontabs/root | grep -v '#' |sort|uniq -c |awk '$1!=1{print $0}'|wc -l`
repeat_cron_str=`cat /var/spool/cron/crontabs/root | grep -v '#' |sort|uniq -c |awk '$1!=1{print $0}'`
if [ ${cron_start_str} -ne 0 ];then
  result_num=$[$result_num+1] && echo "7.定时任务有重复项,重复项为 ${repeat_cron_str} 请检查"
fi

#计划任务服务检查
cron_start_str=`cat /var/spool/cron/crontabs/root  |grep -v "#"`
echo $cron_start_str |grep  "pool.ntp.org" > /dev/null
[ $? -ne 0 ] && echo "时间同步未在定时任务里,请检查" && result_num=$[$result_num+1]
echo $cron_start_str |grep  "auto_cut_nginx_log.sh" > /dev/null
[ $? -ne 0 ] && echo "auto_cut_nginx_log.sh 未在定时任务里,请检查" && result_num=$[$result_num+1]
echo $cron_start_str |grep "clean_log.sh" > /dev/null
[ $? -ne 0 ] && echo "clean_log.sh 未在定时任务里,请检查" && result_num=$[$result_num+1]
echo $cron_start_str |grep "euler-client" > /dev/null
[ $? -ne 0 ] && echo "euler-client 未在定时任务里,请检查" && result_num=$[$result_num+1]


if [ $result_num -eq 0 ];then
  echo "云盒所有服务都正常!"
else
  echo "共 ${result_num}个问题,请检查"
fi

  

posted @ 2018-08-25 18:00  lixinliang  阅读(225)  评论(0编辑  收藏  举报