Hi,
Source:
http://www.journaldev.com/574/apache-res...ache-crash
This script polls a website to check it's responding usin php:
servercheck.php
It will return 1 or 0. It will be run using:
apache_restart.sh
This script could be tailored to add a mySQL restart or detect mySQL errors too. Or even to check response delay to trigger other custom responses and automates some admin task.
M B
Source:
http://www.journaldev.com/574/apache-res...ache-crash
This script polls a website to check it's responding usin php:
servercheck.php
Quote:<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://www.journaldev.com'); // Connect to your server
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11");
curl_setopt($curl, CURLOPT_TIMEOUT, 15);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_exec($curl);
$info = curl_getinfo($curl);
// Check server's state
if ((!curl_error($curl)) && ($info['http_code'] != 0)) {
echo 1;
} else {
echo 0;
}
curl_close($curl);
?>
It will return 1 or 0. It will be run using:
apache_restart.sh
Quote:#!/bin/bash
# Make sure you make these paths correct
result=`/usr/local/bin/php /home/journal/scripts/apache_restart/servercheck.php`
echo $result
if [ $result != 1 ]
then
/etc/init.d/httpd restart
sleep 10
restartcheck=`/usr/local/bin/php /home/journal/scripts/apache_restart/servercheck.php`
if [ $restartcheck == 1 ]
then
echo "Apache server have been successfully restarted!" | mail -s "Server Alert: Apache restarted" pankaj.kumar@journaldev.com
exit
else
echo "Apache server is still in error state!" | mail -s "Server Alert: Apache in error state" pankaj.kumar@journaldev.com
exit
fi
exit
fi
This script could be tailored to add a mySQL restart or detect mySQL errors too. Or even to check response delay to trigger other custom responses and automates some admin task.
M B
No support using PM (Auto adding to IGNORE list!), use the forum.
How to ask
200$ free to start your VPS 60 days credit
How to ask
200$ free to start your VPS 60 days credit