2023-09-21 19:30:13 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Actions\Service;
|
|
|
|
|
|
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
|
|
|
use App\Models\Service;
|
|
|
|
|
|
|
|
class StopService
|
|
|
|
{
|
|
|
|
use AsAction;
|
|
|
|
public function handle(Service $service)
|
|
|
|
{
|
2024-01-31 08:58:41 +00:00
|
|
|
$server = $service->destination->server;
|
|
|
|
if (!$server->isFunctional()) {
|
|
|
|
return 'Server is not functional';
|
|
|
|
}
|
2023-12-14 13:50:38 +00:00
|
|
|
ray('Stopping service: ' . $service->name);
|
2023-09-21 19:30:13 +00:00
|
|
|
$applications = $service->applications()->get();
|
|
|
|
foreach ($applications as $application) {
|
|
|
|
instant_remote_process(["docker rm -f {$application->name}-{$service->uuid}"], $service->server);
|
|
|
|
$application->update(['status' => 'exited']);
|
|
|
|
}
|
|
|
|
$dbs = $service->databases()->get();
|
|
|
|
foreach ($dbs as $db) {
|
|
|
|
instant_remote_process(["docker rm -f {$db->name}-{$service->uuid}"], $service->server);
|
|
|
|
$db->update(['status' => 'exited']);
|
|
|
|
}
|
2023-09-22 12:47:25 +00:00
|
|
|
instant_remote_process(["docker network disconnect {$service->uuid} coolify-proxy 2>/dev/null"], $service->server, false);
|
2023-09-27 20:35:10 +00:00
|
|
|
instant_remote_process(["docker network rm {$service->uuid} 2>/dev/null"], $service->server, false);
|
2023-10-14 12:22:07 +00:00
|
|
|
// TODO: make notification for databases
|
|
|
|
// $service->environment->project->team->notify(new StatusChanged($service));
|
2023-09-21 19:30:13 +00:00
|
|
|
}
|
|
|
|
}
|