2023-09-21 19:30:13 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Actions\Service;
|
|
|
|
|
|
2024-08-09 16:59:41 +00:00
|
|
|
use App\Actions\Server\CleanupDocker;
|
2024-09-23 10:10:46 +00:00
|
|
|
use App\Models\Service;
|
2024-06-10 20:43:34 +00:00
|
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
2023-09-21 19:30:13 +00:00
|
|
|
|
|
|
|
|
class StopService
|
|
|
|
|
{
|
|
|
|
|
use AsAction;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-11-22 10:16:01 +00:00
|
|
|
public string $jobQueue = 'high';
|
|
|
|
|
|
2024-09-04 12:34:46 +00:00
|
|
|
public function handle(Service $service, bool $isDeleteOperation = false, bool $dockerCleanup = true)
|
2023-09-21 19:30:13 +00:00
|
|
|
{
|
2024-02-08 12:10:29 +00:00
|
|
|
try {
|
|
|
|
|
$server = $service->destination->server;
|
2024-09-23 10:10:46 +00:00
|
|
|
if (! $server->isFunctional()) {
|
2024-02-08 12:10:29 +00:00
|
|
|
return 'Server is not functional';
|
|
|
|
|
}
|
2024-08-09 17:17:58 +00:00
|
|
|
|
2024-08-09 17:39:43 +00:00
|
|
|
$containersToStop = $service->getContainersToStop();
|
|
|
|
|
$service->stopContainers($containersToStop, $server);
|
2024-08-09 00:59:41 +00:00
|
|
|
|
2024-09-23 10:10:46 +00:00
|
|
|
if (! $isDeleteOperation) {
|
2024-08-09 00:59:41 +00:00
|
|
|
$service->delete_connected_networks($service->uuid);
|
2024-09-04 12:34:46 +00:00
|
|
|
if ($dockerCleanup) {
|
2024-09-23 10:10:46 +00:00
|
|
|
CleanupDocker::dispatch($server, true);
|
2024-09-04 12:34:46 +00:00
|
|
|
}
|
2024-08-09 00:59:41 +00:00
|
|
|
}
|
2025-01-07 14:31:43 +00:00
|
|
|
} catch (\Exception $e) {
|
2024-02-08 12:10:29 +00:00
|
|
|
return $e->getMessage();
|
2024-01-31 08:58:41 +00:00
|
|
|
}
|
2023-09-21 19:30:13 +00:00
|
|
|
}
|
2024-08-09 20:15:45 +00:00
|
|
|
}
|