Domain Name Yahoo

Easy Help Troubleshoot Your Linux Box



  

Easy Help Troubleshoot Your Linux Box


Server Availability Monitoring by Email

  

As Server administrator, be informed for your server availability before anyone.
Services that need to be notify is httpd and mysqld.
I created simple easy tips to check your server and services.

First, create sudo rules for any of your services needed by typing

# visudo

If you dont have sudo, you must install it first.
We need sudo to make apache user to be able to execute defined unix syntax.
Add this line to your rules

apache ALL=(ALL) NOPASSWD: /etc/init.d/httpd status, /etc/init.d/mysqld status

That means, apache user is allow to use syntax httpd status and mysqld status.

Second, create1 php file on your public html folder, so it can be accesed from the web.

# vi /var/www/html/checkconnection.php

<?php

$output = “Server Status \n”;
$output = $output.shell_exec(”sudo /etc/init.d/httpd status | grep is”);
$output = $output.shell_exec(”sudo /etc/init.d/mysqld status | grep is”);
$output = $output.shell_exec(”df -h “);

?>

This script will shows you the status of service httpd and mysqld, and also the disk informations.
Please make sure your php safe_mode = off and allow for function shell_exec
Add line echo $output; before ?> to see all in the browser so you can try it on your internet browser by typing http://www.yourdomain.com/checkconnection.php

Third, create 1 more php file but, in the other hosting. You may choose freehosting to do this.
Add this script into that php file :

<?php

content = file_get_contents(”http://www.yourdomain.com/checkconnection.php”);
if ( $content ==”") {

$content = “SERVER ERROR” ;

}
mail(”email@yourdomain.com”,”Status Server”,$content);
echo $content;

?>

This will send email to email@yourdomain.com about the service status.
If your server is not connected to internet or the httpd services has been stopped then your free hosting cannot find checkconnection.php then you will be mailed for SERVER ERROR.
You may change the email into your yahoo email or anything.
Put this script into crontab, run it for ever 6 hours.

* */6 * * * /usr/bin/php /<your path here>/checkconnection.php

I will do some research for automatically notified by SMS ( short Message Service) similliar like push email.

I hope this will help.


March 17th, 2009 Posted by admin | CentOS, General, Ubuntu | no comments

No Comments »

No comments yet.

Leave a comment