Restart Apache if failed
This bash script check web site every 5 minutes, restart the web server if web site is not responding.
Create a file
1 2 |
mkdir /usr/serverok vi /usr/serverok/check_httpd.sh |
Add
1 2 3 4 5 6 7 8 9 10 11 12 |
#!/bin/bash # Author: Yujin Boby # Web: https://serverok.in # Email: [email protected] /usr/bin/wget --tries=1 --timeout=30 -O /dev/null https://YOUR_DOMAIN.EXTN/ if [ $? -ne 0 ]; then systemctl restart httpd datetime=`date "+%Y%m%d %H:%M:%S"` echo $datetime "failure">>/var/log/sok-web.log fi |
In above code, replace https://YOUR_DOMAIN.EXTN/ with your sites actual url.
Make it executable
1 |
chmod 755 /usr/serverok/check_httpd.sh |
Create a cronjob
1 |
crontab -e |
Add
1 |
*/5 * * * * /usr/serverok/check_httpd.sh > /dev/null 2>&1 |