Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

122 rindas
4.8KB

  1. <#
  2. Runs ON the IIS server (invoked over SSH by scripts\deploy-iis.ps1). Not meant to be run
  3. by hand except for troubleshooting a stuck deploy.
  4. - Stops the site/app pool
  5. - Wipes RemoteDir and re-extracts the release zip into it (safe: the DB and error log
  6. live outside RemoteDir, at DbPath/ErrorLogDir, so a full wipe never touches them)
  7. - Points IIS at RemoteDir\public
  8. - Ensures the app pool identity has modify rights on the persistent data folder
  9. - Runs pending migrations (32-bit cscript - ACE OLEDB is x86-only)
  10. - Restarts the site/app pool
  11. #>
  12. param(
  13. [Parameter(Mandatory = $true)][string]$ZipPath,
  14. [Parameter(Mandatory = $true)][string]$RemoteDir,
  15. [Parameter(Mandatory = $true)][string]$SiteName,
  16. [Parameter(Mandatory = $true)][string]$AppPool,
  17. [Parameter(Mandatory = $true)][string]$DbPath,
  18. [string]$AdminSiteName = '',
  19. [string]$AdminAppPool = '',
  20. [switch]$RunMigrations = $true
  21. )
  22. $ErrorActionPreference = 'Stop'
  23. Import-Module WebAdministration
  24. if(!(Get-Website -Name $SiteName -ErrorAction SilentlyContinue)){
  25. throw "IIS site '$SiteName' does not exist yet. Create the site and app pool once manually (or via a one-time setup script) before running this deploy."
  26. }
  27. if(!(Test-Path ('IIS:\AppPools\' + $AppPool))){
  28. throw "App pool '$AppPool' does not exist yet. Create it once manually before running this deploy."
  29. }
  30. Write-Host "Stopping IIS site $SiteName and app pool $AppPool"
  31. try { Stop-Website -Name $SiteName } catch { }
  32. try { Stop-WebAppPool -Name $AppPool } catch { }
  33. if(Test-Path $RemoteDir){
  34. Write-Host "Wiping $RemoteDir"
  35. Remove-Item -Recurse -Force (Join-Path $RemoteDir '*') -ErrorAction SilentlyContinue
  36. } else {
  37. New-Item -ItemType Directory -Force -Path $RemoteDir | Out-Null
  38. }
  39. Write-Host "Extracting $ZipPath -> $RemoteDir"
  40. Expand-Archive -Path $ZipPath -DestinationPath $RemoteDir -Force
  41. Remove-Item $ZipPath -ErrorAction SilentlyContinue
  42. $publicDir = Join-Path $RemoteDir 'public'
  43. if(!(Test-Path $publicDir)){
  44. throw "No public\ folder in the extracted release - deploy aborted, site left stopped for inspection."
  45. }
  46. # Persistent data folder (DB + error log) - lives outside RemoteDir so it survives the wipe
  47. # above. Create it and grant the app pool identity modify rights.
  48. $dataDir = Split-Path $DbPath -Parent
  49. if(!(Test-Path $dataDir)){
  50. New-Item -ItemType Directory -Force -Path $dataDir | Out-Null
  51. }
  52. $logDir = Join-Path $dataDir 'logs'
  53. if(!(Test-Path $logDir)){
  54. New-Item -ItemType Directory -Force -Path $logDir | Out-Null
  55. }
  56. icacls $dataDir /grant ("IIS AppPool\" + $AppPool + ":(OI)(CI)(M)") /T | Out-Null
  57. Set-ItemProperty ('IIS:\Sites\' + $SiteName) -Name physicalPath -Value $publicDir
  58. Set-ItemProperty ('IIS:\Sites\' + $SiteName) -Name applicationPool -Value $AppPool
  59. # This server has the 64-bit Access Database Engine (ACE OLEDB) installed, unlike the local
  60. # dev machine, which needs the 32-bit one - so the app pool stays 64-bit here.
  61. Set-ItemProperty ('IIS:\AppPools\' + $AppPool) -Name enable32BitAppOnWin64 -Value $false
  62. # --- Admin site ---
  63. $adminPublicDir = Join-Path $RemoteDir 'public-admin'
  64. if(![string]::IsNullOrWhiteSpace($AdminSiteName) -and (Test-Path $adminPublicDir)){
  65. if(!(Get-Website -Name $AdminSiteName -ErrorAction SilentlyContinue)){
  66. throw "IIS admin site '$AdminSiteName' does not exist yet. Create the site and app pool once manually before running this deploy."
  67. }
  68. Write-Host "Configuring admin site $AdminSiteName"
  69. Stop-Website -Name $AdminSiteName -ErrorAction SilentlyContinue
  70. if(![string]::IsNullOrWhiteSpace($AdminAppPool)){
  71. Stop-WebAppPool -Name $AdminAppPool -ErrorAction SilentlyContinue
  72. Set-ItemProperty ('IIS:\Sites\' + $AdminSiteName) -Name applicationPool -Value $AdminAppPool
  73. Set-ItemProperty ('IIS:\AppPools\' + $AdminAppPool) -Name enable32BitAppOnWin64 -Value $false
  74. icacls $dataDir /grant ("IIS AppPool\" + $AdminAppPool + ":(OI)(CI)(M)") /T | Out-Null
  75. }
  76. Set-ItemProperty ('IIS:\Sites\' + $AdminSiteName) -Name physicalPath -Value $adminPublicDir
  77. }
  78. if($RunMigrations){
  79. Write-Host 'Running pending migrations'
  80. Push-Location $RemoteDir
  81. try {
  82. & cscript.exe //nologo scripts\runMigrations.vbs up
  83. if($LASTEXITCODE -ne 0){ throw 'runMigrations.vbs up failed - see output above' }
  84. } finally {
  85. Pop-Location
  86. }
  87. }
  88. Write-Host "Starting IIS site $SiteName and app pool $AppPool"
  89. if((Get-WebAppPoolState -Name $AppPool).Value -eq 'Started'){
  90. Restart-WebAppPool -Name $AppPool
  91. } else {
  92. Start-WebAppPool -Name $AppPool
  93. }
  94. Start-Website $SiteName
  95. if(![string]::IsNullOrWhiteSpace($AdminSiteName)){
  96. if(![string]::IsNullOrWhiteSpace($AdminAppPool)){
  97. if((Get-WebAppPoolState -Name $AdminAppPool).Value -eq 'Started'){
  98. Restart-WebAppPool -Name $AdminAppPool
  99. } else {
  100. Start-WebAppPool -Name $AdminAppPool
  101. }
  102. }
  103. Start-Website $AdminSiteName
  104. }
  105. Write-Host 'Remote apply complete.'

Powered by TurnKey Linux.