2024-02-07 13:55:06 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Actions\Application;
|
|
|
|
|
|
|
|
use App\Models\Application;
|
|
|
|
use App\Models\Server;
|
|
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
|
|
|
|
|
|
|
class StopApplicationOneServer
|
|
|
|
{
|
|
|
|
use AsAction;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-02-07 13:55:06 +00:00
|
|
|
public function handle(Application $application, Server $server)
|
|
|
|
{
|
|
|
|
if ($application->destination->server->isSwarm()) {
|
|
|
|
return;
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
if (! $server->isFunctional()) {
|
2024-02-07 13:55:06 +00:00
|
|
|
return 'Server is not functional';
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
$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
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
ray($e->getMessage());
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-02-07 13:55:06 +00:00
|
|
|
return $e->getMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|