lasthourcloud/app/Actions/Application/StopApplication.php

50 lines
1.7 KiB
PHP
Raw Normal View History

<?php
namespace App\Actions\Application;
use App\Models\Application;
use Lorisleiva\Actions\Concerns\AsAction;
class StopApplication
{
use AsAction;
2024-06-10 20:43:34 +00:00
public function handle(Application $application)
{
if ($application->destination->server->isSwarm()) {
instant_remote_process(["docker stack rm {$application->uuid}"], $application->destination->server);
2024-06-10 20:43:34 +00:00
return;
}
$servers = collect([]);
$servers->push($application->destination->server);
2024-02-07 13:55:06 +00:00
$application->additional_servers->map(function ($server) use ($servers) {
$servers->push($server);
});
foreach ($servers as $server) {
2024-06-10 20:43:34 +00:00
if (! $server->isFunctional()) {
return 'Server is not functional';
}
2023-11-28 17:31:04 +00:00
$containers = getCurrentApplicationContainerStatus($server, $application->id, 0);
if ($containers->count() > 0) {
foreach ($containers as $container) {
$containerName = data_get($container, 'Names');
if ($containerName) {
instant_remote_process(
["docker rm -f {$containerName}"],
$server
);
}
}
}
if ($application->build_pack === 'dockercompose') {
2024-07-11 09:30:20 +00:00
// remove network
$uuid = $application->uuid;
2024-07-11 09:30:20 +00:00
instant_remote_process(["docker network disconnect {$uuid} coolify-proxy"], $server, false);
instant_remote_process(["docker network rm {$uuid}"], $server, false);
}
2023-11-27 14:25:15 +00:00
}
}
}