lasthourcloud/app/Actions/Application/StopApplication.php

44 lines
1.3 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
);
}
}
}
2023-11-27 14:25:15 +00:00
}
}
}