Bruno
20-04-2008, 20:00
Hello,
Here is a (quickly made) PHP script that does a hard reboot on your rps if this one is down (ping OK but SSH down --> "read-only"). You have to run this script on a different server !
NB : it only concerns the RPS servers
The file hardRebootDoIfReadOnly.php :
The crontab directive (crontab -e) to test the rps every 10 minutes :
You can modify it, here are the error codes returned by OCO :
#-- ERROR
300 - ERROR
301 - Connection time out
302 - Connection refused
310 - Login error
311 - Logout error
312 - Transfer error
350 - Time out of executing check script
398 - Result to old
399 - No result files
Here is a (quickly made) PHP script that does a hard reboot on your rps if this one is down (ping OK but SSH down --> "read-only"). You have to run this script on a different server !
NB : it only concerns the RPS servers
The file hardRebootDoIfReadOnly.php :
PHP Code:
/* This PHP script tests your RPS's status and do a reboot hard if it's down
Reboot hard only if your rps is in read-only */
############# begin config #############
// OBLIGATOIRE
$host = "rXXXXX.ovh.net" ; // the rps name
$login_manager = "XXXXXX-ovh" ; // your manager login...
$passwd_manager = "*******" ; // ...and its password
$mail = "" ; // the mail to send the hard reboot alert
// OPTIONAL
$reason = "OCO 398 Error read-only" ; // the reason of the hard reboot
############# end config ###############
// test the rps status with OCO (OvhChckOut) via telnet
$test = shell_exec("telnet $host 79") ;
$result = explode("\n", $test) ;
$result = $result[3] ;
// get the error code
$code = intval($result[0].$result[1].$result[2]) ;
if ($code == 398)
{ // the RPS is KO, reboot hard !
$soap = new SoapClient('http://www.ovh.com/soapi/ovh.wsdl');
//login
try {
$login = $login_manager;
$password = $passwd_manager ;
$session = $soap->login($login,$password,null);
echo "login successfull";
} catch(SoapFault $fault) {
echo "Error : ".$fault;
}
//dedicatedHardRebootDo
try {
$result = $soap->dedicatedHardRebootDo($session, $host, $reason, $mail, '');
echo "dedicatedHardRebootDo successfull";
} catch(SoapFault $fault) {
echo "Error : ".$fault;
}
//logout
try {
$result = $soap->logout($session);
echo "logout successfull";
} catch(SoapFault $fault) {
echo "Error : ".$fault;
}
}
?>
Code:
*/10 * * * * php /path/of/the/file/hardRebootDoIfReadOnly.php
#-- ERROR
300 - ERROR
301 - Connection time out
302 - Connection refused
310 - Login error
311 - Logout error
312 - Transfer error
350 - Time out of executing check script
398 - Result to old
399 - No result files