Skip to content

Instantly share code, notes, and snippets.

@valmirphp
Forked from fer-ri/restart-service.sh
Last active June 5, 2019 13:57
Show Gist options
  • Save valmirphp/1a515cbd0306a9921e2f116df3eec8ae to your computer and use it in GitHub Desktop.
Save valmirphp/1a515cbd0306a9921e2f116df3eec8ae to your computer and use it in GitHub Desktop.
Auto Restart PHP5-FPM When Down or Bad Gateway
#!/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
#!/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" yourmail@domain.com -aFrom:cron@yourmail.com
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment