mirror of
https://github.com/nextcloud/all-in-one.git
synced 2025-12-19 22:16:49 +00:00
Merge pull request #6693 from nextcloud/enh/noid/allow-force-stop-nextcloud
aio-interface: allow to force-stop Nextcloud container via API
This commit is contained in:
commit
a9303b7918
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 {
|
||||
$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
|
||||
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', '/');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue