From 53d7de1ec8e892f2651fc2d77c51deaa0fb5cb46 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 25 May 2021 12:22:05 +0200 Subject: [PATCH] bozza script installazione --- AppDeploy.ps1 | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 AppDeploy.ps1 diff --git a/AppDeploy.ps1 b/AppDeploy.ps1 new file mode 100644 index 00000000..b7b16fde --- /dev/null +++ b/AppDeploy.ps1 @@ -0,0 +1,79 @@ +#------------------------------------------------------------------- +# Egalware 2021.05.25 +# +# AppDeploy -AppPool MP.STATS -SourceDir c:\Steamware\installers\MP.STATS -ZipFile MP.STATS.zip -DestDir c:\inetpub\wwwroot\MP\STATS +# +# Powershell script per deploy applicazione Blazor / dotnet core +# +# requisito: modulo powershell x 7zip: +# Set-ExecutionPolicy Bypass -Scope CurrentUser -Force +# Install-Module -Name 7Zip4Powershell +#------------------------------------------------------------------- + +# step 0: lettura variabili +param ( + [Parameter(Mandatory=$true)] + [ValidateNotNull()] + [string]$AppPool = "MP.STATS", + + [Parameter(Mandatory=$true)] + [ValidateNotNull()] + [string]$SourceDir, + + [Parameter(Mandatory=$true)] + [ValidateNotNull()] + [string]$ZipFile, + + [Parameter(Mandatory=$true)] + [ValidateNotNull()] + [string]$DestDir +) + +# recupera timestamp x logging +function Get-TimeStamp +{ + return "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date) +} +# registra log! +function DoLog($txt2log) +{ + Write-Output "$(Get-TimeStamp) $txt2log" | Out-File $filelog -Append +} +# esegue e registra log +function ExecuteLog($txt2log) +{ + Write-Output "-------------------------------------------------------------------------------------------------------------------------------------------------" | Out-File -FilePath "$filelog" -Append + Write-Output "$(Get-TimeStamp) $txt2log" | Out-File -FilePath "$filelog" -Append + Invoke-Expression "$txt2log 2>&1 | Out-File -FilePath $filelog -Append" + if( $LASTEXITCODE -ne 0) + { + Write-Host "Error during cmmand: $txt2log" -ForegroundColor Red ; + Write-Host "Exit...." -ForegroundColor Red ; + Set-Location $PSScriptRoot + exit + } +} +# conf x logging +$filelog = "c:\Steamware\tmp\Script.log" +$utilDir = "c:\Steamware\tmp\" + +Write-Output "-------------------------------- START script --------------------------------" | Out-File $filelog +$StopWatch = New-Object System.Diagnostics.Stopwatch +$StopWatch.Start() + + +# step 1 : stop del pool applicazioni IIS +Write-Host "Stop AppPool" +ExecuteLog "Stop-WebAppPool -Name '$AppPool'" + +# step 2 : unzip +ExecuteLog "Expand-7Zip -ArchiveFileName '$SourceDir\$ZipFile' -TargetPath '$utilDir'" + +# step 3 : replica applicazione +Write-Host "START copy step" +ExecuteLog "robocopy '$utilDir\publish\net5.0\' '$DestDir' /MIR /Z /LOG:C:\tmp\ViewMirror.log /XF logs/*.txt logs/*.log" +Write-Host "END copy step" + +# step 4 : riavvio pool +Write-Host "Start AppPool" +ExecuteLog "Start-WebAppPool -Name '$AppPool'"