Skip to content

Commit bbcfa69

Browse files
Merge pull request #36218 from nextcloud/backport/35873/stable25
[stable25] Add option to return an exit-code when occ status signals an update is needed
2 parents 2181b1f + 87678c2 commit bbcfa69

2 files changed

Lines changed: 25 additions & 5 deletions

File tree

core/Command/Status.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use OCP\IConfig;
3030
use OCP\Util;
3131
use Symfony\Component\Console\Input\InputInterface;
32+
use Symfony\Component\Console\Input\InputOption;
3233
use Symfony\Component\Console\Output\OutputInterface;
3334

3435
class Status extends Base {
@@ -47,22 +48,40 @@ protected function configure() {
4748

4849
$this
4950
->setDescription('show some status information')
50-
;
51+
->addOption(
52+
'exit-code',
53+
'e',
54+
InputOption::VALUE_NONE,
55+
'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.'
56+
);
5157
}
5258

5359
protected function execute(InputInterface $input, OutputInterface $output): int {
60+
$maintenanceMode = $this->config->getSystemValueBool('maintenance', false);
61+
$needUpgrade = Util::needUpgrade();
5462
$values = [
5563
'installed' => $this->config->getSystemValueBool('installed', false),
5664
'version' => implode('.', Util::getVersion()),
5765
'versionstring' => OC_Util::getVersionString(),
5866
'edition' => '',
59-
'maintenance' => $this->config->getSystemValueBool('maintenance', false),
60-
'needsDbUpgrade' => Util::needUpgrade(),
67+
'maintenance' => $maintenanceMode,
68+
'needsDbUpgrade' => $needUpgrade,
6169
'productname' => $this->themingDefaults->getProductName(),
6270
'extendedSupport' => Util::hasExtendedSupport()
6371
];
6472

65-
$this->writeArrayInOutputFormat($input, $output, $values);
73+
if ($input->getOption('verbose') || !$input->getOption('exit-code')) {
74+
$this->writeArrayInOutputFormat($input, $output, $values);
75+
}
76+
77+
if ($input->getOption('exit-code')) {
78+
if ($maintenanceMode === true) {
79+
return 1;
80+
}
81+
if ($needUpgrade === true) {
82+
return 2;
83+
}
84+
}
6685
return 0;
6786
}
6887
}

lib/private/Console/Application.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ private function writeMaintenanceModeInfo(
181181
InputInterface $input, ConsoleOutputInterface $output
182182
) {
183183
if ($input->getArgument('command') !== '_completion'
184-
&& $input->getArgument('command') !== 'maintenance:mode') {
184+
&& $input->getArgument('command') !== 'maintenance:mode'
185+
&& $input->getArgument('command') !== 'status') {
185186
$errOutput = $output->getErrorOutput();
186187
$errOutput->writeln(
187188
'<comment>Nextcloud is in maintenance mode, hence the database isn\'t accessible.' . PHP_EOL .

0 commit comments

Comments
 (0)