-
-
Save valmirphp/1a515cbd0306a9921e2f116df3eec8ae to your computer and use it in GitHub Desktop.
Auto Restart PHP5-FPM When Down or Bad Gateway
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# add cron: */3 * * * * /root/nginxfix.sh >> /var/log/nginxfix.log 2>&1 | |
# REF: https://www.hrupin.com/2017/07/how-to-automatically-restart-nginx | |
PATH=/usr/sbin:/usr/bin:/sbin:/bin | |
if [[ ! "$(/etc/init.d/nginx status)" =~ "active (running)" ]] | |
then | |
echo $(date -u) "NGINX server has been stopped. It has now been restarted." | |
service nginx start | |
else | |
echo $(date -u) "OK" | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if curl --head -sf http://yourdomain.com/some-script.php -o /dev/null; then | |
echo "PHP FPM is up" | |
else | |
service php5-fpm restart && service nginx restart && service mysql restart | |
echo "Opps .. service was down" | mail -s "PHP-FPM Service Down" [email protected] -aFrom:[email protected] | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment