Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

refactor(Database): streamline container shutdown process and reduce timeout duration

Andras Bacsaie516aeb534ec
diff --git a/app/Actions/Database/StopDatabase.php b/app/Actions/Database/StopDatabase.php
index de4eaa31fc..f8f6f8519b 100644
--- a/app/Actions/Database/StopDatabase.php
+++ b/app/Actions/Database/StopDatabase.php
@@ -11,7 +11,6 @@ use App\Models\StandaloneMongodb;
use App\Models\StandaloneMysql;
use App\Models\StandalonePostgresql;
use App\Models\StandaloneRedis;
-use Illuminate\Support\Facades\Process;
use Lorisleiva\Actions\Concerns\AsAction;
class StopDatabase
@@ -39,37 +38,12 @@ class StopDatabase
return 'Database stopped successfully';
}
- private function stopContainer($database, string $containerName, int $timeout = 300): void
+ private function stopContainer($database, string $containerName, int $timeout = 30): void
{
$server = $database->destination->server;
-
- $process = Process::timeout($timeout)->start("docker stop --time=$timeout $containerName");
-
- $startTime = time();
- while ($process->running()) {
- if (time() - $startTime >= $timeout) {
- $this->forceStopContainer($containerName, $server);
- break;
- }
- usleep(100000);
- }
-
- $this->removeContainer($containerName, $server);
- }
-
- private function forceStopContainer(string $containerName, $server): void
- {
- instant_remote_process(command: ["docker kill $containerName"], server: $server, throwError: false);
- }
-
- private function removeContainer(string $containerName, $server): void
- {
- instant_remote_process(command: ["docker rm -f $containerName"], server: $server, throwError: false);
- }
-
- private function deleteConnectedNetworks($uuid, $server)
- {
- instant_remote_process(["docker network disconnect {$uuid} coolify-proxy"], $server, false);
- instant_remote_process(["docker network rm {$uuid}"], $server, false);
+ instant_remote_process(command: [
+ "docker stop --time=$timeout $containerName",
+ "docker rm -f $containerName",
+ ], server: $server, throwError: false);
}
}
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php
index d79e09151f..bebec64cfd 100644
--- a/app/Jobs/ApplicationDeploymentJob.php
+++ b/app/Jobs/ApplicationDeploymentJob.php
@@ -27,7 +27,6 @@ use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Collection;
-use Illuminate\Support\Facades\Process;
use Illuminate\Support\Sleep;
use Illuminate\Support\Str;
use RuntimeException;
@@ -2246,24 +2245,16 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");
$this->application_deployment_queue->addLogEntry('Building docker image completed.');
}
- private function graceful_shutdown_container(string $containerName, int $timeout = 300)
+ private function graceful_shutdown_container(string $containerName, int $timeout = 30)
{
try {
- $this->execute_remote_command(
- ["docker stop --time=$timeout $containerName", 'hidden' => true, 'ignore_errors' => true],
- );
- } catch (\Exception $error) {
+ $this->execute_remote_command(
+ ["docker stop --time=$timeout $containerName", 'hidden' => true, 'ignore_errors' => true],
+ ["docker rm -f $containerName", 'hidden' => true, 'ignore_errors' => true]
+ );
+ } catch (Exception $error) {
$this->application_deployment_queue->addLogEntry("Error stopping container $containerName: ".$error->getMessage(), 'stderr');
}
-
- $this->remove_container($containerName);
- }
-
- private function remove_container(string $containerName)
- {
- $this->execute_remote_command(
- ["docker rm -f $containerName", 'hidden' => true, 'ignore_errors' => true]
- );
}
private function stop_running_container(bool $force = false)