diff --git a/php/src/Controller/DockerController.php b/php/src/Controller/DockerController.php index 378ddab6..39befc63 100644 --- a/php/src/Controller/DockerController.php +++ b/php/src/Controller/DockerController.php @@ -83,17 +83,18 @@ readonly class DockerController { } public function StartBackupContainerBackup(Request $request, Response $response, array $args) : Response { - $this->startBackup(); + $forceStopNextcloud = true; + $this->startBackup($forceStopNextcloud); return $response->withStatus(201)->withHeader('Location', '/'); } - public function startBackup() : void { + public function startBackup(bool $forceStopNextcloud = false) : void { $config = $this->configurationManager->GetConfig(); $config['backup-mode'] = 'backup'; $this->configurationManager->WriteConfig($config); $id = self::TOP_CONTAINER; - $this->PerformRecursiveContainerStop($id); + $this->PerformRecursiveContainerStop($id, $forceStopNextcloud); $id = 'nextcloud-aio-borgbackup'; $this->PerformRecursiveContainerStart($id); @@ -125,7 +126,8 @@ readonly class DockerController { $this->configurationManager->WriteConfig($config); $id = self::TOP_CONTAINER; - $this->PerformRecursiveContainerStop($id); + $forceStopNextcloud = true; + $this->PerformRecursiveContainerStop($id, $forceStopNextcloud); $id = 'nextcloud-aio-borgbackup'; $this->PerformRecursiveContainerStart($id); @@ -224,7 +226,7 @@ readonly class DockerController { $this->PerformRecursiveContainerStart($id); } - private function PerformRecursiveContainerStop(string $id) : void + private function PerformRecursiveContainerStop(string $id, bool $forceStopNextcloud = false) : void { $container = $this->containerDefinitionFetcher->GetContainerById($id); @@ -236,7 +238,12 @@ readonly class DockerController { } // Stop itself first and then all the dependencies - $this->dockerActionManager->StopContainer($container); + if ($id !== 'nextcloud-aio-nextcloud') { + $this->dockerActionManager->StopContainer($container); + } else { + // We want to stop the Nextcloud container after 10s and not wait for the configured stop_grace_period + $this->dockerActionManager->StopContainer($container, $forceStopNextcloud); + } foreach($container->GetDependsOn() as $dependency) { $this->PerformRecursiveContainerStop($dependency); } @@ -245,7 +252,8 @@ readonly class DockerController { public function StopContainer(Request $request, Response $response, array $args) : Response { $id = self::TOP_CONTAINER; - $this->PerformRecursiveContainerStop($id); + $forceStopNextcloud = true; + $this->PerformRecursiveContainerStop($id, $forceStopNextcloud); return $response->withStatus(201)->withHeader('Location', '/'); } diff --git a/php/src/Docker/DockerActionManager.php b/php/src/Docker/DockerActionManager.php index 2c8e365e..f6ffbdc3 100644 --- a/php/src/Docker/DockerActionManager.php +++ b/php/src/Docker/DockerActionManager.php @@ -898,8 +898,13 @@ readonly class DockerActionManager { } } - public function StopContainer(Container $container): void { - $url = $this->BuildApiUrl(sprintf('containers/%s/stop?t=%s', urlencode($container->GetIdentifier()), $container->GetMaxShutdownTime())); + public function StopContainer(Container $container, bool $forceStopContainer = false): void { + if ($forceStopContainer) { + $maxShutDownTime = 10; + } else { + $maxShutDownTime = $container->GetMaxShutdownTime(); + } + $url = $this->BuildApiUrl(sprintf('containers/%s/stop?t=%s', urlencode($container->GetIdentifier()), $maxShutDownTime)); try { $this->guzzleClient->post($url); } catch (RequestException $e) {