Add cleanup option to app:init command

This commit is contained in:
Andras Bacsai 2023-11-29 15:03:21 +01:00
parent f4803ad58b
commit 0dff57e69f
2 changed files with 30 additions and 29 deletions

View File

@ -30,6 +30,7 @@ public function handle()
$this->alive(); $this->alive();
$cleanup = $this->option('cleanup'); $cleanup = $this->option('cleanup');
if ($cleanup) { if ($cleanup) {
echo "Running cleanup\n";
$this->cleanup_stucked_resources(); $this->cleanup_stucked_resources();
$this->cleanup_ssh(); $this->cleanup_ssh();
} }
@ -101,14 +102,14 @@ private function cleanup_stucked_resources()
ray('Application without environment', $application->name); ray('Application without environment', $application->name);
$application->delete(); $application->delete();
} }
if (!data_get($application, 'destination.server')) {
ray('Application without server', $application->name);
$application->delete();
}
if (!$application->destination()) { if (!$application->destination()) {
ray('Application without destination', $application->name); ray('Application without destination', $application->name);
$application->delete(); $application->delete();
} }
if (!data_get($application, 'destination.server')) {
ray('Application without server', $application->name);
$application->delete();
}
} }
} catch (\Throwable $e) { } catch (\Throwable $e) {
echo "Error in application: {$e->getMessage()}\n"; echo "Error in application: {$e->getMessage()}\n";
@ -120,14 +121,14 @@ private function cleanup_stucked_resources()
ray('Postgresql without environment', $postgresql->name); ray('Postgresql without environment', $postgresql->name);
$postgresql->delete(); $postgresql->delete();
} }
if (!data_get($postgresql, 'destination.server')) {
ray('Postgresql without server', $postgresql->name);
$postgresql->delete();
}
if (!$postgresql->destination()) { if (!$postgresql->destination()) {
ray('Postgresql without destination', $postgresql->name); ray('Postgresql without destination', $postgresql->name);
$postgresql->delete(); $postgresql->delete();
} }
if (!data_get($postgresql, 'destination.server')) {
ray('Postgresql without server', $postgresql->name);
$postgresql->delete();
}
} }
} catch (\Throwable $e) { } catch (\Throwable $e) {
echo "Error in postgresql: {$e->getMessage()}\n"; echo "Error in postgresql: {$e->getMessage()}\n";
@ -139,14 +140,14 @@ private function cleanup_stucked_resources()
ray('Redis without environment', $redis->name); ray('Redis without environment', $redis->name);
$redis->delete(); $redis->delete();
} }
if (!data_get($redis, 'destination.server')) {
ray('Redis without server', $redis->name);
$redis->delete();
}
if (!$redis->destination()) { if (!$redis->destination()) {
ray('Redis without destination', $redis->name); ray('Redis without destination', $redis->name);
$redis->delete(); $redis->delete();
} }
if (!data_get($redis, 'destination.server')) {
ray('Redis without server', $redis->name);
$redis->delete();
}
} }
} catch (\Throwable $e) { } catch (\Throwable $e) {
echo "Error in redis: {$e->getMessage()}\n"; echo "Error in redis: {$e->getMessage()}\n";
@ -159,14 +160,14 @@ private function cleanup_stucked_resources()
ray('Mongodb without environment', $mongodb->name); ray('Mongodb without environment', $mongodb->name);
$mongodb->delete(); $mongodb->delete();
} }
if (!data_get($mongodb, 'destination.server')) {
ray('Mongodb without server', $mongodb->name);
$mongodb->delete();
}
if (!$mongodb->destination()) { if (!$mongodb->destination()) {
ray('Mongodb without destination', $mongodb->name); ray('Mongodb without destination', $mongodb->name);
$mongodb->delete(); $mongodb->delete();
} }
if (!data_get($mongodb, 'destination.server')) {
ray('Mongodb without server', $mongodb->name);
$mongodb->delete();
}
} }
} catch (\Throwable $e) { } catch (\Throwable $e) {
echo "Error in mongodb: {$e->getMessage()}\n"; echo "Error in mongodb: {$e->getMessage()}\n";
@ -179,14 +180,14 @@ private function cleanup_stucked_resources()
ray('Mysql without environment', $mysql->name); ray('Mysql without environment', $mysql->name);
$mysql->delete(); $mysql->delete();
} }
if (!data_get($mysql, 'destination.server')) {
ray('Mysql without server', $mysql->name);
$mysql->delete();
}
if (!$mysql->destination()) { if (!$mysql->destination()) {
ray('Mysql without destination', $mysql->name); ray('Mysql without destination', $mysql->name);
$mysql->delete(); $mysql->delete();
} }
if (!data_get($mysql, 'destination.server')) {
ray('Mysql without server', $mysql->name);
$mysql->delete();
}
} }
} catch (\Throwable $e) { } catch (\Throwable $e) {
echo "Error in mysql: {$e->getMessage()}\n"; echo "Error in mysql: {$e->getMessage()}\n";
@ -199,14 +200,14 @@ private function cleanup_stucked_resources()
ray('Mariadb without environment', $mariadb->name); ray('Mariadb without environment', $mariadb->name);
$mariadb->delete(); $mariadb->delete();
} }
if (!data_get($mariadb, 'destination.server')) {
ray('Mariadb without server', $mariadb->name);
$mariadb->delete();
}
if (!$mariadb->destination()) { if (!$mariadb->destination()) {
ray('Mariadb without destination', $mariadb->name); ray('Mariadb without destination', $mariadb->name);
$mariadb->delete(); $mariadb->delete();
} }
if (!data_get($mariadb, 'destination.server')) {
ray('Mariadb without server', $mariadb->name);
$mariadb->delete();
}
} }
} catch (\Throwable $e) { } catch (\Throwable $e) {
echo "Error in mariadb: {$e->getMessage()}\n"; echo "Error in mariadb: {$e->getMessage()}\n";
@ -219,14 +220,14 @@ private function cleanup_stucked_resources()
ray('Service without environment', $service->name); ray('Service without environment', $service->name);
$service->delete(); $service->delete();
} }
if (!data_get($service, 'server')) {
ray('Service without server', $service->name);
$service->delete();
}
if (!$service->destination()) { if (!$service->destination()) {
ray('Service without destination', $service->name); ray('Service without destination', $service->name);
$service->delete(); $service->delete();
} }
if (!data_get($service, 'server')) {
ray('Service without server', $service->name);
$service->delete();
}
} }
} catch (\Throwable $e) { } catch (\Throwable $e) {
echo "Error in service: {$e->getMessage()}\n"; echo "Error in service: {$e->getMessage()}\n";

View File

@ -1,2 +1,2 @@
#!/command/execlineb -P #!/command/execlineb -P
php /var/www/html/artisan app:init php /var/www/html/artisan app:init --cleanup