diff --git a/SHIR/health-check.ps1 b/SHIR/health-check.ps1 index 6856efd..1c22856 100644 --- a/SHIR/health-check.ps1 +++ b/SHIR/health-check.ps1 @@ -1,9 +1,48 @@ $DmgcmdPath = "C:\Program Files\Microsoft Integration Runtime\5.0\Shared\dmgcmd.exe" +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." + } + + if ([string]::IsNullOrEmpty($outContent)) + { + return $outContent + } + + return $outContent.Trim() +} function Check-Node-Connection() { - Start-Process $DmgcmdPath -Wait -ArgumentList "-cgc" -RedirectStandardOutput "C:\SHIR\status-check.txt" - $ConnectionResult = Get-Content "C:\SHIR\status-check.txt" - Remove-Item -Force "C:\SHIR\status-check.txt" + + $ConnectionResult = Run-Process $DmgcmdPath "-cgc" if ($ConnectionResult -like "Connected") { return $TRUE diff --git a/SHIR/setup.ps1 b/SHIR/setup.ps1 index 3111577..ee3aa56 100644 --- a/SHIR/setup.ps1 +++ b/SHIR/setup.ps1 @@ -47,19 +47,17 @@ function RegisterNewNode { ) Write-Log "Start registering the new SHIR node" - + if ($ENABLE_HA -eq "true") { + Write-Log "Enable High Availability" + $PORT = if (!$HA_PORT) { "8060" } else { $HA_PORT } + Start-Process $DmgcmdPath -Wait -ArgumentList "-EnableRemoteAccessInContainer", "$($PORT)" -RedirectStandardOutput "C:\SHIR\register-out.txt" -RedirectStandardError "C:\SHIR\register-error.txt" + } if (!$NODE_NAME) { Start-Process $DmgcmdPath -Wait -ArgumentList "-RegisterNewNode", "$($AUTH_KEY)" -RedirectStandardOutput "C:\SHIR\register-out.txt" -RedirectStandardError "C:\SHIR\register-error.txt" } else { Start-Process $DmgcmdPath -Wait -ArgumentList "-RegisterNewNode", "$($AUTH_KEY)", "$($NODE_NAME)" -RedirectStandardOutput "C:\SHIR\register-out.txt" -RedirectStandardError "C:\SHIR\register-error.txt" } - if ($ENABLE_HA -eq "true") { - Write-Log "Enable High Availability" - $PORT = $HA_PORT -or "8060" - Start-Process $DmgcmdPath -Wait -ArgumentList "-EnableRemoteAccess", "$($PORT)" - } - $StdOutResult = Get-Content "C:\SHIR\register-out.txt" $StdErrResult = Get-Content "C:\SHIR\register-error.txt"