Skip to content

Commit

Permalink
NEW Add script master_move_several_instances.php
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Aug 17, 2024
1 parent db65a46 commit f5aa531
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

## Unreleased

* NEW Add script master_move_several_instances.php
* NEW Add a tool to test the email like it is done during registration.
* NEW On payment by card, the last 4 numbers are saved into the field "numero" of the payment in database.
* NEW Can force permission to see SSH/Mysql access per instance.
Expand Down
36 changes: 27 additions & 9 deletions scripts/master_move_instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,21 @@
$langs->loadLangs(array("main", "errors"));

$oldinstance=isset($argv[1]) ? $argv[1] : '';

$newinstance=isset($argv[2]) ? strtolower($argv[2]) : '';

$mode=isset($argv[3]) ? $argv[3] : '';
$nointeractive = 0;

$i = 0;
while ($i < $argc) {
if (!empty($argv[$i])) {
if ($argv[$i] == '-y') {
$nointeractive = 1;
unset($argv[$i]);
}
}
$i++;
}


$langsen = new Translate('', $conf);
$langsen->setDefaultLang($mysoc->default_lang);
Expand All @@ -191,12 +202,13 @@
print "Move an existing instance from an old server to a new server (with target instance not existing yet).\n";
print "Script must be ran from the master server with login admin.\n";
print "\n";
print "Usage: ".$script_file." oldinstance.withX.mysaasdomainname.com newinstance.withY.mysaasdomainname.com (test|confirm|confirmmaintenance|confirmredirect) [MYPRODUCTREF]\n";
print "Usage: ".$script_file." oldinstance.withX.mysaasdomainname.com newinstance.withY.mysaasdomainname.com (test|confirm|confirmmaintenance|confirmredirect) [MYPRODUCTREF] [-y]\n";
print "Mode is: test test mode (nothing is done).\n";
print " confirm real move of the instance (deprecated, use confirmmaintenance or confirmredirect).\n";
print " confirmmaintenance real move and replace old instance with a definitive message 'Suspended. Instance has been moved.'.\n";
print " confirmredirect real move with a mesage 'Move in progress' during transfer, and then, switch old instance into a redirect instance.\n";
print "MYPRODUCTREF can be set to force a new hosting application service.\n";
print "Option -y can be added to automatically answer yes to questions.\n";
print "Return code: 0 if success, <>0 if error\n";
print "\n";
exit(-1);
Expand Down Expand Up @@ -288,7 +300,7 @@

$productref = '';
$forceproductref = '';
if (isset($argv[4])) {
if (isset($argv[4]) && $argv[4] != '-y') {
$productref = $argv[4];
$forceproductref = $argv[4];
}
Expand Down Expand Up @@ -383,7 +395,7 @@


// Share certificate of old instance by copying them into the common crt dir (they should already be into this directory)
// TODO If the certificate of the source instance are not into crt directory, we must copy them into the sellyoursaas master crt directory with read permission to admin user.
// If the certificate of the source instance are not into crt directory, we must copy them into the sellyoursaas master crt directory with read permission to admin user.
$CERTIFFORCUSTOMDOMAIN = $oldinstance;
if ($CERTIFFORCUSTOMDOMAIN) {
print '--- Check/copy the certificate files (.key, .crt and -intermediate.crt) of instance (generic and custom) into the sellyoursaas master crt directory (to reuse them on the new instance for backward compatibility).'."\n";
Expand Down Expand Up @@ -664,8 +676,11 @@
$output=array();
$return_var=0;

print "Press ENTER to continue by running the rsync command to get files of old instance...";
$input = trim(fgets(STDIN));
if (empty($nointeractive)) {
print "Press ENTER to continue by running the rsync command to get files of old instance...";
$input = trim(fgets(STDIN));
}

print $fullcommand."\n";

$outputfile = $conf->admin->dir_temp.'/out.tmp';
Expand Down Expand Up @@ -729,8 +744,11 @@
$output=array();
$return_var=0;

print "Press ENTER to continue by running the rsync command to push files on remote target host...\n";
$input = trim(fgets(STDIN));
if (empty($nointeractive)) {
print "Press ENTER to continue by running the rsync command to push files on remote target host...\n";
$input = trim(fgets(STDIN));
}

print $fullcommand."\n";

$outputfile = $conf->admin->dir_temp.'/out.tmp';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/

/**
* \file sellyoursaas/scripts/master_move_several_instance.php
* \file sellyoursaas/scripts/master_move_several_instances.php
* \ingroup sellyoursaas
* \brief Script to run from the master server to move several instances from a server to another one.
*/
Expand Down Expand Up @@ -386,7 +386,7 @@
print "Found ".count($listofinstances)." instances.\n";


foreach($listofinstances as $oldinstancecursor) {
foreach ($listofinstances as $oldinstancecursor) {
// Process instance
$oldinstancecursorname = $oldinstancecursor['instance'];
$tmparray = explode('.', $oldinstancecursorname);
Expand All @@ -395,8 +395,8 @@
print "Move instance ".$oldinstancecursorname." into ".$newinstancecursorname.".\n";

$command='php '.DOL_DOCUMENT_ROOT."/custom/sellyoursaas/scripts/master_move_instance.php ".escapeshellarg($oldinstancecursorname)." ".escapeshellarg($newinstancecursorname);
$command .= " ".$mode;
echo $command."\n";
$command .= " ".$mode." -y";
print $command."\n";

$return_val = 0;
if ($mode == 'confirm' || $mode == 'confirmredirect' || $mode == 'confirmmaintenance') {
Expand All @@ -406,10 +406,10 @@
$return_val = $resultarray['result'];
$content_grabbed = $resultarray['output'];

echo "Result: ".$return_val."\n";
print "Result: ".$return_val."\n";
if (!empty($resultarray['error'])) {
echo "Output: ".$content_grabbed."\n";
echo "Error: ".$resultarray['error']."\n";
print "Output: ".$content_grabbed."\n";
print "Error: ".$resultarray['error']."\n";
}
}

Expand All @@ -429,7 +429,7 @@
print 'Move of old instances matching name '.$oldinstance." canceled (test mode)\n";
}
} else {
print 'Failed to move some instance'."\n";
print 'Failed to move last instance'."\n";
print "\n";
exit(-1);
}
Expand Down

0 comments on commit f5aa531

Please sign in to comment.