diff --git a/inc/vCenter-SSL.ps1 b/inc/vCenter-SSL.ps1 index 8baac630..80aa7095 100644 --- a/inc/vCenter-SSL.ps1 +++ b/inc/vCenter-SSL.ps1 @@ -1,6 +1,6 @@ #!/usr/bin/env pwsh # ----------------------------------------------------------------------------------- -# vCenter + Posh-ACME Script (Fully Automated with Verbose Logging) +# vCenter + Posh-ACME Script (Fully Automated with Verbose Logging and SSH Fallback) # ----------------------------------------------------------------------------------- . /opt/idssys/nodemgmt/conf/powerwall/settings.ps1 @@ -36,8 +36,6 @@ if (-not (Get-Module -ListAvailable -Name VMware.PowerCLI)) { Install-Module -Name VMware.PowerCLI -Force -Scope AllUsers } Import-Module VMware.PowerCLI -ErrorAction Stop - -# Ignore self-signed cert warnings Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false | Out-Null # ---------------------------- @@ -104,7 +102,6 @@ try { # Collect certificate paths dynamically # ---------------------------- if ($certSuccess) { - # Get the most recent order $paOrder = Get-PAOrder | Sort-Object Created -Descending | Select-Object -First 1 $certFolder = $paOrder.CertFolder @@ -153,7 +150,7 @@ if ($certSuccess) { } # ---------------------------- -# Automatic vpxd restart via REST with verbose logging +# Automatic vpxd restart via REST with retries, fallback to SSH # ---------------------------- $maxRetries = 20 $retryCount = 0 @@ -161,16 +158,14 @@ $restartSucceeded = $false while ($retryCount -lt $maxRetries -and -not $restartSucceeded) { try { - # Test if REST endpoint is available $healthUri = "https://$VCENTERHOST/rest/appliance/health/system" Write-Host "Checking vCenter REST health endpoint..." -ForegroundColor Cyan $resp = Invoke-RestMethod -Uri $healthUri -Method Get -SkipCertificateCheck -ErrorAction Stop - # Restart vpxd service $restartUri = "https://$VCENTERHOST/rest/appliance/system/services/vpxd?action=restart" Write-Host "Requesting vpxd service restart via REST..." -ForegroundColor Cyan Invoke-RestMethod -Uri $restartUri -Method Post -SkipCertificateCheck -ErrorAction Stop - Write-Host "vpxd service restart requested successfully." -ForegroundColor Green + Write-Host "vpxd service restart requested successfully via REST." -ForegroundColor Green $restartSucceeded = $true } catch { Write-Host "vpxd REST endpoint not ready yet, retrying in 15 seconds... (Attempt $($retryCount+1)/$maxRetries)" -ForegroundColor Yellow @@ -180,9 +175,18 @@ while ($retryCount -lt $maxRetries -and -not $restartSucceeded) { } if (-not $restartSucceeded) { - Write-Host "Automatic vpxd restart failed after $maxRetries attempts." -ForegroundColor Red - Write-Host "Please restart manually via SSH:" -ForegroundColor Red - Write-Host "ssh root@$VCENTERHOST 'service-control --stop vpxd; service-control --start vpxd'" -ForegroundColor Red + Write-Host "REST endpoint failed after $maxRetries attempts, falling back to SSH restart..." -ForegroundColor Yellow + try { + Write-Host "Restarting vpxd via SSH..." -ForegroundColor Cyan + $sshCommand = "service-control --stop vpxd; service-control --start vpxd" + ssh root@$VCENTERHOST $sshCommand + Write-Host "vpxd service restarted successfully via SSH." -ForegroundColor Green + $restartSucceeded = $true + } catch { + Write-Host "SSH fallback restart failed: $($_.Exception.Message)" -ForegroundColor Red + Write-Host "Please restart manually via SSH:" -ForegroundColor Red + Write-Host "ssh root@$VCENTERHOST 'service-control --stop vpxd; service-control --start vpxd'" -ForegroundColor Red + } } # ----------------------------