自动判断NGINX和php-cgi状态重启SHELL脚本

NGINX

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/bash    
#*/3 * * * * /data/shell/nginx.sh  > /dev/null 2>&1
PROG=/usr/local/nginx/sbin/nginx    
LOG=/root/nginx.log    
time=`date`    
status=$(curl -s --head "$url" | awk '/HTTP/ {print $2}')    
if [ "$status" != "200" ]; then   
     echo "Restart nginx at ${time} " >> $LOG    
     killall nginx    
     $PROG    
     echo "HTTP stauts: ${status} time:$time" | /bin/mail -s "HTTP [nginx80] status check" ${maillist}    
              
fi

php-fpm

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/bash    
#*/3 * * * * /usr/local/sbin/restart_php.sh  > /dev/null 2>&1
PROG=/usr/local/php5.2.17/sbin/php-fpm    
LOG=/tmp/php-cgi.log    
time=`date`    
status=$(curl -s --head "$url" | awk '/HTTP/ {print $2}')    
if [ "$status" != "200" ]; then   
     echo "Restart php-cgi at ${time} " >> $LOG    
     $PROG restart    
     echo "HTTP stauts: ${status} time:$time" | /bin/mail -s "HTTP [restart_php] status check" ${maillist}    
              
fi

Tagged: , ,

Comments are closed.