CasperSecurity
| Current Path : /usr/local/bin/ |
|
|
| Current File : //usr/local/bin/check_apache.sh |
#!/bin/bash
# Define the service to check
APACHE_SERVICE="apache2"
# URL to check for website health. Should be a reliable page.
# We will check if we can download the main UIET homepage.
URL_TO_CHECK="https://uiet.co.in"
# Check if the site is reachable using curl
# The --max-time 5 flag ensures curl gives up after 5 seconds if the site is down
# The -s -f flags make curl silent and fail on server errors
if ! curl -s -f --max-time 5 "$URL_TO_CHECK" > /dev/null
then
# If the curl command fails, the site is down. Restart Apache.
echo "$(date): Website check failed for $URL_TO_CHECK. Restarting Apache..." >> /var/log/apache_watchdog.log
systemctl restart "$APACHE_SERVICE"
echo "$(date): Apache restarted via watchdog." >> /var/log/apache_watchdog.log
fi