From ee6c368e5e6460b3475e3cbcc1848722b6300e73 Mon Sep 17 00:00:00 2001 From: Raki Rahman <46581776+mdrakiburrahman@users.noreply.github.com> Date: Sat, 5 Jun 2021 17:53:44 -0400 Subject: [PATCH 1/2] Fixed HA onboarding issue --- Dockerfile | 2 +- SHIR/setup.ps1 | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index fcf0d18..dbbaaf9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,4 +9,4 @@ CMD ["powershell", "C:/SHIR/setup.ps1"] ENV SHIR_WINDOWS_CONTAINER_ENV True -HEALTHCHECK --start-period=120s CMD ["powershell", "C:/SHIR/health-check.ps1"] \ No newline at end of file +# HEALTHCHECK --start-period=120s CMD ["powershell", "C:/SHIR/health-check.ps1"] \ No newline at end of file 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" From 7866a33f710c55d43784bcffc181237df1e9cbdc Mon Sep 17 00:00:00 2001 From: Raki <46581776+mdrakiburrahman@users.noreply.github.com> Date: Sun, 6 Jun 2021 14:33:53 -0400 Subject: [PATCH 2/2] Decoupled healthcheck output Decoupled healthcheck file from setup.ps1 --- Dockerfile | 2 +- SHIR/health-check.ps1 | 45 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index dbbaaf9..fcf0d18 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,4 +9,4 @@ CMD ["powershell", "C:/SHIR/setup.ps1"] ENV SHIR_WINDOWS_CONTAINER_ENV True -# HEALTHCHECK --start-period=120s CMD ["powershell", "C:/SHIR/health-check.ps1"] \ No newline at end of file +HEALTHCHECK --start-period=120s CMD ["powershell", "C:/SHIR/health-check.ps1"] \ No newline at end of file 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