[root@hechaojie monitor]# cat process.sh
#!/bin/sh
ctime=`date +%Y-%m-%d\ %H:%S:%S`
server_name=hechaojie
server_dir=/data/$server_name/tomcat
echo $ctime' 监听服务运行状态,'$server_name
function checkserver(){
count=`ps -ef |grep $2 |grep -v "grep" |wc -l`
echo '服务数:'$count
if [ 0 == $count ];then
echo $1'已停止,正在启动...'
#source /data/shell/killprocess.sh $1
echo '启动完毕,3s启动server'
sleep 3
source /data/$1/deploy/start.sh
count=`ps -ef |grep $2 |grep -v "grep" |wc -l`
echo '启动完成,服务数:'$count
fi
return $count
}
checkserver $server_name $server_dir
2.crontab定时任务扫描
*/2 * * * * source /etc/profile && sh /data/shell/monitor/process.sh >> /var/log/process.log