function switchserver_main() { global $argc, $argv; global $gbl, $sgbl, $login, $ghtml; //sleep(60); initProgram("admin"); if ($argc === 1) { print "Usage: {$argv['0']} --class= --name= --v-syncserver= \n"; exit; } try { $opt = parse_opt($argv); $param = get_variable($opt); dprintr($param); $class = $opt['class']; $name = $opt['name']; if (lx_core_lock("{$class}-{$name}.switchserver")) { exit; } $object = new $class(null, 'localhost', $name); $object->get(); if ($object->dbaction === 'add') { throw new lxException("no_object", '', ''); exit; } if (!$object->syncserver) { print "No_synserver...\n"; throw new lxException("no_syncserver", '', ''); exit; } if ($param['syncserver'] === $object->syncserver) { print "No Change...\n"; throw new lxException("no_change", '', ''); exit; } $driverapp_old = $gbl->getSyncClass('localhost', $object->syncserver, $object->get__table()); $driverapp_new = $gbl->getSyncClass('localhost', $param['syncserver'], $object->get__table()); if ($driverapp_new !== $driverapp_old) { //throw new lxException ("the_drivers_are_different_in_two_servers", '', ''); } $object->doupdateSwitchserver($param); } catch (exception $e) { print $e->getMessage(); /// hcak ahck... Chnage only the olddelete variable which is the mutex used for locking in the process of switch. The problem is we want to totally bail out if the switchserver fails. The corect way would be save after reverting the syncserve to the old value, but that's a bit risky. So we just use a hack to change only the olddeleteflag; Not a real hack.. This is the better way. $message = "{$e->getMessage()}"; write_to_object($object, $message, $param['syncserver']); $fullmesage = "Switch of {$object->get__table()}:{$object->nname} to {$object->syncserver} failed due to {$e->getMessage()}"; log_switch($fullmesage); mail($login->contactemail, "Switch Failed:", "{$fullmesage}\n"); print "\n"; exit; } mail($login->contactemail, "Switch Succeeded", "Switch Succeeded {$object->get__table()}:{$object->nname} to {$param['syncserver']}\n"); }
function switchserver_main() { global $argc, $argv; global $gbl, $sgbl, $login, $ghtml; //sleep(60); initProgram("admin"); if ($argc === 1) { print "Usage: {$argv['0']} --class= --name= --v-syncserver= \n"; exit; } try { $opt = parse_opt($argv); $param = get_variable($opt); dprintr($param); $class = $opt['class']; $name = $opt['name']; if (lx_core_lock("{$class}-{$name}.livemigrate")) { exit; } $object = new $class(null, 'localhost', $name); $object->get(); if ($object->dbaction === 'add') { throw new lxException("no_object", '', ''); exit; } if (!$object->syncserver) { print "No_synserver...\n"; throw new lxException("no_syncserver", '', ''); exit; } if ($param['syncserver'] === $object->syncserver) { print "No Change...\n"; throw new lxException("no_change", '', ''); exit; } $driverapp_old = $gbl->getSyncClass('localhost', $object->syncserver, $object->getClass()); $driverapp_new = $gbl->getSyncClass('localhost', $param['syncserver'], $object->getClass()); $oldserver = $object->syncserver; $newserver = $param['syncserver']; if ($driverapp_new !== $driverapp_old) { throw new lxException("the_drivers_are_different_in_two_servers", '', ''); } $actualserver = getFQDNforServer($newserver); setup_ssh_channel($oldserver, $newserver, $actualserver); $ssh_port = db_get_value("sshconfig", $newserver, "ssh_port"); if (!$ssh_port) { $ssh_port = "22"; } $res = rl_exec_get(null, $oldserver, "exec_vzmigrate", array($object->vpsid, $actualserver, $ssh_port)); list($ret, $error) = $res; if ($ret !== 0) { throw new lxException("vzmigrate_failed_due_to:{$error}", '', ''); } $object->olddeleteflag = 'done'; $object->syncserver = $newserver; $object->username = null; $object->makeSureTheUserExists(); $object->setUpdateSubaction(); $object->write(); } catch (exception $e) { print $e->getMessage(); /// hcak ahck... Chnage only the olddelete variable which is the mutex used for locking in the process of switch. The problem is we want to totally bail out if the switchserver fails. The corect way would be save after reverting the syncserve to the old value, but that's a bit risky. So we just use a hack to change only the olddeleteflag; Not a real hack.. This is the better way. $message = "{$e->getMessage()}"; $message = str_replace("'", "", $message); write_to_object($object, $message, $param['syncserver']); $fullmesage = "Switch of {$object->getClass()}:{$object->nname} to {$param['syncserver']} failed due to {$e->getMessage()}"; log_switch($fullmesage); mail($login->contactemail, "Switch Failed:", "{$fullmesage}\n"); print "\n"; exit; } mail($login->contactemail, "Switch Succeeded", "Switch Succeeded {$object->getClass()}:{$object->nname} to {$param['syncserver']}\n"); }