fix(server): enable disabled self-hosted servers again on validation

On self-hosted, a validation that connects now clears force_disabled. The unreachable cleanup skips the localhost server, and the server page explains why a server is disabled. Cloud and transferred servers stay disabled.

Closes #12475
This commit is contained in:
Andras Bacsai
2026-11-06 18:57:06 +01:00
parent 5af4715b8a
commit f7ea962145
4 changed files with 101 additions and 1 deletions
@@ -15,7 +15,8 @@ class CleanupUnreachableServers extends Command
public function handle()
{
echo "Running unreachable server cleanup...\n";
$servers = Server::where('unreachable_count', '>=', 3)->whereHas('notificationThrottles', fn ($query) => $query->where('notification', Unreachable::class))->where('updated_at', '<', now()->subDays(7))->get();
// The localhost server is the Coolify host itself, so the cleanup never touches it.
$servers = Server::where('id', '!=', 0)->where('unreachable_count', '>=', 3)->whereHas('notificationThrottles', fn ($query) => $query->where('notification', Unreachable::class))->where('updated_at', '<', now()->subDays(7))->get();
if ($servers->count() > 0) {
foreach ($servers as $server) {
echo "Cleanup unreachable server ($server->id) with name $server->name";
+17
View File
@@ -1438,6 +1438,15 @@ $siteAddress {
return $this->settings->force_disabled;
}
/**
* On self-hosted, only the unreachable cleanup disables a server, so a working connection can enable it again.
* On Cloud the flag enforces the plan server limit, and a transferred server stays an archive.
*/
public function canBeReEnabled(): bool
{
return $this->settings->force_disabled === true && ! isCloud() && ! $this->isTransferredAway();
}
/**
* Server was migrated away from this Coolify instance (source side).
* Must not be revalidated or re-enabled as a live managed host.
@@ -2544,6 +2553,11 @@ $siteAddress {
public function validateConnection(bool $justCheckingNewKey = false)
{
// A validation enables a disabled self-hosted server again, but only when the connection works.
$isReEnabling = $this->canBeReEnabled() && ! $this->hasPlaceholderIp();
if ($isReEnabling) {
$this->forceEnableServer();
}
if ($this->skipServer()) {
return ['uptime' => false, 'error' => 'Server skipped.'];
}
@@ -2564,6 +2578,9 @@ $siteAddress {
return ['uptime' => true, 'error' => null];
} catch (\Throwable $e) {
if ($isReEnabling) {
$this->forceDisableServer();
}
$error = $e->getMessage();
if ($error === SshMultiplexingHelper::HOST_KEY_CHANGED_MESSAGE && ! $this->recordHostKeyMismatch()) {
$error = 'SSH host key verification failed, but the server still sends the trusted host key.';