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.

wip: server check instead of app check

Andras Bacsaicd0da04ea29f
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
index 85fa80aacf..ae40fec496 100644
--- a/app/Console/Kernel.php
+++ b/app/Console/Kernel.php
@@ -11,6 +11,7 @@ use App\Jobs\DatabaseContainerStatusJob;
use App\Jobs\DockerCleanupJob;
use App\Jobs\InstanceAutoUpdateJob;
use App\Jobs\ProxyContainerStatusJob;
+use App\Jobs\ServerDetailsCheckJob;
use App\Models\Application;
use App\Models\InstanceSettings;
use App\Models\ScheduledDatabaseBackup;
@@ -24,20 +25,25 @@ class Kernel extends ConsoleKernel
protected function schedule(Schedule $schedule): void
{
if (isDev()) {
- $schedule->command('horizon:snapshot')->everyMinute();
- $schedule->job(new CleanupInstanceStuffsJob)->everyMinute();
+ $schedule->job(new ServerDetailsCheckJob(Server::find(0)))->everyTenMinutes()->onOneServer();
+ // $schedule->command('horizon:snapshot')->everyMinute();
+ // $schedule->job(new CleanupInstanceStuffsJob)->everyMinute();
// $schedule->job(new CheckResaleLicenseJob)->hourly();
- $schedule->job(new DockerCleanupJob)->everyOddHour();
+ // $schedule->job(new DockerCleanupJob)->everyOddHour();
+ // $this->instance_auto_update($schedule);
+ // $this->check_scheduled_backups($schedule);
+ // $this->check_resources($schedule);
+ // $this->check_proxies($schedule);
} else {
$schedule->command('horizon:snapshot')->everyFiveMinutes();
$schedule->job(new CleanupInstanceStuffsJob)->everyTenMinutes()->onOneServer();
$schedule->job(new CheckResaleLicenseJob)->hourly()->onOneServer();
$schedule->job(new DockerCleanupJob)->everyTenMinutes()->onOneServer();
+ $this->instance_auto_update($schedule);
+ $this->check_scheduled_backups($schedule);
+ $this->check_resources($schedule);
+ $this->check_proxies($schedule);
}
- $this->instance_auto_update($schedule);
- $this->check_scheduled_backups($schedule);
- $this->check_resources($schedule);
- $this->check_proxies($schedule);
}
private function check_proxies($schedule)
{
diff --git a/app/Jobs/ServerDetailsCheckJob.php b/app/Jobs/ServerDetailsCheckJob.php
new file mode 100644
index 0000000000..606931c423
--- /dev/null
+++ b/app/Jobs/ServerDetailsCheckJob.php
@@ -0,0 +1,79 @@
+<?php
+
+namespace App\Jobs;
+
+use App\Models\Server;
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldBeUnique;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Bus\Dispatchable;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Queue\Middleware\WithoutOverlapping;
+use Illuminate\Queue\SerializesModels;
+use Str;
+
+class ServerDetailsCheckJob implements ShouldQueue, ShouldBeUnique
+{
+ use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+
+ public $tries = 1;
+ public $timeout = 120;
+
+ public function __construct(public Server $server)
+ {
+ }
+
+ public function middleware(): array
+ {
+ return [new WithoutOverlapping($this->server->uuid)];
+ }
+
+ public function uniqueId(): string
+ {
+ return $this->server->uuid;
+ }
+
+ public function handle(): void
+ {
+ try {
+ ray()->clearAll();
+ $containers = instant_remote_process(["docker container inspect $(docker container ls -q) --format '{{json .}}'"], $this->server);
+ $containers = format_docker_command_output_to_json($containers);
+ $applications = $this->server->applications();
+ // ray($applications);
+ // ray(format_docker_command_output_to_json($containers));
+ foreach ($applications as $application) {
+ $uuid = data_get($application, 'uuid');
+ $foundContainer = $containers->filter(function ($value, $key) use ($uuid) {
+ $image = data_get($value, 'Config.Image');
+ return Str::startsWith($image, $uuid);
+ })->first();
+
+ if ($foundContainer) {
+ $containerStatus = data_get($foundContainer, 'State.Status');
+ $databaseStatus = data_get($application, 'status');
+ ray($containerStatus, $databaseStatus);
+ if ($containerStatus !== $databaseStatus) {
+ // $application->update(['status' => $containerStatus]);
+ }
+ }
+ }
+ // foreach ($containers as $container) {
+ // $labels = format_docker_labels_to_json(data_get($container,'Config.Labels'));
+ // $foundLabel = $labels->filter(fn ($value, $key) => Str::startsWith($key, 'coolify.applicationId'));
+ // if ($foundLabel->count() > 0) {
+ // $appFound = $applications->where('id', $foundLabel['coolify.applicationId'])->first();
+ // if ($appFound) {
+ // $containerStatus = data_get($container, 'State.Status');
+ // $databaseStatus = data_get($appFound, 'status');
+ // ray($containerStatus, $databaseStatus);
+ // }
+ // }
+ // }
+ } catch (\Throwable $e) {
+ // send_internal_notification('ServerDetailsCheckJob failed with: ' . $e->getMessage());
+ ray($e->getMessage());
+ throw $e;
+ }
+ }
+}
diff --git a/bootstrap/helpers/docker.php b/bootstrap/helpers/docker.php
index 080448f712..e3629e71c1 100644
--- a/bootstrap/helpers/docker.php
+++ b/bootstrap/helpers/docker.php
@@ -26,8 +26,11 @@ function format_docker_command_output_to_json($rawOutput): Collection
->map(fn ($outputLine) => json_decode($outputLine, true, flags: JSON_THROW_ON_ERROR));
}
-function format_docker_labels_to_json($rawOutput): Collection
+function format_docker_labels_to_json(string|Array $rawOutput): Collection
{
+ if (is_array($rawOutput)) {
+ return collect($rawOutput);
+ }
$outputLines = explode(PHP_EOL, $rawOutput);
return collect($outputLines)