100 lines
2.9 KiB
PowerShell
100 lines
2.9 KiB
PowerShell
#-------------------------------------------------------------------
|
|
# Egalware 2021.05.25
|
|
#
|
|
# .\AppDeploy.ps1 -AppPool MP.STATS -SourceDir c:\Steamware\installers\MP\STATS -ZipFile MP.STATS.zip -DestDir c:\inetpub\wwwroot\MP\STATS2
|
|
#
|
|
# 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
|
|
)
|
|
|
|
# conf x logging
|
|
$logDir = "c:\Steamware\tmp"
|
|
$logFile = "$logDir\Script.log"
|
|
$logMirror = "$logDir\Mirror.log"
|
|
$utilDir = "c:\Steamware\tmp"
|
|
$installDir = "c:\Steamware\installers\"
|
|
|
|
# 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 $logFile -Append
|
|
}
|
|
# esegue e registra log
|
|
function ExecuteLog($txt2log)
|
|
{
|
|
Write-Output "-------------------------------------------------------------------------------------------------------------------------------------------------" | Out-File -FilePath "$logFile" -Append
|
|
Write-Output "$(Get-TimeStamp) $txt2log" | Out-File -FilePath "$logFile" -Append
|
|
Invoke-Expression "$txt2log 2>&1 | Out-File -FilePath $logFile -Append"
|
|
if( $LASTEXITCODE -ne 0)
|
|
{
|
|
Write-Host "Error during cmmand: $txt2log" -ForegroundColor Red ;
|
|
Write-Host "Exit...." -ForegroundColor Red ;
|
|
Set-Location $PSScriptRoot
|
|
exit
|
|
}
|
|
}
|
|
|
|
# fix cartelle...
|
|
If (!(test-path $logFile))
|
|
{
|
|
New-Item -ItemType Directory -Force -Path $logDir
|
|
New-Item -ItemType File -Force -Path $logFile
|
|
New-Item -ItemType File -Force -Path $logMirror
|
|
}
|
|
|
|
Write-Output "-------------------------------- START script --------------------------------" | Out-File $logFile
|
|
$StopWatch = New-Object System.Diagnostics.Stopwatch
|
|
$StopWatch.Start()
|
|
|
|
|
|
# step 1 : stop del pool applicazioni IIS
|
|
$currState = Get-WebAppPoolState -Name $AppPool
|
|
if($currState.value -eq "Started")
|
|
{
|
|
Write-Host "Stop AppPool"
|
|
ExecuteLog "Stop-WebAppPool -Name '$AppPool'"
|
|
}
|
|
|
|
# step 2 : cambio dir + unzip
|
|
Write-Host "Unzip"
|
|
cd $utilDir
|
|
ExecuteLog "7z x ""$SourceDir\$ZipFile"" "
|
|
|
|
# step 3 : replica applicazione
|
|
Write-Host "START copy step"
|
|
ExecuteLog "robocopy '$utilDir\publish\net8.0\' '$DestDir' /MIR /Z /LOG:'$logMirror'"
|
|
Write-Host "END copy step"
|
|
|
|
# step 4 : riavvio pool
|
|
Write-Host "Start AppPool"
|
|
ExecuteLog "Start-WebAppPool -Name '$AppPool'"
|
|
|
|
# step 5 : fix dir originale
|
|
cd $installDir |