2023-10-14 12:22:07 +00:00
|
|
|
<?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
|
|
|
|
2023-10-14 12:22:07 +00:00
|
|
|
public function handle(Application $application)
|
|
|
|
{
|
2024-02-06 14:05:11 +00:00
|
|
|
if ($application->destination->server->isSwarm()) {
|
|
|
|
instant_remote_process(["docker stack rm {$application->uuid}"], $application->destination->server);
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-02-06 14:05:11 +00:00
|
|
|
return;
|
2024-01-30 08:48:51 +00:00
|
|
|
}
|
2024-02-06 14:05:11 +00:00
|
|
|
|
|
|
|
$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);
|
2024-02-06 14:05:11 +00:00
|
|
|
});
|
|
|
|
foreach ($servers as $server) {
|
2024-06-10 20:43:34 +00:00
|
|
|
if (! $server->isFunctional()) {
|
2024-02-06 14:05:11 +00:00
|
|
|
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
|
|
|
|
);
|
|
|
|
}
|
2023-10-14 12:22:07 +00:00
|
|
|
}
|
|
|
|
}
|
2024-07-11 08:16:56 +00:00
|
|
|
if ($application->build_pack === 'dockercompose') {
|
2024-07-11 09:30:20 +00:00
|
|
|
// remove network
|
2024-07-11 08:16:56 +00:00
|
|
|
$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);
|
2024-07-11 08:16:56 +00:00
|
|
|
}
|
2023-11-27 14:25:15 +00:00
|
|
|
}
|
2023-10-14 12:22:07 +00:00
|
|
|
}
|
|
|
|
}
|