diff --git a/app/Actions/CoolifyTask/RunRemoteProcess.php b/app/Actions/CoolifyTask/RunRemoteProcess.php
index 926d30fe6..8ce9aa1f2 100644
--- a/app/Actions/CoolifyTask/RunRemoteProcess.php
+++ b/app/Actions/CoolifyTask/RunRemoteProcess.php
@@ -85,7 +85,6 @@ class RunRemoteProcess
]);
$processResult = $process->wait();
- // $processResult = Process::timeout($timeout)->run($this->getCommand(), $this->handleOutput(...));
if ($this->activity->properties->get('status') === ProcessStatus::ERROR->value) {
$status = ProcessStatus::ERROR;
} else {
diff --git a/app/Actions/Proxy/StopProxy.php b/app/Actions/Proxy/StopProxy.php
index a5dcc6cf4..75b22d236 100644
--- a/app/Actions/Proxy/StopProxy.php
+++ b/app/Actions/Proxy/StopProxy.php
@@ -3,54 +3,27 @@
namespace App\Actions\Proxy;
use App\Models\Server;
-use Carbon\Carbon;
-use Illuminate\Process\InvokedProcess;
-use Illuminate\Support\Facades\Process;
use Lorisleiva\Actions\Concerns\AsAction;
class StopProxy
{
use AsAction;
- public function handle(Server $server, bool $forceStop = true)
+ public function handle(Server $server, bool $forceStop = true, int $timeout = 30)
{
try {
$containerName = $server->isSwarm() ? 'coolify-proxy_traefik' : 'coolify-proxy';
- $timeout = 30;
- $process = $this->stopContainer($containerName, $timeout);
+ instant_remote_process(command: [
+ "docker stop --time=$timeout $containerName",
+ "docker rm -f $containerName",
+ ], server: $server, throwError: false);
- $startTime = Carbon::now()->getTimestamp();
- while ($process->running()) {
- if (Carbon::now()->getTimestamp() - $startTime >= $timeout) {
- $this->forceStopContainer($containerName, $server);
- break;
- }
- usleep(100000);
- }
-
- $this->removeContainer($containerName, $server);
- } catch (\Throwable $e) {
- return handleError($e);
- } finally {
$server->proxy->force_stop = $forceStop;
$server->proxy->status = 'exited';
$server->save();
+ } catch (\Throwable $e) {
+ return handleError($e);
}
}
-
- private function stopContainer(string $containerName, int $timeout): InvokedProcess
- {
- return Process::timeout($timeout)->start("docker stop --time=$timeout $containerName");
- }
-
- private function forceStopContainer(string $containerName, Server $server)
- {
- instant_remote_process(["docker kill $containerName"], $server, throwError: false);
- }
-
- private function removeContainer(string $containerName, Server $server)
- {
- instant_remote_process(["docker rm -f $containerName"], $server, throwError: false);
- }
}
diff --git a/app/Livewire/Project/Application/Previews.php b/app/Livewire/Project/Application/Previews.php
index 88ce65c53..193a22280 100644
--- a/app/Livewire/Project/Application/Previews.php
+++ b/app/Livewire/Project/Application/Previews.php
@@ -5,10 +5,7 @@ namespace App\Livewire\Project\Application;
use App\Actions\Docker\GetContainersStatus;
use App\Models\Application;
use App\Models\ApplicationPreview;
-use Carbon\Carbon;
-use Illuminate\Process\InvokedProcess;
use Illuminate\Support\Collection;
-use Illuminate\Support\Facades\Process;
use Livewire\Component;
use Spatie\Url\Url;
use Visus\Cuid2\Cuid2;
@@ -193,13 +190,12 @@ class Previews extends Component
{
try {
$server = $this->application->destination->server;
- $timeout = 300;
if ($this->application->destination->server->isSwarm()) {
instant_remote_process(["docker stack rm {$this->application->uuid}-{$pull_request_id}"], $server);
} else {
$containers = getCurrentApplicationContainerStatus($server, $this->application->id, $pull_request_id)->toArray();
- $this->stopContainers($containers, $server, $timeout);
+ $this->stopContainers($containers, $server);
}
GetContainersStatus::run($server);
@@ -215,13 +211,12 @@ class Previews extends Component
{
try {
$server = $this->application->destination->server;
- $timeout = 300;
if ($this->application->destination->server->isSwarm()) {
instant_remote_process(["docker stack rm {$this->application->uuid}-{$pull_request_id}"], $server);
} else {
$containers = getCurrentApplicationContainerStatus($server, $this->application->id, $pull_request_id)->toArray();
- $this->stopContainers($containers, $server, $timeout);
+ $this->stopContainers($containers, $server);
}
ApplicationPreview::where('application_id', $this->application->id)
@@ -237,48 +232,14 @@ class Previews extends Component
}
}
- private function stopContainers(array $containers, $server, int $timeout)
+ private function stopContainers(array $containers, $server, int $timeout = 30)
{
- $processes = [];
foreach ($containers as $container) {
$containerName = str_replace('/', '', $container['Names']);
- $processes[$containerName] = $this->stopContainer($containerName, $timeout);
- }
-
- $startTime = Carbon::now()->getTimestamp();
- while (count($processes) > 0) {
- $finishedProcesses = array_filter($processes, function ($process) {
- return ! $process->running();
- });
- foreach (array_keys($finishedProcesses) as $containerName) {
- unset($processes[$containerName]);
- $this->removeContainer($containerName, $server);
- }
-
- if (Carbon::now()->getTimestamp() - $startTime >= $timeout) {
- $this->forceStopRemainingContainers(array_keys($processes), $server);
- break;
- }
-
- usleep(100000);
- }
- }
-
- private function stopContainer(string $containerName, int $timeout): InvokedProcess
- {
- return Process::timeout($timeout)->start("docker stop --time=$timeout $containerName");
- }
-
- private function removeContainer(string $containerName, $server)
- {
- instant_remote_process(["docker rm -f $containerName"], $server, throwError: false);
- }
-
- private function forceStopRemainingContainers(array $containerNames, $server)
- {
- foreach ($containerNames as $containerName) {
- instant_remote_process(["docker kill $containerName"], $server, throwError: false);
- $this->removeContainer($containerName, $server);
+ instant_remote_process(command: [
+ "docker stop --time=$timeout $containerName",
+ "docker rm -f $containerName",
+ ], server: $server, throwError: false);
}
}
}
diff --git a/app/Models/Application.php b/app/Models/Application.php
index 233c8d806..124a62eb7 100644
--- a/app/Models/Application.php
+++ b/app/Models/Application.php
@@ -9,9 +9,7 @@ use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
-use Illuminate\Process\InvokedProcess;
use Illuminate\Support\Collection;
-use Illuminate\Support\Facades\Process;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Str;
use OpenApi\Attributes as OA;
@@ -270,47 +268,13 @@ class Application extends BaseModel
return $containers->pluck('Names')->toArray();
}
- public function stopContainers(array $containerNames, $server, int $timeout = 600)
- {
- $processes = [];
- foreach ($containerNames as $containerName) {
- $processes[$containerName] = $this->stopContainer($containerName, $server, $timeout);
- }
-
- $startTime = time();
- while (count($processes) > 0) {
- $finishedProcesses = array_filter($processes, function ($process) {
- return ! $process->running();
- });
- foreach ($finishedProcesses as $containerName => $process) {
- unset($processes[$containerName]);
- $this->removeContainer($containerName, $server);
- }
-
- if (time() - $startTime >= $timeout) {
- $this->forceStopRemainingContainers(array_keys($processes), $server);
- break;
- }
-
- usleep(100000);
- }
- }
-
- public function stopContainer(string $containerName, $server, int $timeout): InvokedProcess
- {
- return Process::timeout($timeout)->start("docker stop --time=$timeout $containerName");
- }
-
- public function removeContainer(string $containerName, $server)
- {
- instant_remote_process(command: ["docker rm -f $containerName"], server: $server, throwError: false);
- }
-
- public function forceStopRemainingContainers(array $containerNames, $server)
+ public function stopContainers(array $containerNames, $server, int $timeout = 30)
{
foreach ($containerNames as $containerName) {
- instant_remote_process(command: ["docker kill $containerName"], server: $server, throwError: false);
- $this->removeContainer($containerName, $server);
+ instant_remote_process(command: [
+ "docker stop --time=$timeout $containerName",
+ "docker rm -f $containerName",
+ ], server: $server, throwError: false);
}
}
diff --git a/app/Models/Service.php b/app/Models/Service.php
index 23ddb5923..5232e5897 100644
--- a/app/Models/Service.php
+++ b/app/Models/Service.php
@@ -6,9 +6,7 @@ use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
-use Illuminate\Process\InvokedProcess;
use Illuminate\Support\Collection;
-use Illuminate\Support\Facades\Process;
use Illuminate\Support\Facades\Storage;
use OpenApi\Attributes as OA;
use Spatie\Url\Url;
@@ -158,47 +156,13 @@ class Service extends BaseModel
return $containersToStop;
}
- public function stopContainers(array $containerNames, $server, int $timeout = 300)
- {
- $processes = [];
- foreach ($containerNames as $containerName) {
- $processes[$containerName] = $this->stopContainer($containerName, $timeout);
- }
-
- $startTime = time();
- while (count($processes) > 0) {
- $finishedProcesses = array_filter($processes, function ($process) {
- return ! $process->running();
- });
- foreach (array_keys($finishedProcesses) as $containerName) {
- unset($processes[$containerName]);
- $this->removeContainer($containerName, $server);
- }
-
- if (time() - $startTime >= $timeout) {
- $this->forceStopRemainingContainers(array_keys($processes), $server);
- break;
- }
-
- usleep(100000);
- }
- }
-
- public function stopContainer(string $containerName, int $timeout): InvokedProcess
- {
- return Process::timeout($timeout)->start("docker stop --time=$timeout $containerName");
- }
-
- public function removeContainer(string $containerName, $server)
- {
- instant_remote_process(command: ["docker rm -f $containerName"], server: $server, throwError: false);
- }
-
- public function forceStopRemainingContainers(array $containerNames, $server)
+ public function stopContainers(array $containerNames, $server, int $timeout = 30)
{
foreach ($containerNames as $containerName) {
- instant_remote_process(command: ["docker kill $containerName"], server: $server, throwError: false);
- $this->removeContainer($containerName, $server);
+ instant_remote_process(command: [
+ "docker stop --time=$timeout $containerName",
+ "docker rm -f $containerName",
+ ], server: $server, throwError: false);
}
}
diff --git a/resources/views/livewire/project/application/heading.blade.php b/resources/views/livewire/project/application/heading.blade.php
index aecab0265..560597530 100644
--- a/resources/views/livewire/project/application/heading.blade.php
+++ b/resources/views/livewire/project/application/heading.blade.php
@@ -117,7 +117,8 @@
@script
diff --git a/resources/views/livewire/project/service/navbar.blade.php b/resources/views/livewire/project/service/navbar.blade.php
index 4b3c93504..dd2ce4142 100644
--- a/resources/views/livewire/project/service/navbar.blade.php
+++ b/resources/views/livewire/project/service/navbar.blade.php
@@ -138,7 +138,7 @@
@script