CentOS7脚本检测Redis/Nginx宕机并自动重启

 1、Redis宕机检测并自动重启

#!/bin/sh

while true
do

A=`ps -C redis-server --no-header | wc -l`
if [ $A -eq 0 ];then
    echo $(date +%F%n%T) "redis未启动,启动redis..."
    systemctl start redis
    sleep 10
else
    echo $(date +%F%n%T) "redis正在运行..."
fi

sleep 5
done

2、Nginx宕机检测并自动重启

#!/bin/sh

while true
do
A=`ps -C nginx --no-header | wc -l`
if [ $A -eq 0 ];then    
    echo $(date +%F%n%T) "nginx未启动,启动nginx..."
    systemctl start nginx    
    sleep 10
else
    echo $(date +%F%n%T) "nginx正在运行..."
fi

sleep 5
done

 

你可能感兴趣的:(CentOS7,Redis,宕机检测,自动重启,Nginx,CentOS)