]> source.dussan.org Git - nextcloud-server.git/commitdiff
Implement occ status command via return codes (Fixes: #35704)
authorLee Garrett <lgarrett@rocketjump.eu>
Thu, 22 Dec 2022 21:03:21 +0000 (22:03 +0100)
committerLee Garrett <lgarrett@rocketjump.eu>
Tue, 3 Jan 2023 09:58:07 +0000 (10:58 +0100)
Running `./occ status -e` will produce any output. However, it will:

exit 0 during normal operation,
exit 1 when in maintenance mode,
exit 2 when `./occ upgrade` is needed.

Signed-off-by: Lee Garrett <lgarrett@rocketjump.eu>
core/Command/Status.php
lib/private/Console/Application.php

index 45ccb28f5c4995f382e16f65779e7727af3842a3..9b3af59b94a344f31fc740c6ccb11ae87c51c5b6 100644 (file)
@@ -29,6 +29,7 @@ use OCP\Defaults;
 use OCP\IConfig;
 use OCP\Util;
 use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Output\OutputInterface;
 
 class Status extends Base {
@@ -47,17 +48,33 @@ class Status extends Base {
 
                $this
                        ->setDescription('show some status information')
-               ;
+                       ->addOption(
+                               'exit-code',
+                               'e',
+                               InputOption::VALUE_NONE,
+                               'exit with 0 if running in normal mode, 1 when in maintenance mode, 2 when `./occ upgrade` is needed. Does not write any output to STDOUT.'
+                       );
        }
 
        protected function execute(InputInterface $input, OutputInterface $output): int {
+               $maintenanceMode = $this->config->getSystemValueBool('maintenance', false);
+               $needUpgrade = Util::needUpgrade();
+               if ($input->getOption('exit-code')) {
+                       if ($maintenanceMode === true) {
+                               return 1;
+                       } elseif ($needUpgrade == true) {
+                               return 2;
+                       } else {
+                               return 0;
+                       }
+               }
                $values = [
                        'installed' => $this->config->getSystemValueBool('installed', false),
                        'version' => implode('.', Util::getVersion()),
                        'versionstring' => OC_Util::getVersionString(),
                        'edition' => '',
-                       'maintenance' => $this->config->getSystemValueBool('maintenance', false),
-                       'needsDbUpgrade' => Util::needUpgrade(),
+                       'maintenance' => $maintenanceMode,
+                       'needsDbUpgrade' => $needUpgrade,
                        'productname' => $this->themingDefaults->getProductName(),
                        'extendedSupport' => Util::hasExtendedSupport()
                ];
index fc48f57e4995dfa370d4114322806b4f866a8bbd..2b48f9f5adace45c89e2528bfb85066d74afc543 100644 (file)
@@ -181,7 +181,8 @@ class Application {
                InputInterface $input, ConsoleOutputInterface $output
        ) {
                if ($input->getArgument('command') !== '_completion'
-                       && $input->getArgument('command') !== 'maintenance:mode') {
+                       && $input->getArgument('command') !== 'maintenance:mode'
+                       && $input->getArgument('command') !== 'status') {
                        $errOutput = $output->getErrorOutput();
                        $errOutput->writeln(
                                '<comment>Nextcloud is in maintenance mode, hence the database isn\'t accessible.' . PHP_EOL .