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.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
refactor(application): enhance application stopping logic to support multiple servers
Andras Bacsai102bdb5bc361
diff --git a/app/Actions/Application/StopApplication.php b/app/Actions/Application/StopApplication.phpindex 01c258b650..0ca703fce0 100644--- a/app/Actions/Application/StopApplication.php+++ b/app/Actions/Application/StopApplication.php@@ -15,33 +15,46 @@ class StopApplicationpublic function handle(Application $application, bool $previewDeployments = false, bool $dockerCleanup = true){- ray('StopApplication');- try {- $server = $application->destination->server;- if (! $server->isFunctional()) {- return 'Server is not functional';- }-- if ($server->isSwarm()) {- instant_remote_process(["docker stack rm {$application->uuid}"], $server);-- return;- }-- $containersToStop = $application->getContainersToStop($previewDeployments);- $application->stopContainers($containersToStop, $server);-- if ($application->build_pack === 'dockercompose') {- $application->deleteConnectedNetworks();- }-- if ($dockerCleanup) {- CleanupDocker::dispatch($server, true);+ $servers = collect([$application->destination->server]);+ if ($application?->additional_servers?->count() > 0) {+ $servers = $servers->merge($application->additional_servers);+ }+ foreach ($servers as $server) {+ try {+ if (! $server->isFunctional()) {+ return 'Server is not functional';+ }++ if ($server->isSwarm()) {+ instant_remote_process(["docker stack rm {$application->uuid}"], $server);++ return;+ }++ $containers = $previewDeployments+ ? getCurrentApplicationContainerStatus($server, $application->id, includePullrequests: true)+ : getCurrentApplicationContainerStatus($server, $application->id, 0);++ $containersToStop = $containers->pluck('Names')->toArray();++ foreach ($containersToStop as $containerName) {+ instant_remote_process(command: [+ "docker stop --time=30 $containerName",+ "docker rm -f $containerName",+ ], server: $server, throwError: false);+ }++ if ($application->build_pack === 'dockercompose') {+ $application->deleteConnectedNetworks();+ }++ if ($dockerCleanup) {+ CleanupDocker::dispatch($server, true);+ }+ } catch (\Exception $e) {+ return $e->getMessage();}- } catch (\Exception $e) {- return $e->getMessage();- } finally {- ServiceStatusChanged::dispatch($application->environment->project->team->id);}+ ServiceStatusChanged::dispatch($application->environment->project->team->id);}}diff --git a/app/Actions/Application/StopApplicationOneServer.php b/app/Actions/Application/StopApplicationOneServer.phpindex b13b10efd6..600b1cb9a8 100644--- a/app/Actions/Application/StopApplicationOneServer.php+++ b/app/Actions/Application/StopApplicationOneServer.php@@ -25,7 +25,10 @@ class StopApplicationOneServer$containerName = data_get($container, 'Names');if ($containerName) {instant_remote_process(- ["docker rm -f {$containerName}"],+ [+ "docker stop --time=30 $containerName",+ "docker rm -f $containerName",+ ],$server);}diff --git a/app/Livewire/Project/Application/Configuration.php b/app/Livewire/Project/Application/Configuration.phpindex 021731c201..b50d7b7360 100644--- a/app/Livewire/Project/Application/Configuration.php+++ b/app/Livewire/Project/Application/Configuration.php@@ -23,6 +23,7 @@ class Configuration extends Componentreturn ["echo-private:team.{$teamId},ServiceChecked" => '$refresh',+ "echo-private:team.{$teamId},ServiceStatusChanged" => '$refresh','buildPackUpdated' => '$refresh','refresh' => '$refresh',];diff --git a/app/Livewire/Project/Shared/Destination.php b/app/Livewire/Project/Shared/Destination.phpindex a4343bff92..40291d2b0f 100644--- a/app/Livewire/Project/Shared/Destination.php+++ b/app/Livewire/Project/Shared/Destination.php@@ -26,6 +26,7 @@ class Destination extends Componentreturn ["echo-private:team.{$teamId},ApplicationStatusChanged" => 'loadData',+ "echo-private:team.{$teamId},ServiceStatusChanged" => 'mount','refresh' => 'mount',];}diff --git a/app/Models/Application.php b/app/Models/Application.phpindex 94bd5c75ba..7929aadc15 100644--- a/app/Models/Application.php+++ b/app/Models/Application.php@@ -259,25 +259,15 @@ class Application extends BaseModelreturn Application::whereRelation('environment.project.team', 'id', currentTeam()->id)->orderBy('name');}- public function getContainersToStop(bool $previewDeployments = false): array+ public function getContainersToStop(Server $server, bool $previewDeployments = false): array{$containers = $previewDeployments- ? getCurrentApplicationContainerStatus($this->destination->server, $this->id, includePullrequests: true)- : getCurrentApplicationContainerStatus($this->destination->server, $this->id, 0);+ ? getCurrentApplicationContainerStatus($server, $this->id, includePullrequests: true)+ : getCurrentApplicationContainerStatus($server, $this->id, 0);return $containers->pluck('Names')->toArray();}- public function stopContainers(array $containerNames, $server, int $timeout = 30)- {- foreach ($containerNames as $containerName) {- instant_remote_process(command: [- "docker stop --time=$timeout $containerName",- "docker rm -f $containerName",- ], server: $server, throwError: false);- }- }-public function deleteConfigurations(){$server = data_get($this, 'destination.server');