Skip to content

Commit 9040ccd

Browse files
committed
DockerController: refactor stopping of containers to show the current process
Signed-off-by: Simon L. <szaimen@e.mail.de>
1 parent c7041c4 commit 9040ccd

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

php/src/Controller/DockerController.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,19 @@ public function startWatchtower(?\Closure $addToStreamingResponseBody = null) :
247247
$this->PerformRecursiveContainerStart($id, true, $addToStreamingResponseBody);
248248
}
249249

250-
private function PerformRecursiveContainerStop(string $id, bool $forceStopNextcloud = false) : void
250+
private function PerformRecursiveContainerStop(string $id, bool $forceStopNextcloud = false, ?\Closure $addToStreamingResponseBody = null) : void
251251
{
252252
$container = $this->containerDefinitionFetcher->GetContainerById($id);
253253

254254
// This is a hack but no better solution was found for the meantime
255255
// Stop Collabora first to make sure it force-saves
256256
// See https://github.com/nextcloud/richdocuments/issues/3799
257257
if ($id === self::TOP_CONTAINER && $this->configurationManager->isCollaboraEnabled) {
258-
$this->PerformRecursiveContainerStop('nextcloud-aio-collabora');
258+
$this->PerformRecursiveContainerStop('nextcloud-aio-collabora', false, $addToStreamingResponseBody);
259+
}
260+
261+
if ($addToStreamingResponseBody !== null) {
262+
$addToStreamingResponseBody($container, "Stopping container");
259263
}
260264

261265
// Stop itself first and then all the dependencies
@@ -266,17 +270,23 @@ private function PerformRecursiveContainerStop(string $id, bool $forceStopNextcl
266270
$this->dockerActionManager->StopContainer($container, $forceStopNextcloud);
267271
}
268272
foreach($container->dependsOn as $dependency) {
269-
$this->PerformRecursiveContainerStop($dependency, $forceStopNextcloud);
273+
$this->PerformRecursiveContainerStop($dependency, $forceStopNextcloud, $addToStreamingResponseBody);
270274
}
271275
}
272276

273277
public function StopContainer(Request $request, Response $response, array $args) : Response
274278
{
279+
// Get streaming response start and closure
280+
$nonbufResp = $this->startStreamingResponse($response);
281+
$addToStreamingResponseBody = $this->getAddToStreamingResponseBody($nonbufResp);
282+
275283
$id = self::TOP_CONTAINER;
276284
$forceStopNextcloud = true;
277-
$this->PerformRecursiveContainerStop($id, $forceStopNextcloud);
285+
$this->PerformRecursiveContainerStop($id, $forceStopNextcloud, $addToStreamingResponseBody);
278286

279-
return $response->withStatus(201)->withHeader('Location', '.');
287+
// End streaming response
288+
$this->finalizeStreamingResponse($nonbufResp);
289+
return $nonbufResp;
280290
}
281291

282292
public function stopTopContainer() : void {

php/templates/containers.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@
264264
{% else %}
265265
<p>It seems at least one container was not able to start correctly and is currently restarting.</p>
266266
<p>To break this endless loop, you can stop the containers below and investigate the issue in the container logs before starting the containers again.</p>
267-
<form method="POST" action="api/docker/stop" class="xhr">
267+
<form method="POST" action="api/docker/stop" target="overlay-log">
268268
<input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
269269
<input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
270270
<input type="submit" value="Stop containers" />
@@ -317,7 +317,7 @@
317317
<p>You can find all changes <a target="_blank" href="https://github.com/nextcloud-releases/all-in-one/commits/main"><strong>here</strong></a></p>
318318
{% endif %}
319319
{% endif %}
320-
<form method="POST" action="api/docker/stop" class="xhr">
320+
<form method="POST" action="api/docker/stop" target="overlay-log">
321321
<input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
322322
<input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
323323
<input type="submit" value="Stop containers" />

0 commit comments

Comments
 (0)