检测nginx服务中断并自动启动脚本

 if ps aux | grep 'nginx' | grep -v grep  > /dev/null ; then

            echo "nginx is runnning !"    
    else
            echo "nginx is down. Starting over..."
            /etc/init.d/nginx start
    fi

将此脚本保存为nginx-running.sh

检测php-cgi服务中断并自动启动脚本

if ps aux | grep 'php-cgi' | grep -v grep  > /dev/null ; then

            echo "PHP-cgi is runnning !"    
    else
            echo "PHP-cgi is down. Starting over..."
            /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u nginx -g nginx -f /usr/bin/php-cgi -P /var/run/fastcgi-php.pid
    fi

将此脚本保存为phpcgi-running.sh

在crontab加入每分钟检测一次计划即可