Skip to content

Commit 892bcc2

Browse files
author
Xiaoyu Wang
committed
Add script
1 parent 3bbc3f9 commit 892bcc2

File tree

6 files changed

+180
-0
lines changed

6 files changed

+180
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SHIR/IntegrationRuntime*.msi

Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM mcr.microsoft.com/windows/servercore:ltsc2019
2+
3+
# Download the latest self-hosted integration runtime installer into the SHIR folder
4+
COPY SHIR C:/SHIR/
5+
6+
RUN ["powershell", "C:/SHIR/build.ps1"]
7+
8+
CMD ["powershell", "C:/SHIR/setup.ps1"]
9+
10+
ENV SHIR_WINDOWS_CONTAINER_ENV True
11+
12+
HEALTHCHECK --start-period=120s CMD ["powershell", "C:/SHIR/health-check.ps1"]

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Azure Data Factory Integration Runtime in Windows Container Sample
2+
=======
3+
This repo contains the sample for running the Azure Data Factory Integration Runtime in Windows Container
4+
5+
For more information about Azure Data Factory, see [https://docs.microsoft.com/en-us/azure/data-factory/concepts-integration-runtime](https://docs.microsoft.com/en-us/azure/data-factory/concepts-integration-runtime)
6+
17

28
# Contributing
39

SHIR/build.ps1

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
$DmgcmdPath = "C:\Program Files\Microsoft Integration Runtime\4.0\Shared\dmgcmd.exe"
2+
3+
function Write-Log($Message) {
4+
function TS { Get-Date -Format 'MM/dd/yyyy hh:mm:ss' }
5+
Write-Host "[$(TS)] $Message"
6+
}
7+
8+
function Install-SHIR() {
9+
Write-Log "Install the Self-hosted Integration Runtime in the Windows container"
10+
11+
$MsiFileName = (Get-ChildItem -Path C:\SHIR | Where-Object { $_.Name -match [regex] "IntegrationRuntime_.*.msi" })[0].Name
12+
Start-Process msiexec.exe -Wait -ArgumentList "/i C:\SHIR\$MsiFileName /qn"
13+
if (!$?) {
14+
Write-Log "SHIR MSI Install Failed"
15+
}
16+
17+
Write-Log "SHIR MSI Install Successfully"
18+
}
19+
20+
function SetupEnv() {
21+
Write-Log "Begin to Setup the SHIR Environment"
22+
Start-Process $DmgcmdPath -Wait -ArgumentList "-Stop -StopUpgradeService -TurnOffAutoUpdate"
23+
Write-Log "SHIR Environment Setup Successfully"
24+
}
25+
26+
Install-SHIR
27+
28+
exit 0

SHIR/health-check.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
$DmgcmdPath = "C:\Program Files\Microsoft Integration Runtime\4.0\Shared\dmgcmd.exe"
2+
3+
function Check-Node-Connection() {
4+
Start-Process $DmgcmdPath -Wait -ArgumentList "-cgc" -RedirectStandardOutput "C:\SHIR\status-check.txt"
5+
$ConnectionResult = Get-Content "C:\SHIR\status-check.txt"
6+
Remove-Item -Force "C:\SHIR\status-check.txt"
7+
8+
if ($ConnectionResult -like "Connected") {
9+
return $TRUE
10+
}
11+
else {
12+
exit 1
13+
}
14+
}
15+
16+
if (Check-Node-Connection) {
17+
exit 0
18+
}

SHIR/setup.ps1

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
$DmgcmdPath = "C:\Program Files\Microsoft Integration Runtime\4.0\Shared\dmgcmd.exe"
2+
3+
function Write-Log($Message) {
4+
function TS { Get-Date -Format 'MM/dd/yyyy hh:mm:ss' }
5+
Write-Host "[$(TS)] $Message"
6+
}
7+
8+
function Check-Is-Registered() {
9+
$result = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\DataTransfer\DataManagementGateway\ConfigurationManager' -Name HaveRun -ErrorAction SilentlyContinue
10+
if (($result -ne $null) -and ($result.HaveRun -eq 'Mdw')) {
11+
return $TRUE
12+
}
13+
return $FALSE
14+
}
15+
16+
function Check-Main-Process() {
17+
$ProcessResult = Get-WmiObject Win32_Process -Filter "name = 'diahost.exe'"
18+
19+
if ($ProcessResult) {
20+
return $TRUE
21+
}
22+
else {
23+
throw "Main Process not found"
24+
}
25+
}
26+
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+
}
38+
}
39+
40+
41+
function RegisterNewNode {
42+
Param(
43+
$AUTH_KEY,
44+
$NODE_NAME,
45+
$ENABLE_HA,
46+
$HA_PORT
47+
)
48+
49+
Write-Log "Start registering the new SHIR node"
50+
51+
if (!$NODE_NAME) {
52+
Start-Process $DmgcmdPath -Wait -ArgumentList "-RegisterNewNode", "$($AUTH_KEY)" -RedirectStandardOutput "C:\SHIR\register-out.txt" -RedirectStandardError "C:\SHIR\register-error.txt"
53+
} else {
54+
Start-Process $DmgcmdPath -Wait -ArgumentList "-RegisterNewNode", "$($AUTH_KEY)", "$($NODE_NAME)" -RedirectStandardOutput "C:\SHIR\register-out.txt" -RedirectStandardError "C:\SHIR\register-error.txt"
55+
}
56+
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+
$StdOutResult = Get-Content "C:\SHIR\register-out.txt"
64+
$StdErrResult = Get-Content "C:\SHIR\register-error.txt"
65+
66+
67+
if ($StdOutResult)
68+
{
69+
Write-Log "Registration output:"
70+
$StdOutResult | ForEach-Object { Write-Log $_ }
71+
}
72+
73+
if ($StdErrResult)
74+
{
75+
Write-Log "Registration errors:"
76+
$StdErrResult | ForEach-Object { Write-Log $_ }
77+
}
78+
}
79+
80+
# Register SHIR with key from Env Variable: AUTH_KEY
81+
if (Check-Is-Registered) {
82+
Write-Log "Restart the existing node"
83+
Start-Process $DmgcmdPath -Wait -ArgumentList "-Start"
84+
} 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)"
89+
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
91+
} else {
92+
Write-Log "Invalid AUTH_KEY Value"
93+
exit 1
94+
}
95+
96+
Write-Log "Waiting 30 seconds waiting for connecting"
97+
Start-Sleep -Seconds 30
98+
99+
try {
100+
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
105+
}
106+
}
107+
}
108+
finally {
109+
Write-Log "Stop the node connection"
110+
Start-Process $DmgcmdPath -Wait -ArgumentList "-Stop"
111+
Write-Log "Stop the node connection successfully"
112+
exit 0
113+
}
114+
115+
exit 1

0 commit comments

Comments
 (0)