定时检测并启动服务

15 篇文章 0 订阅

(一) start all server

[lvhongmin@AY1401201736089361adZ start_svr]$ cat check_star_all_svr 

#!/bin/bash

errpath[0]=''
errnum=0
runnum=0
curr_path=`pwd`

#进程的名字

array[${#array[*]}]=/home/lvhongmin/bin/bin.gatemaster/check_lhm_proxy
slp[${#slp[*]}]=5  
array[${#array[*]}]=/home/lvhongmin/bin/bin.connect/check_lhm_proxy
slp[${#slp[*]}]=2
array[${#array[*]}]=/home/lvhongmin/bin/bin.ss.hall/check_lhm_proxy
slp[${#slp[*]}]=2
array[${#array[*]}]=/home/lvhongmin/bin/bin.cornucopia/check_lhm_proxy
slp[${#slp[*]}]=1
array[${#array[*]}]=/home/lvhongmin/bin/bin.ddz.match/check_lhm_proxy
slp[${#slp[*]}]=1
array[${#array[*]}]=/home/lvhongmin/bin/bin.ddz.pt/check_lhm_proxy
slp[${#slp[*]}]=1
array[${#array[*]}]=/home/lvhongmin/bin/bin.horse/check_lhm_proxy
slp[${#slp[*]}]=1
array[${#array[*]}]=/home/lvhongmin/bin/bin.hsz.pt/check_lhm_proxy
slp[${#slp[*]}]=1
array[${#array[*]}]=/home/lvhongmin/bin/bin.jpwl.pt/check_lhm_proxy
slp[${#slp[*]}]=1
array[${#array[*]}]=/home/lvhongmin/bin/bin.lzddz.pt/check_lhm_proxy
slp[${#slp[*]}]=1
array[${#array[*]}]=/home/lvhongmin/bin/bin.pklottery/check_lhm_proxy
slp[${#slp[*]}]=1
array[${#array[*]}]=/home/lvhongmin/bin/bin.six/check_lhm_proxy
slp[${#slp[*]}]=1
array[${#array[*]}]=/home/lvhongmin/bin/bin.record.lhm/check_lhm_proxy
slp[${#slp[*]}]=1
array[${#array[*]}]=/home/lvhongmin/bin/bin.paiyou/check_lhm_proxy
slp[${#slp[*]}]=1

#declare -a array
len=${#array[*]}
echo "server num=" $len

for((i=0; i<$len;i++ ))
do
#  echo ${array[$i]}
  exen=${array[$i]}
  slpnum=${slp[$i]}
  if [ -f $exen  ]; then
#       echo  ${exen} '  >> ' $slpnum
#       fpath=${exen%/*}
#       echo $fpath 
#       cd $fpath
       ${exen}
       sleep $slpnum
       runnum=`expr $runnum + 1`
   else
       echo '  --' $exen
       errpathn[$unnum]=$exen    
       errnum=`expr $errnum + 1`   
   fi
done

bb=$(date +%Y%m%d_%H_%M_%S)
cd $curr_path
echo ""
echo "running :" ${runnum} "   " ${bb}
echo "no server:" ${errnum} "  " ${bb}

(二)restart_proxy

[lvhongmin@AY1401201736089361adZ bin.gatemaster]$ cat restart_proxy
#!/bin/bash
exemake=gatemaster.svr
exe=lhm.gatemaster.svr
curr_path=`pwd`
cd $curr_path

#checke exe file exist
if [ ! -f $exe  ]; then
        if [ -f $exemake  ]; then
                cp $exemake $exe
        else
                echo "error:no exe ..."
                exit 0
        fi
else
        if [ -f $exemake  ]; then
                cp $exemake $exe
        fi
fi

sleep 1
log_path=log.back
curr_path=`pwd`
killall -9 -q $exe
sleep 2

if [ ! -d $log_path  ] ; then
        mkdir $log_path
        sleep 1
fi

#the time stamp
bb=$(date +%Y%m%d_%H_%M_%S)
#new log full path
log_full_path=$log_path/$bb
mkdir $log_full_path

log=$exe.log
elog=$exe.err

if [ -f $log  ]; then
         echo "uncopy gatemaster log"
        #cp $log $log_full_path
fi

if [ -f $elog  ]; then
        cp $elog $log_full_path
fi

nohup $curr_path/$exe 2>$elog >$log &

if [ $# -ge 1 ]; then
        if [ $1="showlog" ] ; then
                echo "sholog .."
                tail -f $log
        fi
fi

#END

(三)check_lhm_proxy

[lvhongmin@AY1401201736089361adZ bin.gatemaster]$ cat check_lhm_proxy 
#/usr/bin
exen=lhm.gatemaster.svr
INFO=`ps afux | grep "${exen}" | grep -v "grep"`

#若进程不存在,则启动该进程 -z为空时返回真

bb=$(date +%Y%m%d_%H_%M_%S)
if [ -z "$INFO" ]; then
   cd /home/lvhongmin/bin/bin.gatemaster
   echo "${exen} starts at " ${bb}

   /home/lvhongmin/bin/bin.gatemaster/restart_proxy  
else
   echo "${exen} is running " ${bb}
fi 

(四)定时检测

[lvhongmin@AY1401201736089361adZ start_svr]$ crontab -l


*/5 5-7 * 7 * /home/lvhongmin/start_svr/check_start_all_svr >/home/lvhongmin/start_svr/start.log 2>&1




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值