我们使用blue-green部署理念来部署我们的应用程序,并在PS脚本中投入大量资金来创建和配置IIS网站。
最近,我们更新了脚本以配置IIS日志记录,以使用New-ItemProperty
包含自定义标头的值。但是,我们已经看到了这个命令似乎没有"提交" (因为想要更好的词),对IIS和配置的更改将无声地失败。
这是脚本的简化版本(包括我们因WebAdministration而必须采用的其他一些黑客)。
Import-Module WebAdministration
$websiteName = "Product 1.0 App"
$aTargetLocation = "C:\Apps\Product\1.0\App"
$aAppPool = "App"
$httpPort = 8870
New-Website -Name "$websiteName" -PhysicalPath $aTargetLocation -ApplicationPool $aAppPool
Start-Sleep -s 3
Write-Host "Ensure site is stopped and stays stopped until explicitly started"
Stop-Website -Name "$websiteName"
Start-Sleep -s 1
Set-ItemProperty "IIS:\Sites\$websiteName" serverAutoStart False
Write-Host "Remove default port 80 binding that was added by default..."
Get-WebBinding -Port 80 -Name "$websiteName" | Remove-WebBinding
Start-Sleep -s 1
Write-Host "New web binding $websiteName -> Http Port $httpPort"
New-WebBinding -Name "$websiteName" -Port $httpPort -IPAddress *
Start-Sleep -s 1
Write-Host "Ensuring we log the CorrelationId in IIS logfiles"
New-ItemProperty "IIS:\Sites\$websiteName" -Name logfile.customFields.collection -Value `
@{logFieldName='CorrelationId';sourceType='RequestHeader';sourceName='CorrelationId'}
Start-Sleep -s 1
因此对于某些应用程序来说,这是一种享受,而CorrelationId
标题的配置仍然存在。对于其他站点,它似乎一直无声地失败 - 没有错误,没有任何事件记录:配置只是没有"#34;提交"我们最终在部署后手动添加标题,这违背了自动化的目的!
在尝试调试此问题时,我能够重复进行多次尝试 - 但随后价值出现了"坚持"并且永远不会再失败:最令人沮丧的。
任何提示/解决方法?
顺便说一句,我厌倦了为了在部署期间编写网站脚本而使用powershell WebAdministration模块我必须做的黑客攻击。这是一个苦涩的清单: