This bash script check web site every 5 minutes, restart the web server if web site is not responding.
Create a file
mkdir /usr/serverok vi /usr/serverok/check_httpd.sh
Add
#!/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
chmod 755 /usr/serverok/check_httpd.sh
Create a cronjob
crontab -e
Add
*/5 * * * * /usr/serverok/check_httpd.sh > /dev/null 2>&1
Leave a Reply