forked from GuanceCloud/datakit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.ps1.template
420 lines (355 loc) · 11.6 KB
/
install.ps1.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
# DataKit install script for Windows
# Tue Aug 10 22:47:16 PDT 2021
# Author: tanb
# See https://stackoverflow.com/a/4647985/342348
function Write-COutput($ForegroundColor) {
# save the current color
$fc = $host.UI.RawUI.ForegroundColor
# set the new color
$host.UI.RawUI.ForegroundColor = $ForegroundColor
# output
if ($args) {
Write-Output $args
}
else {
$input | Write-Output
}
# restore the original color
$host.UI.RawUI.ForegroundColor = $fc
}
# https://gist.github.com/markembling/173887
# usage: remove-host $file $args[1]
function remove-host([string]$filename, [string]$hostname) {
$c = Get-Content $filename
$newLines = @()
foreach ($line in $c) {
$bits = [regex]::Split($line, "\t+")
if ($bits.count -eq 2) {
if ($bits[1] -ne $hostname) {
$newLines += $line
}
} else {
$newLines += $line
}
}
# Write file
Clear-Content $filename
foreach ($line in $newLines) {
$line | Out-File -encoding ASCII -append $filename
}
}
##########################
# Detect variables
##########################
$installer_base_url = "https://{{.InstallBaseURL}}"
$domain = @(
"static.guance.com"
"openway.guance.com"
"dflux-dial.guance.com"
"static.dataflux.cn"
"openway.dataflux.cn"
"dflux-dial.dataflux.cn"
"zhuyun-static-files-production.oss-cn-hangzhou.aliyuncs.com"
)
$x = [Environment]::GetEnvironmentVariable("DK_UPGRADE")
if ($x -ne $null) {
$upgrade = $x
Write-COutput green ("* set upgrade" )
}
$x = [Environment]::GetEnvironmentVariable("DK_DATAWAY")
if ($x -ne $null) {
$dataway = $x
Write-COutput green ("* set dataway to $dataway" )
}
$http_listen = "localhost"
$x = [Environment]::GetEnvironmentVariable("DK_HTTP_LISTEN")
if ($x -ne $null) {
$http_listen = $x
Write-COutput green "* set HTTP listen to $x"
}
$http_port = 9529
$x = [Environment]::GetEnvironmentVariable("DK_HTTP_PORT")
if ($x -ne $null) {
$http_port = $x
Write-COutput green "* set HTTP port to $x"
}
$namespace=""
$x = [Environment]::GetEnvironmentVariable("DK_NAMESPACE")
if ($x -ne $null) {
$namespace = $x
Write-COutput green "* set namespace to $x"
}
$cloud_provider=""
$x = [Environment]::GetEnvironmentVariable("DK_CLOUD_PROVIDER")
if ($x -ne $null) {
$cloud_provider = $x
Write-COutput green "* set cloud provider to $x"
}
$proxy=""
$x = [Environment]::GetEnvironmentVariable("HTTP_PROXY")
if ($x -ne $null) {
$proxy = $x
Write-COutput green "* set Proxy to $x"
}
$x = [Environment]::GetEnvironmentVariable("HTTPS_PROXY")
if ($x -ne $null) {
$proxy = $x
Write-COutput green "* set Proxy to $x"
}
# check nginx proxy
$proxy_type=""
$x = [Environment]::GetEnvironmentVariable("DK_PROXY_TYPE")
if ($x -ne $null) {
$proxy_type = $x
$proxy_type.ToLower()
Write-COutput green "* found Proxy Type: $proxy_type"
if ($proxy_type -eq "nginx") {
# env DK_NGINX_IP has highest priority on proxy level
$x = ""
$x = [Environment]::GetEnvironmentVariable("DK_NGINX_IP")
if ($x -ne $null -or $x -ne "") {
$proxy = $x
Write-COutput green "* got nginx Proxy $proxy"
# 更新 hosts
foreach ( $node in $domain )
{
remove-host $env:windir\System32\drivers\etc\hosts $node
Add-Content -Path $env:windir\System32\drivers\etc\hosts -Value "`n$proxy`t$node" -Force
}
$proxy=""
}
}
}
$env_hostname=""
$x = [Environment]::GetEnvironmentVariable("DK_HOSTNAME")
if ($x -ne $null) {
$env_hostname=$x
Write-COutput green "* set hostname to $x"
}
$enable_experimental="0"
$x = [Environment]::GetEnvironmentVariable("DK_ENABLE_EXPEIMENTAL")
if ($x -ne $null) {
$enable_experimental=$x
Write-COutput green "* set enable_experimental to $x"
}
$global_host_tags=""
$x = [Environment]::GetEnvironmentVariable("DK_GLOBAL_HOST_TAGS")
if ($x -ne $null) {
$global_host_tags = $x
Write-COutput green "* set global host tags $x"
}
$global_election_tags=""
$x = [Environment]::GetEnvironmentVariable("DK_GLOBAL_ELECTION_TAGS")
if ($x -ne $null) {
$global_election_tags = $x
Write-COutput green "* set global election tags $x"
}
$install_only="0"
$x = [Environment]::GetEnvironmentVariable("DK_INSTALL_ONLY")
if ($x -ne $null) {
$install_only = "1"
Write-COutput yellow "* set install only"
}
$dca_white_list=
$x = [Environment]::GetEnvironmentVariable("DK_DCA_WHITE_LIST")
if ($x -ne $null) {
$dca_white_list = $x
Write-COutput yellow "* set DCA white list $x"
}
$dca_listen=""
$x = [Environment]::GetEnvironmentVariable("DK_DCA_LISTEN")
if ($x -ne $null) {
$dca_listen = $x
Write-COutput yellow "* set DCA server listen address and port"
}
$dca_enable=
$x = [Environment]::GetEnvironmentVariable("DK_DCA_ENABLE")
if ($x -ne $null) {
$dca_enable = $x
Write-COutput yellow "* enable DCA server"
if ($dca_white_list -eq $null) {
Write-COutput red "DCA service is enabled, but white list is not set in DK_DCA_WHITE_LIST!"
Exit
}
}
$enable_pprof=
$x = [Environment]::GetEnvironmentVariable("DK_ENABLE_PPROF")
if ($x -ne $null) {
$enable_pprof = $x
Write-COutput yellow "* set pprof"
}
$pprof_listen=
$x = [Environment]::GetEnvironmentVariable("DK_PPROF_LISTEN")
if ($x -ne $null) {
$pprof_listen = $x
Write-COutput yellow "* set pprof listen address"
}
$git_url=""
$x = [Environment]::GetEnvironmentVariable("DK_GIT_URL")
if ($x -ne $null) {
$git_url = $x
Write-COutput yellow "* set git url"
}
$git_key_path=""
$x = [Environment]::GetEnvironmentVariable("DK_GIT_KEY_PATH")
if ($x -ne $null) {
$git_key_path = $x
Write-COutput yellow "* set git private key path"
}
$git_key_pw=""
$x = [Environment]::GetEnvironmentVariable("DK_GIT_KEY_PW")
if ($x -ne $null) {
$git_key_pw = $x
Write-COutput yellow "* set git private key password"
}
$git_branch=""
$x = [Environment]::GetEnvironmentVariable("DK_GIT_BRANCH")
if ($x -ne $null) {
$git_branch = $x
Write-COutput yellow "* set git branch"
}
$git_pull_interval=""
$x = [Environment]::GetEnvironmentVariable("DK_GIT_INTERVAL")
if ($x -ne $null) {
$git_pull_interval = $x
Write-COutput yellow "* set git interval"
}
$enable_election=""
$x = [Environment]::GetEnvironmentVariable("DK_ENABLE_ELECTION")
if ($x -ne $null) {
$enable_election = $x
Write-COutput yellow "* set enable election"
}
$disable_404page=""
$x = [Environment]::GetEnvironmentVariable("DK_DISABLE_404PAGE")
if ($x -ne $null) {
$disable_404page = $x
Write-COutput yellow "* set disable 404 page"
}
$rum_origin_ip_header=""
$x = [Environment]::GetEnvironmentVariable("DK_RUM_ORIGIN_IP_HEADER")
if ($x -ne $null) {
$rum_origin_ip_header = $x
Write-COutput yellow "* set rum origin IP header"
}
$log_level=""
$x = [Environment]::GetEnvironmentVariable("DK_LOG_LEVEL")
if ($x -ne $null) {
$log_level = $x
Write-COutput yellow "* set log level"
}
$log=""
$x = [Environment]::GetEnvironmentVariable("DK_LOG")
if ($x -ne $null) {
$log = $x
Write-COutput yellow "* set log"
}
$gin_Log=""
$x = [Environment]::GetEnvironmentVariable("DK_GIN_LOG")
if ($x -ne $null) {
$gin_Log = $x
Write-COutput yellow "* set gin log"
}
$ipdb_type=""
$x = [Environment]::GetEnvironmentVariable("DK_INSTALL_IPDB")
if ($x -ne $null) {
$ipdb_type = $x
Write-COutput yellow "* set ipdb type"
}
$sink_metric=""
$x = [Environment]::GetEnvironmentVariable("DK_SINK_M")
if ($x -ne $null) {
$sink_metric = $x
Write-COutput yellow "* set sink metric"
}
$sink_network=""
$x = [Environment]::GetEnvironmentVariable("DK_SINK_N")
if ($x -ne $null) {
$sink_network = $x
Write-COutput yellow "* set sink network"
}
$sink_keyevent=""
$x = [Environment]::GetEnvironmentVariable("DK_SINK_K")
if ($x -ne $null) {
$sink_keyevent = $x
Write-COutput yellow "* set sink keyevent"
}
$sink_object=""
$x = [Environment]::GetEnvironmentVariable("DK_SINK_O")
if ($x -ne $null) {
$sink_object = $x
Write-COutput yellow "* set sink object"
}
$sink_custom_object=""
$x = [Environment]::GetEnvironmentVariable("DK_SINK_CO")
if ($x -ne $null) {
$sink_custom_object = $x
Write-COutput yellow "* set sink custom object"
}
$sink_logging=""
$x = [Environment]::GetEnvironmentVariable("DK_SINK_L")
if ($x -ne $null) {
$sink_logging = $x
Write-COutput yellow "* set sink logging"
}
$sink_tracing=""
$x = [Environment]::GetEnvironmentVariable("DK_SINK_T")
if ($x -ne $null) {
$sink_tracing = $x
Write-COutput yellow "* set sink tracing"
}
$sink_rum=""
$x = [Environment]::GetEnvironmentVariable("DK_SINK_R")
if ($x -ne $null) {
$sink_rum = $x
Write-COutput yellow "* set sink rum"
}
$sink_security=""
$x = [Environment]::GetEnvironmentVariable("DK_SINK_S")
if ($x -ne $null) {
$sink_security = $x
Write-COutput yellow "* set sink security"
}
$sink_profile=""
$x = [Environment]::GetEnvironmentVariable("DK_SINK_P")
if ($x -ne $null) {
$sink_profile = $x
Write-COutput yellow "* set sink profile"
}
##########################
# Detect arch 32 or 64
##########################
$arch = "amd64"
if ([Environment]::Is64BitProcess -ne [Environment]::Is64BitOperatingSystem) {
$arch="386"
}
$installer_url = "$installer_base_url/installer-windows-$arch-{{.Version}}.exe"
$installer=".dk-installer.exe"
##########################
# try install...
##########################
Write-COutput green "* Downloading $installer_url..."
if (Test-Path $installer) {
Remove-Item $installer
}
Import-Module bitstransfer
$dl_installer_action = "start-bitstransfer -source $installer_url -destination $installer"
if ($proxy -ne "") {
$dl_installer_action = "start-bitstransfer -ProxyUsage Override -ProxyList $proxy -source $installer_url -destination $installer"
}
Invoke-Expression $dl_installer_action
if ($upgrade -ne $null) { # upgrade
$action = "$installer -upgrade --proxy=${proxy} --enable-experimental=${enable_experimental}"
} else { # install new datakit
$action = "$installer --dataway=$dataway --listen=$http_listen --port=${http_port} --proxy=${proxy} --namespace=${namespace} --env_hostname=${env_hostname} --cloud-provider=${cloud_provider} --global-host-tags='${global_host_tags}' --global-election-tags='${global_election_tags}' --dca-enable=$dca_enable --dca-listen=$dca_listen --dca-white-list=$dca_white_list --git-url='${git_url}' --git-key-path='${git_key_path}' --git-key-pw='${git_key_pw}' --git-branch='${git_branch}' --git-pull-interval='${git_pull_interval}' --install-only='${install_only}' --enable-election='${enable_election}' --rum-origin-ip-header='${rum_origin_ip_header}' --disable-404page='${disable_404page}' --log-level='${log_level}' --log='${log}' --gin-log='${gin_log}' --ipdb-type='${ipdb_type}' --enable-pprof='${enable_pprof}' --pprof-listen='${pprof_listen}' --sink-metric='${sink_metric}' --sink-network='${sink_network}' --sink-keyevent='${sink_keyevent}' --sink-object='${sink_object}' --sink-custom-object='${sink_custom_object}' --sink-logging='${sink_logging}' --sink-tracing='${sink_tracing}' --sink-rum='${sink_rum}' --sink-security='${sink_security}' --sink-profile='${sink_profile}'"
}
Write-COutput green "action: $action"
Invoke-Expression $action
# remove installer
Remove-Item -Force -ErrorAction SilentlyContinue $installer
Remove-Item -Force -ErrorAction SilentlyContinue .\installer.ps1
# clean envs
$optional_envs="DK_DATAWAY","DK_UPGRADE","HTTP_PROXY","HTTP_PROXY","DK_HTTP_PORT","DK_HOSTNAME","DK_HTTP_LISTEN","DK_INSTALL_ONLY","DK_DCA_ENABLE","DK_DCA_WHITE_LIST","DK_PROXY_TYPE","DK_NGINX_IP","DK_GIT_URL","DK_GIT_KEY_PATH","DK_GIT_KEY_PW","DK_GIT_BRANCH","DK_GIT_INTERVAL","DK_ENABLE_ELECTION","DK_DISABLE_404PAGE","DK_RUM_ORIGIN_IP_HEADER","DK_LOG_LEVEL","DK_LOG","DK_GIN_LOG","DK_INSTALL_IPDB","DK_ENABLE_PPROF","DK_PPROF_LISTEN","DK_SINK_M","DK_SINK_N","DK_SINK_K","DK_SINK_O","DK_SINK_CO","DK_SINK_L","DK_SINK_T","DK_SINK_R","DK_SINK_S"
foreach ($env in $optional_envs) {
Remove-Item -ErrorAction SilentlyContinue Env:$env
}