From 1f70e2a94f6d3d9e23ea4d442d4fb5ea0f9ffb4f Mon Sep 17 00:00:00 2001 From: Josh Richards Date: Mon, 23 Dec 2024 21:31:20 -0500 Subject: [PATCH] fix(cli): occ error handling Signed-off-by: Josh Richards --- lib/UpdateCommand.php | 74 ++++++++++++++++++++++++++++++------------ updater.phar | Bin 1171590 -> 1173040 bytes 2 files changed, 54 insertions(+), 20 deletions(-) diff --git a/lib/UpdateCommand.php b/lib/UpdateCommand.php index f2586526..293cf566 100644 --- a/lib/UpdateCommand.php +++ b/lib/UpdateCommand.php @@ -42,7 +42,7 @@ class UpdateCommand extends Command { protected function configure(): void { $this ->setName('update') - ->setDescription('Updates the code of an Nextcloud instance') + ->setDescription('Updates the code of a Nextcloud instance') ->setHelp('This command fetches the latest code that is announced via the updater server and safely replaces the existing code with the new one.') ->addOption('no-backup', null, InputOption::VALUE_NONE, 'Skip backup of current Nextcloud version') ->addOption('no-upgrade', null, InputOption::VALUE_NONE, "Don't automatically run occ upgrade"); @@ -266,9 +266,14 @@ protected function execute(InputInterface $input, OutputInterface $output) { $this->updater->log('[info] update of code successful.'); $output->writeln('Update of code successful.'); + // + // Handle `occ upgrade` run + // + if ($this->skipUpgrade) { - $output->writeln('Please now execute "./occ upgrade" to finish the upgrade.'); + $this->updater->log('[info] "occ upgrade" was skipped'); $this->updater->log('[info] updater finished'); + $output->writeln('Please execute "./occ upgrade" manually to finish the upgrade.'); return 0; } @@ -280,20 +285,46 @@ protected function execute(InputInterface $input, OutputInterface $output) { $question = new ConfirmationQuestion('Should the "occ upgrade" command be executed? [Y/n] ', true); if (!$helper->ask($input, $output, $question)) { - $output->writeln('Please now execute "./occ upgrade" to finish the upgrade.'); + $this->updater->log('[info] "occ upgrade" was skipped'); $this->updater->log('[info] updater finished'); + $output->writeln('Please execute "./occ upgrade" manually to finish the upgrade.'); return 0; } } else { - $this->updater->log('[info] updater run in non-interactive mode - occ upgrade is started'); + $this->updater->log('[info] updater run in non-interactive mode - will start "occ upgrade" now'); $output->writeln('Updater run in non-interactive mode - will start "occ upgrade" now.'); $output->writeln(''); } - chdir($path . '/..'); - chmod('occ', 0755); # TODO do this in the updater - system(PHP_BINARY . ' ./occ upgrade -v', $returnValue); + $occPath = $path . '/../occ'; + if (!file_exists($occPath)) { + $this->updater->log('[error] FATAL: "occ" is missing from: ' . $occPath); + $output->writeln(''); + throw new \Exception('FATAL: "occ" is missing from: ' . $occPath); + } + if (chmod($occPath, 0755) === false) { # TODO do this in the updater + throw new \Exception('FATAL: Unable to make "occ" executable: ' . $occPath); + } + $occRunCommand = PHP_BINARY . ' ' . $occPath; + + $this->updater->log('[info] Starting "occ upgrade"'); + system($occRunCommand . ' upgrade -v', $returnValue); + if ($returnValue === 0) { + $this->updater->log('[info] "occ upgrade" finished'); + $output->writeln(''); + $output->writeln('"occ upgrade" finished'); + } else { // something went wrong + $this->updater->log('[info] "occ upgrade" failed - return code: ' . $returnValue); + $output->writeln(''); + $output->writeln('"occ upgrade" failed - return code: ' . $returnValue); + $this->updater->log('[info] updater finished - with errors'); + return $returnValue; + } + // + // Handle maintenance mode toggle + // + $output->writeln(''); if ($input->isInteractive()) { /** @var QuestionHelper */ @@ -301,28 +332,31 @@ protected function execute(InputInterface $input, OutputInterface $output) { $question = new ConfirmationQuestion($this->checkTexts[11] . ' [y/N] ', false); if ($helper->ask($input, $output, $question)) { - $output->writeln('Maintenance mode kept active'); - $this->updater->log('[info] updater finished - maintenance mode kept active'); - return $returnValue; + $this->updater->log('[info] maintenance mode kept active'); + $output->writeln('Please execute "./occ maintenance:mode --off" manually to finish the upgrade.'); + $this->updater->log('[info] updater finished'); + return 0; } } else { - $this->updater->log('[info] updater run in non-interactive mode - disabling maintenance mode'); + $this->updater->log('[info] updater run in non-interactive mode - will disable maintenance mode now'); $output->writeln('Updater run in non-interactive mode - will disable maintenance mode now.'); + $output->writeln(''); } - try { - system(PHP_BINARY . ' ./occ maintenance:mode --off', $returnValueMaintenanceMode); - $this->updater->log('[info] maintenance mode is disabled - return code: ' . $returnValueMaintenanceMode); + $this->updater->log('[info] Disabling maintenance mode'); + system($occRunCommand . ' maintenance:mode --off', $returnValueMaintenanceMode); + if ($returnValueMaintenanceMode === 0) { + $this->updater->log('[info] maintenance mode disabled'); $output->writeln(''); $output->writeln('Maintenance mode is disabled'); - } catch (\Exception $e) { - $this->updater->log('[info] maintenance mode can not be disabled'); - $this->updater->logException($e); + return 0; + } else { // something went wrong + $this->updater->log('[info] Disabling maintenance mode failed - return code: ' . $returnValueMaintenanceMode); $output->writeln(''); - $output->writeln('Maintenance mode can not be disabled'); + $output->writeln('Disabling Maintenance mode failed - return code:' . $returnValueMaintenanceMode); + $this->updater->log('[info] updater finished - with errors'); + return $returnValueMaintenanceMode; } - - return $returnValue; } else { if ($this->shouldStop) { $output->writeln('Update stopped. To resume or retry just execute the updater again.'); diff --git a/updater.phar b/updater.phar index 5f283b36f403f6c303846b4659538290b6f439d7..02e3a73ed6be5e46f576ce861f84a1fb6004134c 100755 GIT binary patch delta 1549 zcmb7EUu;ul6t^%+TL$9*+ZZe3TbU`%WG&me!Me&eCYuS&9*uC&`|9F(DWqO-wxBZK1oyCfMY6Z@--L zoqxaIxmSLkSSU?=bhVLlDSbRLIFLNi&p*D==RE&D?Kpow>G~kvVEysu*eBNW5BA?0 ze#ZWZ_r-%ZzWu>fIpei`@a22Ckq>htF2WYVRzd?|8^KN3PVf-C1Rr4sp^>nYu#3=C z%#G|GSo0k_nmL~A9gOy$C@$=U&p#_peFJa#yTf6h*Xs?3*`%bVvYgFm$t26?GP;!F zGfdB`6|;Ea^}BEwD8JcS(_(2fg>064M)yYb2r?7=Teu$}RD zcrtHt7U&5(E-R9nm$KP;Tr9z%Vqyt~UHHp=Xu?M&X!O@j6b!|1@jkQ&w`XzNo&S@D z;l5?KfTd;dZxwMaFF`B*whG;7EyKxd51W&#}m0G#X;@c$}rBtieO<5)Q9G0AE;#)@(J)YpQgCNH#U5 zNOQ!6U1^0GVQ?0?DWAwPomWq33elCK!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