diff --git a/inc/vCenter-SSL.ps1 b/inc/vCenter-SSL.ps1 index ab0deee5..1ee8540c 100644 --- a/inc/vCenter-SSL.ps1 +++ b/inc/vCenter-SSL.ps1 @@ -1,6 +1,6 @@ #!/usr/bin/env pwsh # ----------------------------------------------------------------------------------- -# vCenter + Posh-ACME Script using PowerCLI (Final Working Version) +# vCenter + Posh-ACME Script using PowerCLI (Final Fully Automated Version) # ----------------------------------------------------------------------------------- . /opt/idssys/nodemgmt/conf/powerwall/settings.ps1 @@ -92,7 +92,7 @@ $certName = "vcenter-cert" $certSuccess = $false try { Write-Host "Requesting certificate via Posh-ACME..." -ForegroundColor Cyan - New-PACertificate -Domain $VCENTERHOST -DnsPlugin PowerDNS -DnsSleep 15 -PluginArgs $pArgs -Contact $ACMEEMAIL -AcceptTOS -Verbose -Force + New-PACertificate -Domain $VCENTERHOST -DnsPlugin PowerDNS -PluginArgs $pArgs -Contact $ACMEEMAIL -AcceptTOS -Verbose -Force -DnsSleep 15 $certSuccess = $true } catch { Write-Host "ACME certificate request failed: $($_.Exception.Message)" -ForegroundColor Yellow @@ -103,8 +103,9 @@ try { # Collect certificate paths dynamically # ---------------------------- if ($certSuccess) { - # Get the folder for this specific domain - $certFolder = (Get-PAOrder -Domain $VCENTERHOST).CertFolder + # Get the most recent certificate order + $paOrder = Get-PAOrder | Sort-Object Created -Descending | Select-Object -First 1 + $certFolder = $paOrder.CertFolder $certPath = Join-Path $certFolder "$certName\cert.pem" $keyPath = Join-Path $certFolder "$certName\privkey.pem" @@ -149,13 +150,37 @@ if ($certSuccess) { } # ---------------------------- -# vpxd restart note +# Automatic vpxd restart via REST (polling) +# ---------------------------- +$maxRetries = 20 +$retryCount = 0 +$restartSucceeded = $false + +while ($retryCount -lt $maxRetries -and -not $restartSucceeded) { + try { + # Test if REST endpoint is available + $healthUri = "https://$VCENTERHOST/rest/appliance/health/system" + $resp = Invoke-RestMethod -Uri $healthUri -Method Get -SkipCertificateCheck -ErrorAction Stop + + # Restart vpxd service + $restartUri = "https://$VCENTERHOST/rest/appliance/system/services/vpxd?action=restart" + Invoke-RestMethod -Uri $restartUri -Method Post -SkipCertificateCheck -ErrorAction Stop + Write-Host "vpxd service restart requested via REST." -ForegroundColor Green + $restartSucceeded = $true + } catch { + Write-Host "vpxd REST endpoint not ready yet, retrying in 15 seconds..." -ForegroundColor Yellow + Start-Sleep -Seconds 15 + $retryCount++ + } +} + +if (-not $restartSucceeded) { + Write-Host "Automatic vpxd restart failed. Please restart manually via SSH:" -ForegroundColor Red + Write-Host "ssh root@$VCENTERHOST 'service-control --stop vpxd; service-control --start vpxd'" -ForegroundColor Red +} + +# ---------------------------- +# Completion message # ---------------------------- -Write-Host "" -Write-Host "IMPORTANT:" -ForegroundColor Yellow -Write-Host "Automatic vpxd restart skipped because REST endpoint is not available." -ForegroundColor Yellow -Write-Host "Please restart the vCenter vpxd service manually via SSH:" -ForegroundColor Yellow -Write-Host "ssh root@$VCENTERHOST 'service-control --stop vpxd; service-control --start vpxd'" -ForegroundColor Yellow - Write-Host "" Write-Host "Script completed. Check `$global:helpme for any error details." -ForegroundColor Green