[root@SOA ~]# more monitor.sh
#!/bin/bash
P1=`ping -c1 192.168.2.115 |grep 192.168.2.115 |grep -c ttl`
if [ "$P1" == "1" ];then
echo "2.115 is active"
mem=`ssh 192.168.2.115 'ps -ef|grep memcached |grep "${mm_ports[$i]}"|grep -v grep|wc -l'`
admin=`ssh 192.168.2.115 'ps -ef|grep tomcat-admin |grep "${mm_ports[$i]}"|grep -v grep|wc -l'`
if [ "$admin" == "1" -a "$mem" == "1" ];then
echo "all services is running"
elif [ "$admin" == "0" -a "$mem" == "1" ];then
echo "tomcat-admin is down,memcache is up"
cd /ServyouAPP/tomcat-admin/bin
nohup ./catalina.sh run &
tail -20 nohup.out
elif [ "$admin" == "1" -a "$mem" == "0" ];then
echo "tomcat-admin is UP,memcache is DOWN"
echo "replace 2.115 memcache-config-file"
echo "startup 2.135 memcache"
sh /memStartUp.sh
#sh 192.168.2.115 /relace.sh
#ssh 192.168.2.115 'sh tomcatStop.sh'
kill -9 `ps aux|grep java|grep -v grep|awk '{print $2}'`
ssh 192.168.2.115 'sh /tomcatStart.sh'
sleep 20
sh replace.sh
kill -9 `ps aux|grep java|grep -v grep|awk '{print $2}'`
sh '/tomcatStart.sh'
elif [ "$admin" == "0" -a "$mem" == "0" ];then
echo "all service is down "
echo "replace 2.115 memcache-config-file"
echo "startup 2.135 memcache"
sh /memStartUp.sh
sh 192.168.2.115 '/relace.sh'
#ssh 192.168.2.115 'sh tomcatStop.sh'
ssh 192.168.2.115 'kill -9 `ps aux|grep java|grep -v grep|awk '{print $2}'`'
ssh 192.168.2.115 'sh /tomcatStart.sh'
sleep 20
sh replace.sh
kill -9 `ps aux|grep java|grep -v grep|awk '{print $2}'`
sh '/tomcatStart.sh'
echo "service is STOP!"
fi
else
echo " 2.115 is NOT ACTIVE "
#ssh 192.168.2.115 'sh tomcatStop.sh'
ssh 192.168.2.115 'kill -9 `ps aux|grep java|grep -v grep|awk '{print $2}'`'
ssh 192.168.2.115 'sh /tomcatStart.sh'
sleep 20
sh replace.sh
kill -9 `ps aux|grep java|grep -v grep|awk '{print $2}'`
sh '/tomcatStart.sh'
fi
监控memcache tomcat脚本
最新推荐文章于 2024-09-15 16:27:40 发布