From 9a899d3682076bb593483e7b4d92e299fc83c2ab Mon Sep 17 00:00:00 2001 From: Daniel Covington Date: Mon, 24 Aug 2026 12:46:53 -0400 Subject: [PATCH] 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. --- scripts/deploy-iis-remote-apply.ps1 | 41 +++++++++++++++++++---------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/scripts/deploy-iis-remote-apply.ps1 b/scripts/deploy-iis-remote-apply.ps1 index 28eef32..74d9c6f 100644 --- a/scripts/deploy-iis-remote-apply.ps1 +++ b/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.'