The admin site's physical path lives inside RemoteDir (RemoteDir\public-admin). On a redeploy it was still running while RemoteDir was wiped, so IIS held its files open and Remove-Item failed with Access is denied. Now both the public and admin site/app pool are stopped up front, before the wipe.master
| @@ -36,6 +36,17 @@ Write-Host "Stopping IIS site $SiteName and app pool $AppPool" | |||||
| try { Stop-Website -Name $SiteName } catch { } | try { Stop-Website -Name $SiteName } catch { } | ||||
| try { Stop-WebAppPool -Name $AppPool } catch { } | try { Stop-WebAppPool -Name $AppPool } catch { } | ||||
| # The admin site's physical path may already point inside RemoteDir (e.g. RemoteDir\public-admin) | |||||
| # from a previous deploy - if it's left running, IIS holds those files open and the wipe below | |||||
| # fails with "Access is denied". Stop it up front, alongside the public site, not after. | |||||
| if(![string]::IsNullOrWhiteSpace($AdminSiteName) -and (Get-Website -Name $AdminSiteName -ErrorAction SilentlyContinue)){ | |||||
| Write-Host "Stopping IIS admin site $AdminSiteName" | |||||
| try { Stop-Website -Name $AdminSiteName } catch { } | |||||
| if(![string]::IsNullOrWhiteSpace($AdminAppPool)){ | |||||
| try { Stop-WebAppPool -Name $AdminAppPool } catch { } | |||||
| } | |||||
| } | |||||
| if(Test-Path $RemoteDir){ | if(Test-Path $RemoteDir){ | ||||
| Write-Host "Wiping $RemoteDir" | Write-Host "Wiping $RemoteDir" | ||||
| Remove-Item -Recurse -Force (Join-Path $RemoteDir '*') -ErrorAction SilentlyContinue | Remove-Item -Recurse -Force (Join-Path $RemoteDir '*') -ErrorAction SilentlyContinue | ||||
| @@ -78,9 +89,7 @@ if(![string]::IsNullOrWhiteSpace($AdminSiteName) -and (Test-Path $adminPublicDir | |||||
| throw "IIS admin site '$AdminSiteName' does not exist yet. Create the site and app pool once manually before running this deploy." | throw "IIS admin site '$AdminSiteName' does not exist yet. Create the site and app pool once manually before running this deploy." | ||||
| } | } | ||||
| Write-Host "Configuring admin site $AdminSiteName" | Write-Host "Configuring admin site $AdminSiteName" | ||||
| Stop-Website -Name $AdminSiteName -ErrorAction SilentlyContinue | |||||
| if(![string]::IsNullOrWhiteSpace($AdminAppPool)){ | if(![string]::IsNullOrWhiteSpace($AdminAppPool)){ | ||||
| Stop-WebAppPool -Name $AdminAppPool -ErrorAction SilentlyContinue | |||||
| Set-ItemProperty ('IIS:\Sites\' + $AdminSiteName) -Name applicationPool -Value $AdminAppPool | Set-ItemProperty ('IIS:\Sites\' + $AdminSiteName) -Name applicationPool -Value $AdminAppPool | ||||
| Set-ItemProperty ('IIS:\AppPools\' + $AdminAppPool) -Name enable32BitAppOnWin64 -Value $false | Set-ItemProperty ('IIS:\AppPools\' + $AdminAppPool) -Name enable32BitAppOnWin64 -Value $false | ||||
| icacls $dataDir /grant ("IIS AppPool\" + $AdminAppPool + ":(OI)(CI)(M)") /T | Out-Null | icacls $dataDir /grant ("IIS AppPool\" + $AdminAppPool + ":(OI)(CI)(M)") /T | Out-Null | ||||
Powered by TurnKey Linux.