#!/bin/sh
killall mon #杀死监控,monitor
ps aux | grep ./mon$ |grep -v grep |awk '{print $2}' | xargs kill -9 #获得进程id,kill,确保正确
killall serv #杀死服务
sleep 60
cd /home/work/serv
nohup ./server & #启动服务
while true
do
server=`ps aux | grep ./tac |grep -v grep |awk '{print $2}'` #获取进程id
echo $server
if [ -z "$server" ]; then #判断进程是启动
echo "server is null"
sleep 10
nohup ./server & #再次启动
else
echo "server = $server" #输出成功提示,退出
break
fi
done
#判断监控是否启动,若没有,手动启动,mon在crontab中设定,每2分钟启动,所以这步不是很必要
#监控启动时间频繁可能造成server正在启动时候报警,因此,根据自己需求设定crontab
mon=`ps aux | grep ./mon$ |grep -v grep |awk '{print $2}'`
if [ -z "$mon" ]
then
cd /home/work/mon
./mon
else
continue
fi
阅读(775) | 评论(0) | 转发(0) |