forked from GuanceCloud/datakit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh.template
executable file
·462 lines (380 loc) · 9.3 KB
/
install.sh.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
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
# DataKit install script for UNIX-like OS
# Wed Aug 11 11:35:28 CST 2021
# Author: [email protected]
# https://stackoverflow.com/questions/19339248/append-line-to-etc-hosts-file-with-shell-script/37824076
# usage: updateHosts ip domain1 domain2 domain3 ...
function updateHosts() {
for n in $@
do
if [ "$n" != "$1" ]; then
# echo $n
ip_address=$1
host_name=$n
# find existing instances in the host file and save the line numbers
matches_in_hosts="$(grep -n $host_name /etc/hosts | cut -f1 -d:)"
host_entry="${ip_address} ${host_name}"
if [ ! -z "$matches_in_hosts" ]
then
# iterate over the line numbers on which matches were found
while read -r line_number; do
# replace the text of each line with the desired host entry
if [[ "$OSTYPE" == "darwin"* ]]; then
sudo_cmd sed -i '' "${line_number}s/.*/${host_entry} /" /etc/hosts
else
sudo_cmd sed -i "${line_number}s/.*/${host_entry} /" /etc/hosts
fi
done <<< "$matches_in_hosts"
else
echo "$host_entry" | sudo_cmd tee -a /etc/hosts > /dev/null
fi
fi
done
}
set -e
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"
)
# detect root user
if [ "$(echo "$UID")" = "0" ]; then
sudo_cmd=''
else
sudo_cmd='sudo'
fi
##################
# colors
##################
RED="\033[31m"
CLR="\033[0m"
BLU="\033[34m"
##################
# Set Variables
##################
# Detect OS/Arch
arch=
case $(uname -m) in
"x86_64")
arch="amd64"
;;
"i386" | "i686")
arch="386"
;;
"aarch64")
arch="arm64"
;;
"arm" | "armv7l")
arch="arm"
;;
"arm64")
arch="arm64"
;;
*)
# shellcheck disable=SC2059
printf "${RED}[E] Unsupport arch $(uname -m) ${CLR}\n"
exit 1
;;
esac
os="linux"
if [[ "$OSTYPE" == "darwin"* ]]; then
if [[ $arch != "amd64" ]] && [[ $arch != "arm64" ]]; then # Darwin only support amd64 and arm64
# shellcheck disable=SC2059
printf "${RED}[E] Darwin only support amd64/arm64.${CLR}\n"
exit 1;
fi
os="darwin"
# NOTE: under darwin, for arm64 and amd64, both use amd64
arch="amd64"
fi
# Select installer
installer_base_url="https://{{.InstallBaseURL}}"
installer_file="installer-${os}-${arch}-{{.Version}}"
# shellcheck disable=SC2059
printf "${BLU} Detect installer ${installer_file}${CLR}\n"
installer_url="${installer_base_url}/${installer_file}"
installer=/tmp/dk-installer
dataway=
if [ -n "$DK_DATAWAY" ]; then
dataway=$DK_DATAWAY
fi
upgrade=
if [ -n "$DK_UPGRADE" ]; then
upgrade=$DK_UPGRADE
fi
def_inputs=
if [ -n "$DK_DEF_INPUTS" ]; then
# shellcheck disable=SC2034
def_inputs=$DK_DEF_INPUTS
fi
global_host_tags=
if [ -n "$DK_GLOBAL_HOST_TAGS" ]; then
global_host_tags=$DK_GLOBAL_HOST_TAGS
fi
global_election_tags=
if [ -n "$DK_GLOBAL_ELECTION_TAGS" ]; then
global_election_tags=$DK_GLOBAL_ELECTION_TAGS
fi
cloud_provider=
if [ -n "$DK_CLOUD_PROVIDER" ]; then
cloud_provider=$DK_CLOUD_PROVIDER
fi
namespace=
if [ -n "$DK_NAMESPACE" ]; then
namespace=$DK_NAMESPACE
fi
http_listen="localhost"
if [ -n "$DK_HTTP_LISTEN" ]; then
http_listen=$DK_HTTP_LISTEN
fi
http_port=9529
if [ -n "$DK_HTTP_PORT" ]; then
http_port=$DK_HTTP_PORT
fi
install_only=0
if [ -n "$DK_INSTALL_ONLY" ]; then
install_only=1
fi
dca_white_list=""
if [ -n "$DK_DCA_WHITE_LIST" ]; then
dca_white_list=$DK_DCA_WHITE_LIST
fi
dca_listen=""
if [ -n "$DK_DCA_LISTEN" ]; then
dca_listen=$DK_DCA_LISTEN
fi
dca_enable=""
if [ -n "$DK_DCA_ENABLE" ]; then
dca_enable=$DK_DCA_ENABLE
if [ -z "$dca_white_list" ]; then
printf "${RED}[E] DCA service is enabled, but white list is not set in DK_DCA_WHITE_LIST!${CLR}\n"
exit 1;
fi
fi
enable_pprof=""
if [ -n "$DK_ENABLE_PPROF" ]; then
enable_pprof=$DK_ENABLE_PPROF
fi
pprof_listen=""
if [ -n "$DK_PPROF_LISTEN" ]; then
pprof_listen=$DK_PPROF_LISTEN
fi
ipdb_type=""
if [ -n "$DK_INSTALL_IPDB" ]; then
ipdb_type=$DK_INSTALL_IPDB
fi
install_externals=""
if [ -n "$DK_INSTALL_EXTERNALS" ]; then
install_externals=$DK_INSTALL_EXTERNALS
fi
if [ -n "$HTTP_PROXY" ]; then
proxy=$HTTP_PROXY
fi
if [ -n "$HTTPS_PROXY" ]; then
proxy=$HTTPS_PROXY
fi
# check nginx proxy
proxy_type=""
if [ -n "$DK_PROXY_TYPE" ]; then
proxy_type=$DK_PROXY_TYPE
proxy_type=$(echo $proxy_type | tr '[:upper:]' '[:lower:]') # to lowercase
printf "${BLU}\n* found Proxy Type: $proxy_type${CLR}\n"
if [ "$proxy_type" == "nginx" ]; then
# env DK_NGINX_IP has highest priority on proxy level
if [ -n "$DK_NGINX_IP" ]; then
proxy=$DK_NGINX_IP
if [ "$proxy" != "" ]; then
printf "${BLU}\n* got nginx Proxy: $proxy${CLR}\n"
for i in ${domain[@]}; do
updateHosts "$proxy" "$i"
done
fi
proxy=""
fi
fi
fi
enable_experimental=0
if [ -n "$DK_ENABLE_EXPEIMENTAL" ]; then
enable_experimental=$DK_ENABLE_EXPEIMENTAL
fi
env_hostname=
if [ -n "$DK_HOSTNAME" ]; then
env_hostname=$DK_HOSTNAME
fi
limit_cpumax=30
if [ -n "$DK_LIMIT_CPUMAX" ]; then
limit_cpumax=$DK_LIMIT_CPUMAX
fi
limit_cpumin=5
if [ -n "$DK_LIMIT_CPUMIN" ]; then
limit_cpumin=$DK_LIMIT_CPUMIN
fi
limit_memmax=4096
if [ -n "$DK_LIMIT_MEMMAX" ]; then
limit_memmax=$DK_LIMIT_MEMMAX
fi
cgroup_disabled=0
if [ -n "$DK_CGROUP_DISABLED" ]; then
cgroup_disabled=1
fi
install_log=/var/log/datakit/install.log
if [ -n "$DK_INSTALL_LOG" ]; then
install_log=$DK_INSTALL_LOG
fi
git_url=""
if [ -n "$DK_GIT_URL" ]; then
git_url=$DK_GIT_URL
fi
git_key_path=""
if [ -n "$DK_GIT_KEY_PATH" ]; then
git_key_path=$DK_GIT_KEY_PATH
fi
git_key_pw=""
if [ -n "$DK_GIT_KEY_PW" ]; then
git_key_pw=$DK_GIT_KEY_PW
fi
git_branch=""
if [ -n "$DK_GIT_BRANCH" ]; then
git_branch=$DK_GIT_BRANCH
fi
git_pull_interval=""
if [ -n "$DK_GIT_INTERVAL" ]; then
git_pull_interval=$DK_GIT_INTERVAL
fi
enable_election=""
if [ -n "$DK_ENABLE_ELECTION" ]; then
enable_election=$DK_ENABLE_ELECTION
fi
rum_origin_ip_header=""
if [ -n "$DK_RUM_ORIGIN_IP_HEADER" ]; then
rum_origin_ip_header=$DK_RUM_ORIGIN_IP_HEADER
fi
disable_404page=""
if [ -n "$DK_DISABLE_404PAGE" ]; then
disable_404page=$DK_DISABLE_404PAGE
fi
log_level=""
if [ -n "$DK_LOG_LEVEL" ]; then
log_level=$DK_LOG_LEVEL
fi
log=""
if [ -n "$DK_LOG" ]; then
log=$DK_LOG
fi
gin_log=""
if [ -n "$DK_GIN_LOG" ]; then
gin_log=$DK_GIN_LOG
fi
sink_metric=""
if [ -n "$DK_SINK_M" ]; then
sink_metric=$DK_SINK_M
fi
sink_network=""
if [ -n "$DK_SINK_N" ]; then
sink_network=$DK_SINK_N
fi
sink_keyevent=""
if [ -n "$DK_SINK_K" ]; then
sink_keyevent=$DK_SINK_K
fi
sink_object=""
if [ -n "$DK_SINK_O" ]; then
sink_object=$DK_SINK_O
fi
sink_custom_object=""
if [ -n "$DK_SINK_CO" ]; then
sink_custom_object=$DK_SINK_CO
fi
sink_logging=""
if [ -n "$DK_SINK_L" ]; then
sink_logging=$DK_SINK_L
fi
sink_tracing=""
if [ -n "$DK_SINK_T" ]; then
sink_tracing=$DK_SINK_T
fi
sink_rum=""
if [ -n "$DK_SINK_R" ]; then
sink_rum=$DK_SINK_R
fi
sink_security=""
if [ -n "$DK_SINK_S" ]; then
sink_security=$DK_SINK_S
fi
sink_profile=""
if [ -n "$DK_SINK_P" ]; then
sink_profile=$DK_SINK_P
fi
##################
# Try install...
##################
# shellcheck disable=SC2059
printf "${BLU}\n* Downloading installer ${installer}\n${CLR}"
rm -rf $installer
if [ "$proxy" ]; then # add proxy for curl
# shellcheck disable=SC2086
curl -x "$proxy" --fail --progress-bar $installer_url > $installer
else
# shellcheck disable=SC2086
curl --fail --progress-bar $installer_url > $installer
fi
# Set executable
chmod +x $installer
if [ "$upgrade" ]; then
# shellcheck disable=SC2059
printf "${BLU}\n* Upgrading DataKit...${CLR}\n"
$sudo_cmd $installer \
--upgrade --proxy="${proxy}" --enable-experimental=${enable_experimental} | $sudo_cmd tee ${install_log}
else
printf "${BLU}\n* Installing DataKit...${CLR}\n"
$sudo_cmd $installer \
--install-only="$install_only" \
--dataway="${dataway}" \
--global-host-tags="${global_host_tags}" \
--global-election-tags="${global_election_tags}" \
--cloud-provider="${cloud_provider}" \
--namespace="${namespace}" \
--listen="${http_listen}" \
--port="${http_port}" \
--proxy="${proxy}" \
--env_hostname="${env_hostname}" \
--dca-enable="${dca_enable}" \
--dca-listen="${dca_listen}" \
--dca-white-list="${dca_white_list}" \
--enable-pprof="${enable_pprof}" \
--pprof-listen="${pprof_listen}" \
--install-externals="${install_externals}" \
--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}" \
--limit-cpumax="${limit_cpumax}" \
--limit-cpumin="${limit_cpumin}" \
--limit-mem="${limit_memmax}" \
--cgroup-disabled="${cgroup_disabled}" \
--enable-election="${enable_election}" \
--rum-origin-ip-header="${rum_origin_ip_header}" \
--disable-404page="${disable_404page}" \
--log-level="${log_level}" \
--log="${log}" \
--ipdb-type="${ipdb_type}" \
--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}" \
--ipdb-type="${ipdb_type}" \
--gin-log="${gin_log}" | $sudo_cmd tee ${install_log}
fi
rm -rf $installer
# install completion
$sudo_cmd datakit tool --setup-completer-script