我有点疏忽地发现章鱼虽然非常棒,但在升级网站之前并没有采取任何可爱或聪明的措施。
在我们的解决方案中,我们有两个 Web 应用程序(一个网站和一个单独的 API Web 应用程序),它们依赖于相同的数据库,因此在一个应用程序进行升级时,另一个应用程序仍然在线,可能会在升级数据库时仍在提供网络或 API 请求。
这不太好!
更好的方法是让Octopus关闭Web应用程序,等待它们关闭后再执行升级操作,完成后将应用程序池重新启动。
如何实现呢?
我有点疏忽地发现章鱼虽然非常棒,但在升级网站之前并没有采取任何可爱或聪明的措施。
在我们的解决方案中,我们有两个 Web 应用程序(一个网站和一个单独的 API Web 应用程序),它们依赖于相同的数据库,因此在一个应用程序进行升级时,另一个应用程序仍然在线,可能会在升级数据库时仍在提供网络或 API 请求。
这不太好!
更好的方法是让Octopus关闭Web应用程序,等待它们关闭后再执行升级操作,完成后将应用程序池重新启动。
如何实现呢?
自拍回答!
让Octopus-deploy在您的部署中多加一些小心,很容易,您只需要在部署例程中添加几个额外的Execute-Powershell步骤。
添加一个新的第一步来停止应用程序池:
# Settings
#---------------
$appPoolName = "PushpayApi" # Or we could set this from an Octopus environment setting.
# Installation
#---------------
Import-Module WebAdministration
# see http://technet.microsoft.com/en-us/library/ee790588.aspx
cd IIS:\
if ( (Get-WebAppPoolState -Name $appPoolName).Value -eq "Stopped" )
{
Write-Host "AppPool already stopped: " + $appPoolName
}
Write-Host "Shutting down the AppPool: " + $appPoolName
Write-Host (Get-WebAppPoolState $appPoolName).Value
# Signal to stop.
Stop-WebAppPool -Name $appPoolName
do
{
Write-Host (Get-WebAppPoolState $appPoolName).Value
Start-Sleep -Seconds 1
}
until ( (Get-WebAppPoolState -Name $appPoolName).Value -eq "Stopped" )
# Wait for the apppool to shut down.
然后在最后添加另一步来重新启动应用程序池:
# Settings
#---------------
$appPoolName = "PushpayApi"
# Installation
#---------------
Import-Module WebAdministration
# see http://technet.microsoft.com/en-us/library/ee790588.aspx
cd IIS:\
if ( (Get-WebAppPoolState -Name $appPoolName).Value -eq "Started" )
{
Write-Host "AppPool already started: " + $appPoolName
}
Write-Host "Starting the AppPool: " + $appPoolName
Write-Host (Get-WebAppPoolState $appPoolName).Value
# To restart the app pool ...
Start-WebAppPool -Name $appPoolName
Get-WebAppPoolState -Name $appPoolName
write-host "Website: $WebSiteName"
# Take Website Offline
$path = "$WebDeployPath";
$path
$verb = "-verb:sync";
$verb
# Take root Website offline
$src = "-source:contentPath=```"$WebSiteName/_app_offline.htm```"";
$src
$dest = "-dest:contentPath=```"$WebSiteName/app_offline.htm```"";
$dest
Invoke-Expression "&'$path' $verb $src $dest";
# Take Sub Website 1 offline
$src = "-source:contentPath=```"$WebSiteName/WebApp1/_app_offline.htm```"";
$dest = "-dest:contentPath=```"$WebSiteName/WebApp1/app_offline.htm```"";
Invoke-Expression "&'$path' $verb $src $dest";
$WebSiteName通常是“默认网站”。此外,请注意,`不是单引号,而实际上是反引号字符(通常与键盘上的tilda一起找到)。
现在,如果章鱼将您的网站部署到新位置,则您的网站将自动恢复在线状态。 如果您不想要这样,可以先部署已经放置了app_offline文件的新网站。 然后,您可以使用以下脚本删除它。
write-host $WebSiteName
# & "c:\Program Files (x86)\IIS\Microsoft Web Deploy V2\msdeploy.exe" -verb:delete -dest:contentPath="$WebSiteName/app_offline.htm"
# those arn't QUOTES!!!!, they are the back accent thing.
write-host "Website: $WebSiteName"
# Put Web app Online.
$path = "$WebDeployPath";
$path
$verb = "-verb:delete";
$verb
$dest = "-dest:contentPath=```"$WebSiteName/app_offline.htm```"";
$dest
Invoke-Expression "&'$path' $verb $dest";
# Put Sub Website Online
$dest = "-dest:contentPath=```"$WebSiteName/WebApp1/app_offline.htm```"";
Invoke-Expression "&'$path' $verb $dest";
app_offline.htm
。重新映射应用程序以使用该应用程序池进行部署,关闭实际的应用程序池,最后执行反向步骤。 - Alex M