From 67e11b92c18c687826cea951f1cf10d9a6384cea Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Tue, 11 Aug 2020 16:48:36 +0200 Subject: [PATCH] updated # fault domains and added ps script for gw --- .../deploy.vmss.json | 2 +- .../gatewayInstall.ps1 | 180 ++++++++++++++++++ 2 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 infra/SelfHostedIntegrationRuntime/gatewayInstall.ps1 diff --git a/infra/SelfHostedIntegrationRuntime/deploy.vmss.json b/infra/SelfHostedIntegrationRuntime/deploy.vmss.json index 4298bd6..3bbf0a5 100644 --- a/infra/SelfHostedIntegrationRuntime/deploy.vmss.json +++ b/infra/SelfHostedIntegrationRuntime/deploy.vmss.json @@ -175,7 +175,7 @@ "automaticRepairsPolicy": {}, "doNotRunExtensionsOnOverprovisionedVMs": false, "overprovision": true, - "platformFaultDomainCount": 3, + "platformFaultDomainCount": 5, "proximityPlacementGroup": {}, "scaleInPolicy": { "rules": [ diff --git a/infra/SelfHostedIntegrationRuntime/gatewayInstall.ps1 b/infra/SelfHostedIntegrationRuntime/gatewayInstall.ps1 new file mode 100644 index 0000000..ecc76a3 --- /dev/null +++ b/infra/SelfHostedIntegrationRuntime/gatewayInstall.ps1 @@ -0,0 +1,180 @@ +param( + [string] + $gatewayKey +) + +# init log setting +$logLoc = "$env:SystemDrive\WindowsAzure\Logs\Plugins\Microsoft.Compute.CustomScriptExtension\" +if (! (Test-Path($logLoc))) +{ + New-Item -path $logLoc -type directory -Force +} +$logPath = "$logLoc\tracelog.log" +"Start to excute gatewayInstall.ps1. `n" | Out-File $logPath + +function Now-Value() +{ + return (Get-Date -Format "yyyy-MM-dd HH:mm:ss") +} + +function Throw-Error([string] $msg) +{ + try + { + throw $msg + } + catch + { + $stack = $_.ScriptStackTrace + Trace-Log "DMDTTP is failed: $msg`nStack:`n$stack" + } + + throw $msg +} + +function Trace-Log([string] $msg) +{ + $now = Now-Value + try + { + "${now} $msg`n" | Out-File $logPath -Append + } + catch + { + #ignore any exception during trace + } + +} + +function Run-Process([string] $process, [string] $arguments) +{ + Write-Verbose "Run-Process: $process $arguments" + + $errorFile = "$env:tmp\tmp$pid.err" + $outFile = "$env:tmp\tmp$pid.out" + "" | Out-File $outFile + "" | Out-File $errorFile + + $errVariable = "" + + if ([string]::IsNullOrEmpty($arguments)) + { + $proc = Start-Process -FilePath $process -Wait -Passthru -NoNewWindow ` + -RedirectStandardError $errorFile -RedirectStandardOutput $outFile -ErrorVariable errVariable + } + else + { + $proc = Start-Process -FilePath $process -ArgumentList $arguments -Wait -Passthru -NoNewWindow ` + -RedirectStandardError $errorFile -RedirectStandardOutput $outFile -ErrorVariable errVariable + } + + $errContent = [string] (Get-Content -Path $errorFile -Delimiter "!!!DoesNotExist!!!") + $outContent = [string] (Get-Content -Path $outFile -Delimiter "!!!DoesNotExist!!!") + + Remove-Item $errorFile + Remove-Item $outFile + + if($proc.ExitCode -ne 0 -or $errVariable -ne "") + { + Throw-Error "Failed to run process: exitCode=$($proc.ExitCode), errVariable=$errVariable, errContent=$errContent, outContent=$outContent." + } + + Trace-Log "Run-Process: ExitCode=$($proc.ExitCode), output=$outContent" + + if ([string]::IsNullOrEmpty($outContent)) + { + return $outContent + } + + return $outContent.Trim() +} + +function Download-Gateway([string] $url, [string] $gwPath) +{ + try + { + $ErrorActionPreference = "Stop"; + $client = New-Object System.Net.WebClient + $client.DownloadFile($url, $gwPath) + Trace-Log "Download gateway successfully. Gateway loc: $gwPath" + } + catch + { + Trace-Log "Fail to download gateway msi" + Trace-Log $_.Exception.ToString() + throw + } +} + +function Install-Gateway([string] $gwPath) +{ + if ([string]::IsNullOrEmpty($gwPath)) + { + Throw-Error "Gateway path is not specified" + } + + if (!(Test-Path -Path $gwPath)) + { + Throw-Error "Invalid gateway path: $gwPath" + } + + Trace-Log "Start Gateway installation" + Run-Process "msiexec.exe" "/i gateway.msi INSTALLTYPE=AzureTemplate /quiet /norestart" + + Start-Sleep -Seconds 30 + + Trace-Log "Installation of gateway is successful" +} + +function Get-RegistryProperty([string] $keyPath, [string] $property) +{ + Trace-Log "Get-RegistryProperty: Get $property from $keyPath" + if (! (Test-Path $keyPath)) + { + Trace-Log "Get-RegistryProperty: $keyPath does not exist" + } + + $keyReg = Get-Item $keyPath + if (! ($keyReg.Property -contains $property)) + { + Trace-Log "Get-RegistryProperty: $property does not exist" + return "" + } + + return $keyReg.GetValue($property) +} + +function Get-InstalledFilePath() +{ + $filePath = Get-RegistryProperty "hklm:\Software\Microsoft\DataTransfer\DataManagementGateway\ConfigurationManager" "DiacmdPath" + if ([string]::IsNullOrEmpty($filePath)) + { + Throw-Error "Get-InstalledFilePath: Cannot find installed File Path" + } + Trace-Log "Gateway installation file: $filePath" + + return $filePath +} + +function Register-Gateway([string] $instanceKey) +{ + Trace-Log "Register Agent" + $filePath = Get-InstalledFilePath + Run-Process $filePath "-era 8060" + Run-Process $filePath "-k $instanceKey" + Trace-Log "Agent registration is successful!" +} + + + +Trace-Log "Log file: $logLoc" +$uri = "https://go.microsoft.com/fwlink/?linkid=839822" +Trace-Log "Gateway download fw link: $uri" +$gwPath= "$PWD\gateway.msi" +Trace-Log "Gateway download location: $gwPath" + + +Download-Gateway $uri $gwPath +Install-Gateway $gwPath + +Register-Gateway $gatewayKey