summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorLee Garrett <lgarrett@rocketjump.eu>2022-12-22 22:03:21 +0100
committerLee Garrett <lgarrett@rocketjump.eu>2023-01-03 10:58:07 +0100
commitfba906e34a35ab31a334421edacdd7d4d29b1d7f (patch)
tree05e2685e616f7f7af55a6474697f10eff2fc668c /core
parent5b64b8119fc9c004887b514722bcecc2353564de (diff)
downloadnextcloud-server-fba906e34a35ab31a334421edacdd7d4d29b1d7f.tar.gz
nextcloud-server-fba906e34a35ab31a334421edacdd7d4d29b1d7f.zip
Implement occ status command via return codes (Fixes: #35704)
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>
Diffstat (limited to 'core')
-rw-r--r--core/Command/Status.php23
1 files changed, 20 insertions, 3 deletions
diff --git a/core/Command/Status.php b/core/Command/Status.php
index 45ccb28f5c4..9b3af59b94a 100644
--- a/core/Command/Status.php
+++ b/core/Command/Status.php
@@ -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()
];