aio-interface: allow to force-stop Nextcloud container via API

Signed-off-by: Simon L. <szaimen@e.mail.de>
This commit is contained in:
Simon L. 2025-07-28 14:31:43 +02:00
parent 6c7c68418c
commit 2a95bc25f9
2 changed files with 22 additions and 9 deletions

View file

@ -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', '/');
}

View file

@ -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) {