1
1
$DmgcmdPath = " C:\Program Files\Microsoft Integration Runtime\5.0\Shared\dmgcmd.exe"
2
2
3
3
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' }
5
5
Write-Host " [$ ( TS) ] $Message "
6
6
}
7
7
@@ -19,22 +19,9 @@ function Check-Main-Process() {
19
19
if ($ProcessResult ) {
20
20
return $TRUE
21
21
}
22
- else {
23
- throw " Main Process not found"
24
- }
25
- }
26
22
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
38
25
}
39
26
40
27
@@ -46,24 +33,28 @@ function RegisterNewNode {
46
33
$HA_PORT
47
34
)
48
35
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
+ }
50
48
51
49
if (! $NODE_NAME ) {
52
50
Start-Process $DmgcmdPath - Wait - ArgumentList " -RegisterNewNode" , " $ ( $AUTH_KEY ) " - RedirectStandardOutput " C:\SHIR\register-out.txt" - RedirectStandardError " C:\SHIR\register-error.txt"
53
51
} else {
54
52
Start-Process $DmgcmdPath - Wait - ArgumentList " -RegisterNewNode" , " $ ( $AUTH_KEY ) " , " $ ( $NODE_NAME ) " - RedirectStandardOutput " C:\SHIR\register-out.txt" - RedirectStandardError " C:\SHIR\register-error.txt"
55
53
}
56
54
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
-
63
55
$StdOutResult = Get-Content " C:\SHIR\register-out.txt"
64
56
$StdErrResult = Get-Content " C:\SHIR\register-error.txt"
65
57
66
-
67
58
if ($StdOutResult )
68
59
{
69
60
Write-Log " Registration output:"
@@ -80,29 +71,57 @@ function RegisterNewNode {
80
71
# Register SHIR with key from Env Variable: AUTH_KEY
81
72
if (Check- Is- Registered) {
82
73
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
+
83
86
Start-Process $DmgcmdPath - Wait - ArgumentList " -Start"
84
87
} 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
+
89
93
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
91
96
} else {
92
97
Write-Log " Invalid AUTH_KEY Value"
93
98
exit 1
94
99
}
95
100
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
98
103
99
104
try {
105
+ $COUNT = 0
106
+ $IS_REGISTERED = $FALSE
100
107
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
+ }
105
113
}
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
106
125
}
107
126
}
108
127
finally {
0 commit comments