coolify/app/Actions/Service/StopService.php

37 lines
972 B
PHP
Raw Normal View History

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;
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
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
{
try {
$server = $service->destination->server;
if (! $server->isFunctional()) {
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);
if (! $isDeleteOperation) {
$service->delete_connected_networks($service->uuid);
2024-09-04 12:34:46 +00:00
if ($dockerCleanup) {
CleanupDocker::dispatch($server, true);
2024-09-04 12:34:46 +00:00
}
}
} catch (\Exception $e) {
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
}