From f5aa531de994a1bfd5db25e99737c0a21f7ef94a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 17 Aug 2024 13:51:00 +0200 Subject: [PATCH] NEW Add script master_move_several_instances.php --- ChangeLog.md | 1 + scripts/master_move_instance.php | 36 ++++++++++++++----- ....php => master_move_several_instances.php} | 16 ++++----- 3 files changed, 36 insertions(+), 17 deletions(-) rename scripts/{master_move_several_instance.php => master_move_several_instances.php} (98%) diff --git a/ChangeLog.md b/ChangeLog.md index a3f2d7c9..0248b04a 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -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. diff --git a/scripts/master_move_instance.php b/scripts/master_move_instance.php index 203a1c4b..69705721 100755 --- a/scripts/master_move_instance.php +++ b/scripts/master_move_instance.php @@ -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); @@ -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); @@ -288,7 +300,7 @@ $productref = ''; $forceproductref = ''; -if (isset($argv[4])) { +if (isset($argv[4]) && $argv[4] != '-y') { $productref = $argv[4]; $forceproductref = $argv[4]; } @@ -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"; @@ -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'; @@ -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'; diff --git a/scripts/master_move_several_instance.php b/scripts/master_move_several_instances.php similarity index 98% rename from scripts/master_move_several_instance.php rename to scripts/master_move_several_instances.php index 9d66917f..a0fdc557 100755 --- a/scripts/master_move_several_instance.php +++ b/scripts/master_move_several_instances.php @@ -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. */ @@ -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); @@ -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') { @@ -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"; } } @@ -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); }