feat: start Sentinel on servers.

This commit is contained in:
Andras Bacsai 2024-05-08 14:22:35 +02:00
parent 2ea27acdde
commit c618e58a11
5 changed files with 36 additions and 2 deletions

View File

@ -55,10 +55,10 @@ public function handle()
$sentinel_found = json_decode($sentinel_found, true);
$status = data_get($sentinel_found, '0.State.Status', 'exited');
if ($status === 'running') {
ray('Sentinel');
ray('Checking with Sentinel');
$this->sentinel();
} else {
ray('Old way');
ray('Checking the Old way');
$this->old_way();
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace App\Actions\Server;
use Lorisleiva\Actions\Concerns\AsAction;
use App\Models\Server;
class StartSentinel
{
use AsAction;
public function handle(Server $server)
{
return instant_remote_process(['docker run --pull always -d --name coolify-sentinel --restart always -p 127.0.0.1:8888:8888 -v /var/run/docker.sock:/var/run/docker.sock -v /data/coolify/metrics:/var/www/html/storage/app/metrics --pid host --health-cmd "curl --fail http://127.0.0.1:8888/api/health || exit 1" --health-interval 10s --health-retries 3 ghcr.io/coollabsio/sentinel:latest'], $server, false);
}
}

View File

@ -44,6 +44,7 @@ public function handle()
if ($this->server->isFunctional()) {
$this->cleanup(notify: false);
$this->removeCoolifyYaml();
$this->server->checkSentinel();
}
} catch (\Throwable $e) {
send_internal_notification('ServerStatusJob failed with: ' . $e->getMessage());

View File

@ -3,6 +3,7 @@
namespace App\Models;
use App\Actions\Server\InstallDocker;
use App\Actions\Server\StartSentinel;
use App\Enums\ProxyTypes;
use App\Notifications\Server\Revived;
use App\Notifications\Server\Unreachable;
@ -462,6 +463,20 @@ public function forceDisableServer()
Storage::disk('ssh-keys')->delete($sshKeyFileLocation);
Storage::disk('ssh-mux')->delete($this->muxFilename());
}
public function checkSentinel() {
ray("Checking sentinel on server: {$this->name}");
if ($this->is_metrics_enabled) {
$sentinel_found = instant_remote_process(["docker inspect coolify-sentinel"], $this, false);
$sentinel_found = json_decode($sentinel_found, true);
$status = data_get($sentinel_found, '0.State.Status', 'exited');
if ($status !== 'running') {
ray('Sentinel is not running, starting it...');
StartSentinel::dispatch($this);
} else {
ray('Sentinel is running');
}
}
}
public function isServerReady(int $tries = 3)
{
if ($this->skipServer()) {

View File

@ -112,6 +112,9 @@ services:
- "127.0.0.1:8888:8888"
healthcheck:
test: curl --fail http://127.0.0.1:8888/api/health || exit 1
interval: 10s
retries: 2
timeout: 5s
postgres:
volumes:
- coolify-db:/var/lib/postgresql/data