Update vCenter-SSL.ps1
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env pwsh
|
#!/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
|
. /opt/idssys/nodemgmt/conf/powerwall/settings.ps1
|
||||||
@@ -92,7 +92,7 @@ $certName = "vcenter-cert"
|
|||||||
$certSuccess = $false
|
$certSuccess = $false
|
||||||
try {
|
try {
|
||||||
Write-Host "Requesting certificate via Posh-ACME..." -ForegroundColor Cyan
|
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
|
$certSuccess = $true
|
||||||
} catch {
|
} catch {
|
||||||
Write-Host "ACME certificate request failed: $($_.Exception.Message)" -ForegroundColor Yellow
|
Write-Host "ACME certificate request failed: $($_.Exception.Message)" -ForegroundColor Yellow
|
||||||
@@ -103,8 +103,9 @@ try {
|
|||||||
# Collect certificate paths dynamically
|
# Collect certificate paths dynamically
|
||||||
# ----------------------------
|
# ----------------------------
|
||||||
if ($certSuccess) {
|
if ($certSuccess) {
|
||||||
# Get the folder for this specific domain
|
# Get the most recent certificate order
|
||||||
$certFolder = (Get-PAOrder -Domain $VCENTERHOST).CertFolder
|
$paOrder = Get-PAOrder | Sort-Object Created -Descending | Select-Object -First 1
|
||||||
|
$certFolder = $paOrder.CertFolder
|
||||||
|
|
||||||
$certPath = Join-Path $certFolder "$certName\cert.pem"
|
$certPath = Join-Path $certFolder "$certName\cert.pem"
|
||||||
$keyPath = Join-Path $certFolder "$certName\privkey.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 ""
|
||||||
Write-Host "Script completed. Check `$global:helpme for any error details." -ForegroundColor Green
|
Write-Host "Script completed. Check `$global:helpme for any error details." -ForegroundColor Green
|
||||||
|
|||||||
Reference in New Issue
Block a user