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
use public function
ayntk-ai41be1f7666c6
diff --git a/app/Actions/Application/StopApplication.php b/app/Actions/Application/StopApplication.phpindex 73abeba7a2..5f5846f555 100644--- a/app/Actions/Application/StopApplication.php+++ b/app/Actions/Application/StopApplication.php@@ -12,41 +12,28 @@ class StopApplicationpublic function handle(Application $application, bool $previewDeployments = false){- if ($application->destination->server->isSwarm()) {- instant_remote_process(["docker stack rm {$application->uuid}"], $application->destination->server);- return;- }-- $servers = collect([]);- $servers->push($application->destination->server);- $application->additional_servers->map(function ($server) use ($servers) {- $servers->push($server);- });- foreach ($servers as $server) {+ try {+ $server = $application->destination->server;if (!$server->isFunctional()) {return 'Server is not functional';}- if ($previewDeployments) {- $containers = getCurrentApplicationContainerStatus($server, $application->id, includePullrequests: true);- } else {- $containers = getCurrentApplicationContainerStatus($server, $application->id, 0);- }- if ($containers->count() > 0) {- foreach ($containers as $container) {- $containerName = data_get($container, 'Names');- if ($containerName) {- instant_remote_process(command: ["docker stop --time=30 $containerName"], server: $server, throwError: false);- instant_remote_process(command: ["docker rm $containerName"], server: $server, throwError: false);- instant_remote_process(command: ["docker rm -f {$containerName}"], server: $server, throwError: false);- }- }+ ray('Stopping application: ' . $application->name);++ if ($server->isSwarm()) {+ instant_remote_process(["docker stack rm {$application->uuid}"], $server);+ return;}- if ($application->build_pack === 'dockercompose') {- $uuid = $application->uuid;- $application->delete_connected_networks($uuid);+ $containersToStop = $application->getContainersToStop($previewDeployments);+ $application->stopContainers($containersToStop, $server);++ if ($application->build_pack === 'dockercompose') {+ $application->delete_connected_networks($application->uuid);CleanupDocker::run($server, true);}+ } catch (\Exception $e) {+ ray($e->getMessage());+ return $e->getMessage();}}}diff --git a/app/Actions/Service/StopService.php b/app/Actions/Service/StopService.phpindex 0357818851..6b348f8300 100644--- a/app/Actions/Service/StopService.php+++ b/app/Actions/Service/StopService.php@@ -5,8 +5,6 @@ namespace App\Actions\Service;use App\Models\Service;use App\Actions\Server\CleanupDocker;use Lorisleiva\Actions\Concerns\AsAction;-use Illuminate\Support\Facades\Process;-use Illuminate\Process\InvokedProcess;class StopService{@@ -21,9 +19,8 @@ class StopService}ray('Stopping service: ' . $service->name);- $containersToStop = $this->getContainersToStop($service);-- $this->stopContainers($containersToStop, $server);+ $containersToStop = $service->getContainersToStop();+ $service->stopContainers($containersToStop, $server);if (!$isDeleteOperation) {$service->delete_connected_networks($service->uuid);@@ -34,62 +31,4 @@ class StopServicereturn $e->getMessage();}}-- private function getContainersToStop(Service $service): array- {- $containersToStop = [];- $applications = $service->applications()->get();- foreach ($applications as $application) {- $containersToStop[] = "{$application->name}-{$service->uuid}";- }- $dbs = $service->databases()->get();- foreach ($dbs as $db) {- $containersToStop[] = "{$db->name}-{$service->uuid}";- }- return $containersToStop;- }-- private function stopContainers(array $containerNames, $server, int $timeout = 300)- {- $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);- }- }-- private function stopContainer(string $containerName, $server, int $timeout): InvokedProcess- {- return Process::timeout($timeout)->start("docker stop --time=$timeout $containerName");- }-- private function removeContainer(string $containerName, $server)- {- instant_remote_process(command: ["docker rm -f $containerName"], server: $server, throwError: false);- }-- private function forceStopRemainingContainers(array $containerNames, $server)- {- foreach ($containerNames as $containerName) {- instant_remote_process(command: ["docker kill $containerName"], server: $server, throwError: false);- $this->removeContainer($containerName, $server);- }- }}