Skip to content

Instantly share code, notes, and snippets.

@xi4oh4o
Last active September 1, 2021 19:10
Show Gist options
  • Save xi4oh4o/4378447 to your computer and use it in GitHub Desktop.
Save xi4oh4o/4378447 to your computer and use it in GitHub Desktop.
Auto restart phpfpm on 502 & 504 Error also save logs
#!/bin/bash
MY_URL="http://moefou.org" #change you website
RESULT_502=`curl -I $MY_URL|grep "HTTP/1.1 502"`
RESULT_504=`curl -I $MY_URL|grep "HTTP/1.1 504"`
if [ -n "$RESULT_502" ]; then
killall php-fpm;php-fpm
date>>/data/logs/web_error.log;echo "502 Bad Gateway">>/data/logs/web_error.log
elif [ -n "$RESULT_504" ]; then
killall php-fpm;php-fpm
date>>/data/logs/web_error.log;echo "504 Gateway Time-out">>/data/logs/web_error.log
fi
: << \EOF
run crontab -e
add below
#Auto Fix WebServer 502 & 504 Error
#* * * * * root /data/task/auto_restart_webserver.sh >/dev/null 2>&1
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment