Skip to content

Commit 7eb5657

Browse files
author
Xiaoyu Wang
committed
Fix script
1 parent 6e5d971 commit 7eb5657

File tree

1 file changed

+54
-35
lines changed

1 file changed

+54
-35
lines changed

SHIR/setup.ps1

Lines changed: 54 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
$DmgcmdPath = "C:\Program Files\Microsoft Integration Runtime\5.0\Shared\dmgcmd.exe"
22

33
function Write-Log($Message) {
4-
function TS { Get-Date -Format 'MM/dd/yyyy hh:mm:ss' }
4+
function TS { Get-Date -Format 'MM/dd/yyyy HH:mm:ss' }
55
Write-Host "[$(TS)] $Message"
66
}
77

@@ -19,22 +19,9 @@ function Check-Main-Process() {
1919
if ($ProcessResult) {
2020
return $TRUE
2121
}
22-
else {
23-
throw "Main Process not found"
24-
}
25-
}
2622

27-
function Check-Node-Connection() {
28-
Start-Process $DmgcmdPath -Wait -ArgumentList "-cgc" -RedirectStandardOutput "C:\SHIR\status-check.txt"
29-
$ConnectionResult = Get-Content "C:\SHIR\status-check.txt"
30-
Remove-Item -Force "C:\SHIR\status-check.txt"
31-
32-
if ($ConnectionResult -like "Connected") {
33-
return $TRUE
34-
}
35-
else {
36-
throw "Node is offline"
37-
}
23+
Write-Log "diahost.exe is not running"
24+
return $FALSE
3825
}
3926

4027

@@ -46,24 +33,28 @@ function RegisterNewNode {
4633
$HA_PORT
4734
)
4835

49-
Write-Log "Start registering the new SHIR node"
36+
Write-Log "Start registering a new SHIR node"
37+
38+
if ($ENABLE_HA -eq "true") {
39+
Write-Log "Enable High Availability"
40+
$PORT = $HA_PORT
41+
if (!$HA_PORT) {
42+
$PORT = "8060"
43+
}
44+
Write-Log "Remote Access Port: $($PORT)"
45+
Start-Process $DmgcmdPath -Wait -ArgumentList "-EnableRemoteAccessInContainer", "$($PORT)" -RedirectStandardOutput "C:\SHIR\register-out.txt" -RedirectStandardError "C:\SHIR\register-error.txt"
46+
Start-Sleep -Seconds 15
47+
}
5048

5149
if (!$NODE_NAME) {
5250
Start-Process $DmgcmdPath -Wait -ArgumentList "-RegisterNewNode", "$($AUTH_KEY)" -RedirectStandardOutput "C:\SHIR\register-out.txt" -RedirectStandardError "C:\SHIR\register-error.txt"
5351
} else {
5452
Start-Process $DmgcmdPath -Wait -ArgumentList "-RegisterNewNode", "$($AUTH_KEY)", "$($NODE_NAME)" -RedirectStandardOutput "C:\SHIR\register-out.txt" -RedirectStandardError "C:\SHIR\register-error.txt"
5553
}
5654

57-
if ($ENABLE_HA -eq "true") {
58-
Write-Log "Enable High Availability"
59-
$PORT = $HA_PORT -or "8060"
60-
Start-Process $DmgcmdPath -Wait -ArgumentList "-EnableRemoteAccess", "$($PORT)"
61-
}
62-
6355
$StdOutResult = Get-Content "C:\SHIR\register-out.txt"
6456
$StdErrResult = Get-Content "C:\SHIR\register-error.txt"
6557

66-
6758
if ($StdOutResult)
6859
{
6960
Write-Log "Registration output:"
@@ -80,29 +71,57 @@ function RegisterNewNode {
8071
# Register SHIR with key from Env Variable: AUTH_KEY
8172
if (Check-Is-Registered) {
8273
Write-Log "Restart the existing node"
74+
75+
if ($ENABLE_HA -eq "true") {
76+
Write-Log "Enable High Availability"
77+
$PORT = $HA_PORT
78+
if (!$HA_PORT) {
79+
$PORT = "8060"
80+
}
81+
Write-Log "Remote Access Port: $($PORT)"
82+
Start-Process $DmgcmdPath -Wait -ArgumentList "-EnableRemoteAccessInContainer", "$($PORT)"
83+
Start-Sleep -Seconds 15
84+
}
85+
8386
Start-Process $DmgcmdPath -Wait -ArgumentList "-Start"
8487
} elseif (Test-Path Env:AUTH_KEY) {
85-
Write-Log "Registering SHIR with the node key: $((Get-Item Env:AUTH_KEY).Value)"
86-
Write-Log "Registering SHIR with the node name: $((Get-Item Env:NODE_NAME).Value)"
87-
Write-Log "Registering SHIR with the enable high availability flag: $((Get-Item Env:ENABLE_HA).Value)"
88-
Write-Log "Registering SHIR with the tcp port: $((Get-Item Env:HA_PORT).Value)"
88+
Write-Log "Registering SHIR node with the node key: $($Env:AUTH_KEY)"
89+
Write-Log "Registering SHIR node with the node name: $($Env:NODE_NAME)"
90+
Write-Log "Registering SHIR node with the enable high availability flag: $($Env:ENABLE_HA)"
91+
Write-Log "Registering SHIR node with the tcp port: $($Env:HA_PORT)"
92+
8993
Start-Process $DmgcmdPath -Wait -ArgumentList "-Start"
90-
RegisterNewNode (Get-Item Env:AUTH_KEY).Value (Get-Item Env:NODE_NAME).Value (Get-Item Env:ENABLE_HA).Value (Get-Item Env:HA_PORT).Value
94+
95+
RegisterNewNode $Env:AUTH_KEY $Env:NODE_NAME $Env:ENABLE_HA $Env:HA_PORT
9196
} else {
9297
Write-Log "Invalid AUTH_KEY Value"
9398
exit 1
9499
}
95100

96-
Write-Log "Waiting 30 seconds waiting for connecting"
97-
Start-Sleep -Seconds 30
101+
Write-Log "Waiting 60 seconds for connecting"
102+
Start-Sleep -Seconds 60
98103

99104
try {
105+
$COUNT = 0
106+
$IS_REGISTERED = $FALSE
100107
while ($TRUE) {
101-
if ((Check-Main-Process) -and (Check-Node-Connection)) {
102-
Write-Log "Node Health Check Pass"
103-
Start-Sleep -Seconds 60
104-
continue
108+
if(!$IS_REGISTERED) {
109+
if (Check-Is-Registered) {
110+
$IS_REGISTERED = $TRUE
111+
Write-Log "Self-hosted Integration Runtime is connected to the cloud service"
112+
}
105113
}
114+
115+
if (Check-Main-Process) {
116+
$COUNT = 0
117+
} else {
118+
$COUNT += 1
119+
if ($COUNT -gt 5) {
120+
throw "Diahost.exe is not running"
121+
}
122+
}
123+
124+
Start-Sleep -Seconds 60
106125
}
107126
}
108127
finally {

0 commit comments

Comments
 (0)