A simple cronjobs to restart your apache server when it’s too busy
#!/bin/bash# URL of Apache server-statusSTATUS_URL=”http://localhost/server-status?auto”# Get current number of busy workersHTML_STATUS_FILE=”/tmp/cron_html_status.html”curl -s “$STATUS_URL” > “$HTML_STATUS_FILE”BUSY_WORKERS=$(cat “$HTML_STATUS_FILE” | grep “BusyWorkers” | awk ‘{print $2}’)# Restart Apache if busy workers exceed thresholdTHRESHOLD=200if [ “$BUSY_WORKERS” -gt “$THRESHOLD” ]; then MESSAGE=”$(date): Restarting Apache – BusyWorkers = $BUSY_WORKERS” echo “$MESSAGE” >> /var/log/apache_monitor.log cp “$HTML_STATUS_FILE” “/var/log/apache_monitor_html_$(date).log” curl -s “http://localhost/server-status” > “$HTML_STATUS_FILE”.”$(date ‘+%Y-%m-%d-%H-%M-%S’).html” logger -t apache_monitor “$MESSAGE” systemctl restart apache2fiRead More →