fix(sentinel): prevent restart after Sentinel is disabled (#11298)
This commit is contained in:
parent
1c25b58dc8
commit
81ed9a3af2
2 changed files with 48 additions and 3 deletions
|
|
@ -21,6 +21,10 @@ public function __construct(public Server $server) {}
|
|||
|
||||
public function handle(): void
|
||||
{
|
||||
if (! $this->sentinelIsEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$latestVersion = get_latest_sentinel_version();
|
||||
|
||||
// Check if sentinel is running
|
||||
|
|
@ -28,7 +32,7 @@ public function handle(): void
|
|||
$sentinelFoundJson = json_decode($sentinelFound, true);
|
||||
$sentinelStatus = data_get($sentinelFoundJson, '0.State.Status', 'exited');
|
||||
if ($sentinelStatus !== 'running') {
|
||||
StartSentinel::run(server: $this->server, restart: true, latestVersion: $latestVersion);
|
||||
$this->startSentinel($latestVersion);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -38,15 +42,31 @@ public function handle(): void
|
|||
$runningVersion = '0.0.0';
|
||||
}
|
||||
if ($latestVersion === '0.0.0' && $runningVersion === '0.0.0') {
|
||||
StartSentinel::run(server: $this->server, restart: true, latestVersion: 'latest');
|
||||
$this->startSentinel('latest');
|
||||
|
||||
return;
|
||||
} else {
|
||||
if (version_compare($runningVersion, $latestVersion, '<')) {
|
||||
StartSentinel::run(server: $this->server, restart: true, latestVersion: $latestVersion);
|
||||
$this->startSentinel($latestVersion);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function sentinelIsEnabled(): bool
|
||||
{
|
||||
$this->server->unsetRelation('settings');
|
||||
|
||||
return $this->server->isSentinelEnabled();
|
||||
}
|
||||
|
||||
private function startSentinel(string $latestVersion): void
|
||||
{
|
||||
if (! $this->sentinelIsEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
StartSentinel::run(server: $this->server, restart: true, latestVersion: $latestVersion);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
25
tests/Feature/Jobs/CheckAndStartSentinelJobTest.php
Normal file
25
tests/Feature/Jobs/CheckAndStartSentinelJobTest.php
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
use App\Jobs\CheckAndStartSentinelJob;
|
||||
use App\Models\Server;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
it('does not start Sentinel after it has been disabled', function () {
|
||||
DB::table('instance_settings')->insert(['id' => 0]);
|
||||
$user = User::factory()->create();
|
||||
$server = Server::factory()->create([
|
||||
'team_id' => $user->teams()->first()->id,
|
||||
]);
|
||||
$server->settings->update([
|
||||
'is_metrics_enabled' => false,
|
||||
'is_sentinel_enabled' => false,
|
||||
]);
|
||||
|
||||
(new CheckAndStartSentinelJob($server))->handle();
|
||||
|
||||
expect((bool) $server->settings->fresh()->is_sentinel_enabled)->toBeFalse();
|
||||
});
|
||||
Loading…
Reference in a new issue