2023-10-14 12:22:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Actions\Database;
|
|
|
|
|
|
2024-09-18 19:18:47 +00:00
|
|
|
use App\Actions\Server\CleanupDocker;
|
2024-04-10 13:00:46 +00:00
|
|
|
use App\Models\StandaloneClickhouse;
|
|
|
|
|
use App\Models\StandaloneDragonfly;
|
|
|
|
|
use App\Models\StandaloneKeydb;
|
2023-10-24 12:31:28 +00:00
|
|
|
use App\Models\StandaloneMariadb;
|
2023-10-19 11:32:03 +00:00
|
|
|
use App\Models\StandaloneMongodb;
|
2023-10-24 12:31:28 +00:00
|
|
|
use App\Models\StandaloneMysql;
|
2023-10-14 12:22:07 +00:00
|
|
|
use App\Models\StandalonePostgresql;
|
|
|
|
|
use App\Models\StandaloneRedis;
|
|
|
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
|
|
|
|
|
|
|
|
|
class StopDatabase
|
|
|
|
|
{
|
|
|
|
|
use AsAction;
|
|
|
|
|
|
2024-09-04 12:59:44 +00:00
|
|
|
public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $database, bool $isDeleteOperation = false, bool $dockerCleanup = true)
|
2023-10-14 12:22:07 +00:00
|
|
|
{
|
|
|
|
|
$server = $database->destination->server;
|
2024-09-18 19:18:47 +00:00
|
|
|
if (! $server->isFunctional()) {
|
2024-01-30 08:48:51 +00:00
|
|
|
return 'Server is not functional';
|
|
|
|
|
}
|
2024-08-06 11:27:06 +00:00
|
|
|
|
2025-04-30 15:39:33 +00:00
|
|
|
$this->stopContainer($database, $database->uuid, 30);
|
2025-03-17 17:52:34 +00:00
|
|
|
if ($isDeleteOperation) {
|
2025-01-07 14:31:43 +00:00
|
|
|
if ($dockerCleanup) {
|
|
|
|
|
CleanupDocker::dispatch($server, true);
|
|
|
|
|
}
|
2024-08-09 20:15:45 +00:00
|
|
|
}
|
2024-08-06 11:27:06 +00:00
|
|
|
|
2023-10-14 12:22:07 +00:00
|
|
|
if ($database->is_public) {
|
|
|
|
|
StopDatabaseProxy::run($database);
|
|
|
|
|
}
|
2024-08-09 20:15:45 +00:00
|
|
|
|
|
|
|
|
return 'Database stopped successfully';
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-30 07:59:03 +00:00
|
|
|
private function stopContainer($database, string $containerName, int $timeout = 30): void
|
2024-08-09 20:15:45 +00:00
|
|
|
{
|
|
|
|
|
$server = $database->destination->server;
|
2025-04-30 07:59:03 +00:00
|
|
|
instant_remote_process(command: [
|
|
|
|
|
"docker stop --time=$timeout $containerName",
|
|
|
|
|
"docker rm -f $containerName",
|
|
|
|
|
], server: $server, throwError: false);
|
2025-01-07 14:31:43 +00:00
|
|
|
}
|
2023-10-14 12:22:07 +00:00
|
|
|
}
|