2023-09-21 19:30:13 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Actions\Service;
|
|
|
|
|
|
|
|
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
|
|
|
|
2023-09-21 19:30:13 +00:00
|
|
|
public function handle(Service $service)
|
|
|
|
{
|
2024-02-08 12:10:29 +00:00
|
|
|
try {
|
|
|
|
$server = $service->destination->server;
|
2024-06-10 20:43:34 +00:00
|
|
|
if (! $server->isFunctional()) {
|
2024-02-08 12:10:29 +00:00
|
|
|
return 'Server is not functional';
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
ray('Stopping service: '.$service->name);
|
2024-02-08 12:10:29 +00:00
|
|
|
$applications = $service->applications()->get();
|
|
|
|
foreach ($applications as $application) {
|
2024-07-11 08:16:56 +00:00
|
|
|
instant_remote_process(["docker rm -f {$application->name}-{$service->uuid}"], $service->server, false);
|
2024-02-08 12:10:29 +00:00
|
|
|
$application->update(['status' => 'exited']);
|
|
|
|
}
|
|
|
|
$dbs = $service->databases()->get();
|
|
|
|
foreach ($dbs as $db) {
|
2024-07-11 08:16:56 +00:00
|
|
|
instant_remote_process(["docker rm -f {$db->name}-{$service->uuid}"], $service->server, false);
|
2024-02-08 12:10:29 +00:00
|
|
|
$db->update(['status' => 'exited']);
|
|
|
|
}
|
2024-07-11 08:16:56 +00:00
|
|
|
instant_remote_process(["docker network disconnect {$service->uuid} coolify-proxy"], $service->server);
|
|
|
|
instant_remote_process(["docker network rm {$service->uuid}"], $service->server);
|
2024-02-08 12:10:29 +00:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
echo $e->getMessage();
|
|
|
|
ray($e->getMessage());
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-02-08 12:10:29 +00:00
|
|
|
return $e->getMessage();
|
2024-01-31 08:58:41 +00:00
|
|
|
}
|
2024-02-08 12:10:29 +00:00
|
|
|
|
2023-09-21 19:30:13 +00:00
|
|
|
}
|
|
|
|
}
|