Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

92 řádky
3.4KB

  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. [switch]$RunMigrations = $true
  19. )
  20. $ErrorActionPreference = 'Stop'
  21. Import-Module WebAdministration
  22. if(!(Get-Website -Name $SiteName -ErrorAction SilentlyContinue)){
  23. 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."
  24. }
  25. if(!(Test-Path ('IIS:\AppPools\' + $AppPool))){
  26. throw "App pool '$AppPool' does not exist yet. Create it once manually before running this deploy."
  27. }
  28. Write-Host "Stopping IIS site $SiteName and app pool $AppPool"
  29. try { Stop-Website -Name $SiteName } catch { }
  30. try { Stop-WebAppPool -Name $AppPool } catch { }
  31. if(Test-Path $RemoteDir){
  32. Write-Host "Wiping $RemoteDir"
  33. Remove-Item -Recurse -Force (Join-Path $RemoteDir '*') -ErrorAction SilentlyContinue
  34. } else {
  35. New-Item -ItemType Directory -Force -Path $RemoteDir | Out-Null
  36. }
  37. Write-Host "Extracting $ZipPath -> $RemoteDir"
  38. Expand-Archive -Path $ZipPath -DestinationPath $RemoteDir -Force
  39. Remove-Item $ZipPath -ErrorAction SilentlyContinue
  40. $publicDir = Join-Path $RemoteDir 'public'
  41. if(!(Test-Path $publicDir)){
  42. throw "No public\ folder in the extracted release - deploy aborted, site left stopped for inspection."
  43. }
  44. # Persistent data folder (DB + error log) - lives outside RemoteDir so it survives the wipe
  45. # above. Create it and grant the app pool identity modify rights.
  46. $dataDir = Split-Path $DbPath -Parent
  47. if(!(Test-Path $dataDir)){
  48. New-Item -ItemType Directory -Force -Path $dataDir | Out-Null
  49. }
  50. $logDir = Join-Path $dataDir 'logs'
  51. if(!(Test-Path $logDir)){
  52. New-Item -ItemType Directory -Force -Path $logDir | Out-Null
  53. }
  54. icacls $dataDir /grant ("IIS AppPool\" + $AppPool + ":(OI)(CI)(M)") /T | Out-Null
  55. Set-ItemProperty ('IIS:\Sites\' + $SiteName) -Name physicalPath -Value $publicDir
  56. Set-ItemProperty ('IIS:\Sites\' + $SiteName) -Name applicationPool -Value $AppPool
  57. # This server has the 64-bit Access Database Engine (ACE OLEDB) installed, unlike the local
  58. # dev machine, which needs the 32-bit one - so the app pool stays 64-bit here.
  59. Set-ItemProperty ('IIS:\AppPools\' + $AppPool) -Name enable32BitAppOnWin64 -Value $false
  60. if($RunMigrations){
  61. Write-Host 'Running pending migrations'
  62. Push-Location $RemoteDir
  63. try {
  64. & cscript.exe //nologo scripts\runMigrations.vbs up
  65. if($LASTEXITCODE -ne 0){ throw 'runMigrations.vbs up failed - see output above' }
  66. } finally {
  67. Pop-Location
  68. }
  69. }
  70. Write-Host "Starting IIS site $SiteName and app pool $AppPool"
  71. if((Get-WebAppPoolState -Name $AppPool).Value -eq 'Started'){
  72. Restart-WebAppPool -Name $AppPool
  73. } else {
  74. Start-WebAppPool -Name $AppPool
  75. }
  76. Start-Website $SiteName
  77. Write-Host 'Remote apply complete.'

Powered by TurnKey Linux.