Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable25] Add option to return an exit-code when occ status signals an update is needed #36218

Merged
merged 3 commits into from
Feb 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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>
  • Loading branch information
Lee Garrett authored and backportbot-nextcloud[bot] committed Jan 18, 2023
commit 9851c86c59602d6619c1a6f2f2aa43eae431f9ee
23 changes: 20 additions & 3 deletions core/Command/Status.php
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@
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 @@ protected function configure() {

$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()
];
3 changes: 2 additions & 1 deletion lib/private/Console/Application.php
Original file line number Diff line number Diff line change
@@ -181,7 +181,8 @@ private function writeMaintenanceModeInfo(
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 .