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.

fix: cleanup stucked resources on start

Andras Bacsai554222abc71d
diff --git a/app/Console/Commands/Init.php b/app/Console/Commands/Init.php
index 446b0c6932..6abac70298 100644
--- a/app/Console/Commands/Init.php
+++ b/app/Console/Commands/Init.php
@@ -3,7 +3,12 @@
namespace App\Console\Commands;
use App\Enums\ApplicationDeploymentStatus;
+use App\Models\Application;
use App\Models\ApplicationDeploymentQueue;
+use App\Models\Service;
+use App\Models\StandaloneMongodb;
+use App\Models\StandalonePostgresql;
+use App\Models\StandaloneRedis;
use Illuminate\Console\Command;
class Init extends Command
@@ -13,7 +18,9 @@ class Init extends Command
public function handle()
{
+ ray()->clearAll();
$this->cleanup_in_progress_application_deployments();
+ $this->cleanup_stucked_resources();
}
private function cleanup_in_progress_application_deployments()
@@ -30,4 +37,70 @@ class Init extends Command
echo "Error: {$e->getMessage()}\n";
}
}
+ private function cleanup_stucked_resources() {
+ // Cleanup any resources that are not attached to any environment or destination or server
+ try {
+ $applications = Application::all();
+ foreach($applications as $application) {
+ if (!$application->environment) {
+ ray('Application without environment', $application->name);
+ $application->delete();
+ }
+ if (!$application->destination()) {
+ ray('Application without destination', $application->name);
+ $application->delete();
+ }
+ }
+ $postgresqls = StandalonePostgresql::all();
+ foreach($postgresqls as $postgresql) {
+ if (!$postgresql->environment) {
+ ray('Postgresql without environment', $postgresql->name);
+ $postgresql->delete();
+ }
+ if (!$postgresql->destination()) {
+ ray('Postgresql without destination', $postgresql->name);
+ $postgresql->delete();
+ }
+ }
+ $redis = StandaloneRedis::all();
+ foreach($redis as $redis) {
+ if (!$redis->environment) {
+ ray('Redis without environment', $redis->name);
+ $redis->delete();
+ }
+ if (!$redis->destination()) {
+ ray('Redis without destination', $redis->name);
+ $redis->delete();
+ }
+ }
+ $mongodbs = StandaloneMongodb::all();
+ foreach($mongodbs as $mongodb) {
+ if (!$mongodb->environment) {
+ ray('Mongodb without environment', $mongodb->name);
+ $mongodb->delete();
+ }
+ if (!$mongodb->destination()) {
+ ray('Mongodb without destination', $mongodb->name);
+ $mongodb->delete();
+ }
+ }
+ $services = Service::all();
+ foreach($services as $service) {
+ if (!$service->environment) {
+ ray('Service without environment', $service->name);
+ $service->delete();
+ }
+ if (!$service->server) {
+ ray('Service without server', $service->name);
+ $service->delete();
+ }
+ if (!$service->destination()) {
+ ray('Service without destination', $service->name);
+ $service->delete();
+ }
+ }
+ } catch (\Throwable $e) {
+ echo "Error: {$e->getMessage()}\n";
+ }
+ }
}