Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

Merge branch 'main' into feat/add-sqlite-database

peaklabs-deva52cafb2db17
diff --cc app/Actions/Database/RestartDatabase.php
index db3ce6025f,3e8f6dec83..6efaf8812f
--- a/app/Actions/Database/RestartDatabase.php
+++ b/app/Actions/Database/RestartDatabase.php
@@@ -10,29 -10,44 +10,45 @@@ use App\Models\StandaloneMongodb
use App\Models\StandaloneMysql;
use App\Models\StandalonePostgresql;
use App\Models\StandaloneRedis;
+use App\Models\StandaloneSqlite;
+ use App\Support\DatabaseOperationReservation;
+ use App\Support\ResourceStartActivity;
use Lorisleiva\Actions\Concerns\AsAction;
class RestartDatabase
{
use AsAction;
- public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse|StandaloneSqlite $database)
+ /**
+ * @param string|null $reservation The token from StartDatabase::reserveOperation(). The request
+ * that queued this action holds the reservation; this action
+ * keeps it during the stop and releases it after the start.
+ */
- public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $database, ?string $reservation = null)
++ public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse|StandaloneSqlite $database, ?string $reservation = null)
{
- $server = $database->destination->server;
- if (! $server->isFunctional()) {
- return 'Server is not functional';
+ $reservation ??= DatabaseOperationReservation::acquire($database->uuid);
+ if ($reservation === null) {
+ return ResourceStartActivity::DATABASE_OPERATION_IN_PROGRESS_MESSAGE;
}
- $busyError = StartDatabase::operationInProgressError($database);
- if ($busyError !== null) {
- return $busyError;
- }
- $prerequisiteError = StartDatabase::prerequisiteError($database);
- if ($prerequisiteError !== null) {
- return $prerequisiteError;
- }
- StopDatabase::run($database, dockerCleanup: false);
- return StartDatabase::run($database);
+ try {
+ $server = $database->destination->server;
+ if (! $server->isFunctional()) {
+ return 'Server is not functional';
+ }
+ $busyError = StartDatabase::operationInProgressError($database, $reservation);
+ if ($busyError !== null) {
+ return $busyError;
+ }
+ $prerequisiteError = StartDatabase::prerequisiteError($database);
+ if ($prerequisiteError !== null) {
+ return $prerequisiteError;
+ }
+ StopDatabase::run($database, dockerCleanup: false);
+
+ return StartDatabase::run($database, $reservation);
+ } finally {
+ DatabaseOperationReservation::release($database->uuid, $reservation);
+ }
}
}
diff --cc app/Actions/Database/StartDatabase.php
index e272b7edc4,5e75d8d0b5..169d996f9a
--- a/app/Actions/Database/StartDatabase.php
+++ b/app/Actions/Database/StartDatabase.php
@@@ -14,7 -14,7 +14,8 @@@ use App\Models\StandaloneMongodb
use App\Models\StandaloneMysql;
use App\Models\StandalonePostgresql;
use App\Models\StandaloneRedis;
+use App\Models\StandaloneSqlite;
+ use App\Support\DatabaseOperationReservation;
use App\Support\ResourceStartActivity;
use Lorisleiva\Actions\Concerns\AsAction;
use Lorisleiva\Actions\Decorators\JobDecorator;
@@@ -30,7 -30,25 +31,25 @@@ class StartDatabas
$job->onQueue(deployment_queue());
}
- public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse|StandaloneSqlite $database): Activity|string
+ /**
+ * @param string|null $reservation The token from reserveOperation(). The request that queued
+ * this action holds the reservation; this action releases it.
+ */
- public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $database, ?string $reservation = null): Activity|string
++ public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse|StandaloneSqlite $database, ?string $reservation = null): Activity|string
+ {
+ $reservation ??= DatabaseOperationReservation::acquire($database->uuid);
+ if ($reservation === null) {
+ return ResourceStartActivity::DATABASE_OPERATION_IN_PROGRESS_MESSAGE;
+ }
+
+ try {
+ return $this->queueStart($database, $reservation);
+ } finally {
+ DatabaseOperationReservation::release($database->uuid, $reservation);
+ }
+ }
+
- private function queueStart(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $database, string $reservation): Activity|string
++ private function queueStart(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse|StandaloneSqlite $database, string $reservation): Activity|string
{
$server = $database->destination->server;
if (! $server->isFunctional()) {
@@@ -88,12 -106,55 +107,55 @@@
return $activity;
}
+ /**
+ * Reserve a start or restart before it is queued, so that a parallel request cannot also
+ * queue one before the queued action has created its activity. Pass the token to the
+ * queued action, which releases the reservation.
+ *
+ * @return string|null The reservation token, or null when another operation is in progress.
+ */
- public static function reserveOperation(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $database): ?string
++ public static function reserveOperation(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse|StandaloneSqlite $database): ?string
+ {
+ $reservation = DatabaseOperationReservation::acquire($database->uuid);
+ if ($reservation === null) {
+ return null;
+ }
+
+ if (self::operationInProgressError($database, $reservation) !== null) {
+ DatabaseOperationReservation::release($database->uuid, $reservation);
+
+ return null;
+ }
+
+ return $reservation;
+ }
+
+ /**
+ * Queue a start or restart action with a reservation. Release the reservation if the
+ * action cannot be queued, because then no action will release it.
+ *
+ * @param class-string<StartDatabase|RestartDatabase> $action
+ */
- public static function dispatchReserved(string $action, StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $database, string $reservation): void
++ public static function dispatchReserved(string $action, StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse|StandaloneSqlite $database, string $reservation): void
+ {
+ try {
+ $action::dispatch($database, $reservation);
+ } catch (Throwable $e) {
+ DatabaseOperationReservation::release($database->uuid, $reservation);
+
+ throw $e;
+ }
+ }
+
/**
* Refuse a second start/restart while a start, restart or import of this database is
- * queued or running. The UI hides Start/Restart in this state; this is the server-side check.
- * Stale start activities do not block and are marked as failed, so the UI stays consistent.
+ * reserved, queued or running. The UI hides Start/Restart in this state; this is the
+ * server-side check. Stale start activities do not block and are marked as failed, so
+ * the UI stays consistent.
+ *
+ * @param string|null $reservation The token of the caller's own reservation, which does not block.
*/
- public static function operationInProgressError(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $database): ?string
- public static function operationInProgressError(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $database, ?string $reservation = null): ?string
++ public static function operationInProgressError(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse|StandaloneSqlite $database, ?string $reservation = null): ?string
{
if (blank($database->uuid)) {
return null;
@@@ -115,7 -180,7 +181,7 @@@
* Check prerequisites that would make the queued start fail, so the user gets the
* error immediately instead of a queued start that can only fail later.
*/
-- public static function prerequisiteError(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $database): ?string
++ public static function prerequisiteError(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse|StandaloneSqlite $database): ?string
{
if (! $database->enable_ssl) {
return null;
diff --cc app/Http/Controllers/Api/DatabasesController.php
index 4b5f65a599,e828066742..178d1f12e7
--- a/app/Http/Controllers/Api/DatabasesController.php
+++ b/app/Http/Controllers/Api/DatabasesController.php
@@@ -21,8 -21,8 +21,9 @@@ use App\Models\ScheduledDatabaseBackup
use App\Models\Server;
use App\Models\StandaloneDocker;
use App\Models\StandalonePostgresql;
+use App\Models\StandaloneSqlite;
use App\Models\SwarmDocker;
+ use App\Support\ResourceStartActivity;
use App\Support\ValidationPatterns;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\JsonResponse;