Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 14 additions & 1 deletion lib/OC.php
Original file line number Diff line number Diff line change
Expand Up @@ -1128,8 +1128,17 @@ public static function handleRequest(): void {
if ($requestPath === '/heartbeat') {
return;
}
$serveAppApiDuringMaintenance = false;
if (substr($requestPath, -3) !== '.js') { // we need these files during the upgrade
self::checkMaintenanceMode($systemConfig);
if (((bool)$systemConfig->getValue('maintenance', false)) && !\OCP\Util::needUpgrade()
&& ($requestPath === '/apps/app_api' || str_starts_with($requestPath, '/apps/app_api/'))
&& Server::get(\OCP\App\IAppManager::class)->isEnabledForAnyone('app_api')) {
// Keep serving ExApp traffic (HaRP metadata) while the instance is in maintenance mode
$serveAppApiDuringMaintenance = true;
}
if (!$serveAppApiDuringMaintenance) {
self::checkMaintenanceMode($systemConfig);
}

if (\OCP\Util::needUpgrade()) {
if (function_exists('opcache_reset')) {
Expand Down Expand Up @@ -1193,6 +1202,10 @@ public static function handleRequest(): void {
$appManager->loadApps(['filesystem', 'logging']);
$appManager->loadApps();
}
if ($serveAppApiDuringMaintenance) {
// loadApps() above is a no-op during maintenance, load app_api explicitly
$appManager->loadApp('app_api');
}
Server::get(\OC\Route\Router::class)->match($request->getRawPathInfo());
return;
} catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) {
Expand Down
20 changes: 18 additions & 2 deletions lib/private/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ public function loadCommands(
if (Util::needUpgrade()) {
throw new NeedsUpdateException();
} elseif ($this->config->getSystemValueBool('maintenance')) {
if ($this->appManager->isEnabledForAnyone('app_api')) {
// AppAPI must stay usable during maintenance mode;
// loading commands from register_command.php is intentionally skipped.
$this->appManager->loadApp('app_api');
$info = $this->appManager->getAppInfo('app_api');
if (isset($info['commands'])) {
try {
$this->loadCommandsFromInfoXml($info['commands']);
} catch (\Throwable $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
$this->logger->error($e->getMessage(), [
'exception' => $e,
]);
}
}
}
$this->writeMaintenanceModeInfo($input, $output);
} else {
$this->appManager->loadApps();
Expand Down Expand Up @@ -161,8 +177,8 @@ private function writeMaintenanceModeInfo(InputInterface $input, ConsoleOutputIn
&& $input->getArgument('command') !== 'maintenance:mode'
&& $input->getArgument('command') !== 'status') {
$errOutput = $output->getErrorOutput();
$errOutput->writeln('<comment>Nextcloud is in maintenance mode, no apps are loaded.</comment>');
$errOutput->writeln('<comment>Commands provided by apps are unavailable.</comment>');
$errOutput->writeln('<comment>Nextcloud is in maintenance mode, only AppAPI commands are loaded.</comment>');
$errOutput->writeln('<comment>Commands provided by other apps are unavailable.</comment>');
}
}

Expand Down
17 changes: 16 additions & 1 deletion ocs/v1.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,18 @@

$request = Server::get(IRequest::class);

if ((Util::needUpgrade() || Server::get(IConfig::class)->getSystemValueBool('maintenance')) && $request->getPathInfo() !== '/core/update') {
$serveAppApiDuringMaintenance = false;
if (!Util::needUpgrade() && Server::get(IConfig::class)->getSystemValueBool('maintenance')) {
$pathInfo = $request->getPathInfo();
// AppAPI must keep serving HaRP traffic (signed OCS calls and ExApp callbacks)
$serveAppApiDuringMaintenance
= ($pathInfo === '/apps/app_api' || str_starts_with($pathInfo, '/apps/app_api/'))
&& Server::get(IAppManager::class)->isEnabledForAnyone('app_api');
}

if ((Util::needUpgrade()
|| (Server::get(IConfig::class)->getSystemValueBool('maintenance') && !$serveAppApiDuringMaintenance))
&& $request->getPathInfo() !== '/core/update') {
// since the behavior of apps or remotes are unpredictable during
// an upgrade, return a 503 directly
ApiHelper::respond(503, 'Service unavailable', ['X-Nextcloud-Maintenance-Mode' => '1'], 503);
Expand All @@ -49,6 +60,10 @@
$request->throwDecodingExceptionIfAny();

if ($request->getPathInfo() !== '/core/update') {
if ($serveAppApiDuringMaintenance) {
// loadApps() below is a no-op during maintenance, load app_api explicitly
$appManager->loadApp('app_api');
}
// load all apps to get all api routes properly setup
// FIXME: this should ideally appear after handleLogin but will cause
// side effects in existing apps
Expand Down
Loading