fix: Stop resources gracefully

This commit is contained in:
Andras Bacsai
2024-08-06 13:27:06 +02:00
parent 35e62a3003
commit e897eb2999
4 changed files with 15 additions and 13 deletions

View File

@@ -31,15 +31,13 @@ class StopApplication
} else { } else {
$containers = getCurrentApplicationContainerStatus($server, $application->id, 0); $containers = getCurrentApplicationContainerStatus($server, $application->id, 0);
} }
ray($containers);
if ($containers->count() > 0) { if ($containers->count() > 0) {
foreach ($containers as $container) { foreach ($containers as $container) {
$containerName = data_get($container, 'Names'); $containerName = data_get($container, 'Names');
if ($containerName) { if ($containerName) {
instant_remote_process( instant_remote_process(command: ["docker stop --time=30 $containerName"], server: $server, throwError: false);
["docker rm -f {$containerName}"], instant_remote_process(command: ["docker rm $containerName"], server: $server, throwError: false);
$server instant_remote_process(command: ["docker rm -f {$containerName}"], server: $server, throwError: false);
);
} }
} }
} }

View File

@@ -22,10 +22,11 @@ class StopDatabase
if (! $server->isFunctional()) { if (! $server->isFunctional()) {
return 'Server is not functional'; return 'Server is not functional';
} }
instant_remote_process(
["docker rm -f {$database->uuid}"], instant_remote_process(command: ["docker stop --time=30 $database->uuid"], server: $server, throwError: false);
$server instant_remote_process(command: ["docker rm $database->uuid"], server: $server, throwError: false);
); instant_remote_process(command: ["docker rm -f $database->uuid"], server: $server, throwError: false);
if ($database->is_public) { if ($database->is_public) {
StopDatabaseProxy::run($database); StopDatabaseProxy::run($database);
} }

View File

@@ -19,18 +19,21 @@ class StopService
ray('Stopping service: '.$service->name); ray('Stopping service: '.$service->name);
$applications = $service->applications()->get(); $applications = $service->applications()->get();
foreach ($applications as $application) { foreach ($applications as $application) {
instant_remote_process(["docker rm -f {$application->name}-{$service->uuid}"], $service->server, false); instant_remote_process(command: ["docker stop --time=30 {$application->name}-{$service->uuid}"], server: $server, throwError: false);
instant_remote_process(command: ["docker rm {$application->name}-{$service->uuid}"], server: $server, throwError: false);
instant_remote_process(command: ["docker rm -f {$application->name}-{$service->uuid}"], server: $server, throwError: false);
$application->update(['status' => 'exited']); $application->update(['status' => 'exited']);
} }
$dbs = $service->databases()->get(); $dbs = $service->databases()->get();
foreach ($dbs as $db) { foreach ($dbs as $db) {
instant_remote_process(["docker rm -f {$db->name}-{$service->uuid}"], $service->server, false); instant_remote_process(command: ["docker stop --time=30 {$db->name}-{$service->uuid}"], server: $server, throwError: false);
instant_remote_process(command: ["docker rm {$db->name}-{$service->uuid}"], server: $server, throwError: false);
instant_remote_process(command: ["docker rm -f {$db->name}-{$service->uuid}"], server: $server, throwError: false);
$db->update(['status' => 'exited']); $db->update(['status' => 'exited']);
} }
instant_remote_process(["docker network disconnect {$service->uuid} coolify-proxy"], $service->server); instant_remote_process(["docker network disconnect {$service->uuid} coolify-proxy"], $service->server);
instant_remote_process(["docker network rm {$service->uuid}"], $service->server); instant_remote_process(["docker network rm {$service->uuid}"], $service->server);
} catch (\Exception $e) { } catch (\Exception $e) {
echo $e->getMessage();
ray($e->getMessage()); ray($e->getMessage());
return $e->getMessage(); return $e->getMessage();

View File

@@ -2030,7 +2030,7 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");
/** /**
* @param int $timeout in seconds * @param int $timeout in seconds
*/ */
private function graceful_shutdown_container(string $containerName, int $timeout = 60) private function graceful_shutdown_container(string $containerName, int $timeout = 30)
{ {
try { try {
$this->execute_remote_command( $this->execute_remote_command(