mirror of
https://github.com/coollabsio/coolify.git
synced 2026-08-29 02:24:29 -05:00
Integrates Valkey as a new standalone database type. This includes adding the necessary model, updating actions to handle Valkey instances, and documenting the integration process.
58 lines
1.8 KiB
PHP
58 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Actions\Database;
|
|
|
|
use App\Actions\Server\CleanupDocker;
|
|
use App\Events\ServiceStatusChanged;
|
|
use App\Models\StandaloneClickhouse;
|
|
use App\Models\StandaloneDragonfly;
|
|
use App\Models\StandaloneKeydb;
|
|
use App\Models\StandaloneMariadb;
|
|
use App\Models\StandaloneMongodb;
|
|
use App\Models\StandaloneMysql;
|
|
use App\Models\StandalonePostgresql;
|
|
use App\Models\StandaloneRedis;
|
|
use App\Models\StandaloneValkey;
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
|
|
|
class StopDatabase
|
|
{
|
|
use AsAction;
|
|
|
|
public function handle(StandaloneRedis|StandaloneValkey|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $database, bool $dockerCleanup = true)
|
|
{
|
|
try {
|
|
$server = $database->destination->server;
|
|
if (! $server->isFunctional()) {
|
|
return 'Server is not functional';
|
|
}
|
|
|
|
$this->stopContainer($database, $database->uuid, 30);
|
|
|
|
if ($dockerCleanup) {
|
|
CleanupDocker::dispatch($server, false, false);
|
|
}
|
|
|
|
if ($database->is_public) {
|
|
StopDatabaseProxy::run($database);
|
|
}
|
|
|
|
return 'Database stopped successfully';
|
|
} catch (\Exception $e) {
|
|
return 'Database stop failed: '.$e->getMessage();
|
|
} finally {
|
|
ServiceStatusChanged::dispatch($database->environment->project->team->id);
|
|
}
|
|
|
|
}
|
|
|
|
private function stopContainer($database, string $containerName, int $timeout = 30): void
|
|
{
|
|
$server = $database->destination->server;
|
|
instant_remote_process(command: [
|
|
"docker stop --timeout=$timeout $containerName",
|
|
"docker rm -f $containerName",
|
|
], server: $server, throwError: false);
|
|
}
|
|
}
|