mirror of
https://github.com/nextcloud/all-in-one.git
synced 2025-12-19 22:16:49 +00:00
aio-interface: allow to force-stop Nextcloud container via API
Signed-off-by: Simon L. <szaimen@e.mail.de>
This commit is contained in:
parent
6c7c68418c
commit
2a95bc25f9
2 changed files with 22 additions and 9 deletions
|
|
@ -83,17 +83,18 @@ readonly class DockerController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function StartBackupContainerBackup(Request $request, Response $response, array $args) : Response {
|
public function StartBackupContainerBackup(Request $request, Response $response, array $args) : Response {
|
||||||
$this->startBackup();
|
$forceStopNextcloud = true;
|
||||||
|
$this->startBackup($forceStopNextcloud);
|
||||||
return $response->withStatus(201)->withHeader('Location', '/');
|
return $response->withStatus(201)->withHeader('Location', '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function startBackup() : void {
|
public function startBackup(bool $forceStopNextcloud = false) : void {
|
||||||
$config = $this->configurationManager->GetConfig();
|
$config = $this->configurationManager->GetConfig();
|
||||||
$config['backup-mode'] = 'backup';
|
$config['backup-mode'] = 'backup';
|
||||||
$this->configurationManager->WriteConfig($config);
|
$this->configurationManager->WriteConfig($config);
|
||||||
|
|
||||||
$id = self::TOP_CONTAINER;
|
$id = self::TOP_CONTAINER;
|
||||||
$this->PerformRecursiveContainerStop($id);
|
$this->PerformRecursiveContainerStop($id, $forceStopNextcloud);
|
||||||
|
|
||||||
$id = 'nextcloud-aio-borgbackup';
|
$id = 'nextcloud-aio-borgbackup';
|
||||||
$this->PerformRecursiveContainerStart($id);
|
$this->PerformRecursiveContainerStart($id);
|
||||||
|
|
@ -125,7 +126,8 @@ readonly class DockerController {
|
||||||
$this->configurationManager->WriteConfig($config);
|
$this->configurationManager->WriteConfig($config);
|
||||||
|
|
||||||
$id = self::TOP_CONTAINER;
|
$id = self::TOP_CONTAINER;
|
||||||
$this->PerformRecursiveContainerStop($id);
|
$forceStopNextcloud = true;
|
||||||
|
$this->PerformRecursiveContainerStop($id, $forceStopNextcloud);
|
||||||
|
|
||||||
$id = 'nextcloud-aio-borgbackup';
|
$id = 'nextcloud-aio-borgbackup';
|
||||||
$this->PerformRecursiveContainerStart($id);
|
$this->PerformRecursiveContainerStart($id);
|
||||||
|
|
@ -224,7 +226,7 @@ readonly class DockerController {
|
||||||
$this->PerformRecursiveContainerStart($id);
|
$this->PerformRecursiveContainerStart($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function PerformRecursiveContainerStop(string $id) : void
|
private function PerformRecursiveContainerStop(string $id, bool $forceStopNextcloud = false) : void
|
||||||
{
|
{
|
||||||
$container = $this->containerDefinitionFetcher->GetContainerById($id);
|
$container = $this->containerDefinitionFetcher->GetContainerById($id);
|
||||||
|
|
||||||
|
|
@ -236,7 +238,12 @@ readonly class DockerController {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop itself first and then all the dependencies
|
// 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) {
|
foreach($container->GetDependsOn() as $dependency) {
|
||||||
$this->PerformRecursiveContainerStop($dependency);
|
$this->PerformRecursiveContainerStop($dependency);
|
||||||
}
|
}
|
||||||
|
|
@ -245,7 +252,8 @@ readonly class DockerController {
|
||||||
public function StopContainer(Request $request, Response $response, array $args) : Response
|
public function StopContainer(Request $request, Response $response, array $args) : Response
|
||||||
{
|
{
|
||||||
$id = self::TOP_CONTAINER;
|
$id = self::TOP_CONTAINER;
|
||||||
$this->PerformRecursiveContainerStop($id);
|
$forceStopNextcloud = true;
|
||||||
|
$this->PerformRecursiveContainerStop($id, $forceStopNextcloud);
|
||||||
|
|
||||||
return $response->withStatus(201)->withHeader('Location', '/');
|
return $response->withStatus(201)->withHeader('Location', '/');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -898,8 +898,13 @@ readonly class DockerActionManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function StopContainer(Container $container): void {
|
public function StopContainer(Container $container, bool $forceStopContainer = false): void {
|
||||||
$url = $this->BuildApiUrl(sprintf('containers/%s/stop?t=%s', urlencode($container->GetIdentifier()), $container->GetMaxShutdownTime()));
|
if ($forceStopContainer) {
|
||||||
|
$maxShutDownTime = 10;
|
||||||
|
} else {
|
||||||
|
$maxShutDownTime = $container->GetMaxShutdownTime();
|
||||||
|
}
|
||||||
|
$url = $this->BuildApiUrl(sprintf('containers/%s/stop?t=%s', urlencode($container->GetIdentifier()), $maxShutDownTime));
|
||||||
try {
|
try {
|
||||||
$this->guzzleClient->post($url);
|
$this->guzzleClient->post($url);
|
||||||
} catch (RequestException $e) {
|
} catch (RequestException $e) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue