Преглед на файлове

Fix deploy: admin site/pool restart being silently skipped

Root cause: the final restart block called Get-WebAppPoolState first to
decide Restart- vs Start-WebAppPool. With \Continue = 'Stop',
any transient error from that check (most likely right after
Wait-AppPoolFullyStopped had to force-kill a lingering worker process,
leaving the pool's WAS state briefly inconsistent) threw an uncaught
error and aborted the rest of the script - silently skipping the admin
site/pool start even though the public site had already restarted
successfully by that point.

Fix: Start-WebAppPool/Start-Website are no-ops if already started, so
drop the state check entirely. Both public and admin site/pool starts
now go through Start-SiteAndPool, which wraps each call independently
in try/catch so one failing doesn't prevent the other from starting,
and reports (rather than swallows or aborts on) any failure.
master
Daniel Covington преди 10 часа
родител
ревизия
9a899d3682
променени са 1 файла, в които са добавени 27 реда и са изтрити 14 реда
  1. +27
    -14
      scripts/deploy-iis-remote-apply.ps1

+ 27
- 14
scripts/deploy-iis-remote-apply.ps1 Целия файл

@@ -157,23 +157,36 @@ if($RunMigrations){
}
}

Write-Host "Starting IIS site $SiteName and app pool $AppPool"
if((Get-WebAppPoolState -Name $AppPool).Value -eq 'Started'){
Restart-WebAppPool -Name $AppPool
} else {
Start-WebAppPool -Name $AppPool
}
Start-Website $SiteName
# Start-WebAppPool/Start-Website are no-ops (no error) if already started, so there's no
# need to check current state first - and checking first (via Get-WebAppPoolState) is what
# was silently killing this whole block: with $ErrorActionPreference = 'Stop', a transient
# error from that check (e.g. right after Wait-AppPoolFullyStopped had to force-kill a
# lingering worker process) aborted the script before the admin site/pool were ever started.
# Each start below is independently wrapped so a problem with one site doesn't prevent the
# other from starting, and every failure is reported instead of aborting silently.
function Start-SiteAndPool {
param([string]$PoolName, [string]$WebsiteName)

if(![string]::IsNullOrWhiteSpace($PoolName)){
try {
Start-WebAppPool -Name $PoolName -ErrorAction Stop
Write-Host "Started app pool $PoolName"
} catch {
Write-Host "WARNING: failed to start app pool $PoolName : $($_.Exception.Message)"
}
}

if(![string]::IsNullOrWhiteSpace($AdminSiteName)){
if(![string]::IsNullOrWhiteSpace($AdminAppPool)){
if((Get-WebAppPoolState -Name $AdminAppPool).Value -eq 'Started'){
Restart-WebAppPool -Name $AdminAppPool
} else {
Start-WebAppPool -Name $AdminAppPool
if(![string]::IsNullOrWhiteSpace($WebsiteName)){
try {
Start-Website -Name $WebsiteName -ErrorAction Stop
Write-Host "Started site $WebsiteName"
} catch {
Write-Host "WARNING: failed to start site $WebsiteName : $($_.Exception.Message)"
}
}
Start-Website $AdminSiteName
}

Start-SiteAndPool -PoolName $AppPool -WebsiteName $SiteName
Start-SiteAndPool -PoolName $AdminAppPool -WebsiteName $AdminSiteName

Write-Host 'Remote apply complete.'

Loading…
Отказ
Запис

Powered by TurnKey Linux.