重启php-fpm如果进程意外死掉

#!/bin/sh
# */5 * * * * /var/www/php.sh >>  /var/www/php.log

php_fpm_count=$(ps aux | grep php-fpm | wc -l)
echo "php_fpm_count is $php_fpm_count"

if [ $php_fpm_count -lt 2 ]; then
    echo "Sorry, we have a problem with php-fpm! restart it"
    service php7.2-fpm restart
    chmod -R 777 /run/php # 如果使用sock,确保sock有执行权限
fi

*/5 * * * * /var/www/php.sh >> /var/www/php.log

放到 任务计划里,每5分钟执行一次。