42121 发表于 2015-11-2 10:58:12

keepalive监控nginx

#!/bin/bash
while :
do
###process count
NGINX_COUNT=`ps -C nginx --no-header|wc -l`
KEEPALIVED_COUNT=`ps -C keepalived --no-header|wc -l`
#if [ $NGINX_COUNT -eq 0 ] && [ $KEEPALIVED_COUNT -eq 0 ];then
#   /etc/init.d/nginx restart && /etc/init.d/keepalived restart
if [ $NGINX_COUNT -eq 0 ] && [ $KEEPALIVED_COUNT -gt 0 ];then
   /etc/init.d/nginx restart
   sleep 3
   NGINX_COUNT=`ps -C nginx --no-header|wc -l`
   [ $NGINX_COUNT -eq 0 ] && /etc/init.d/keepalived stop
elif [ $NGINX_COUNT -gt 0 ] && [ $KEEPALIVED_COUNT -eq 0 ];then
      /etc/init.d/keepalived start
fi
sleep 5
done

页: [1]
查看完整版本: keepalive监控nginx