|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+#!/bin/bash
|
|
|
2
|
+set -ex
|
|
|
3
|
+# for TZ awareness
|
|
|
4
|
+if [ "$TZ" != "" ]; then
|
|
|
5
|
+ ln -sf /usr/share/zoneinfo/$TZ /etc/localtime
|
|
|
6
|
+ echo $TZ >/etc/timezone
|
|
|
7
|
+fi
|
|
|
8
|
+
|
|
|
9
|
+TAOS_ROOT_PASSWORD=${TAOS_ROOT_PASSWORD:-taosdata}
|
|
|
10
|
+export TAOS_KEEPER_TDENGINE_PASSWORD=${TAOS_ROOT_PASSWORD}
|
|
|
11
|
+
|
|
|
12
|
+INITDB_DIR=/docker-entrypoint-initdb.d/
|
|
|
13
|
+
|
|
|
14
|
+# option to disable taosadapter, default is no
|
|
|
15
|
+DISABLE_ADAPTER=${TAOS_DISABLE_ADAPTER:-0}
|
|
|
16
|
+unset TAOS_DISABLE_ADAPTER
|
|
|
17
|
+
|
|
|
18
|
+DISABLE_KEEPER=${TAOS_DISABLE_KEEPER:-0}
|
|
|
19
|
+unset TAOS_DISABLE_KEEPER
|
|
|
20
|
+
|
|
|
21
|
+DISABLE_EXPLORER=${TAOS_DISABLE_EXPLORER:-0}
|
|
|
22
|
+unset TAOS_DISABLE_EXPLORER
|
|
|
23
|
+
|
|
|
24
|
+# Get DATA_DIR from taosd -C
|
|
|
25
|
+DATA_DIR=$(taosd -C|grep -E 'dataDir\s+(\S+)' -o |head -n1|sed 's/dataDir *//')
|
|
|
26
|
+DATA_DIR=${DATA_DIR:-/var/lib/taos}
|
|
|
27
|
+
|
|
|
28
|
+# Get FQDN from taosd -C
|
|
|
29
|
+FQDN=$(taosd -C|grep -E 'fqdn\s+(\S+)' -o |head -n1|sed 's/fqdn *//')
|
|
|
30
|
+# ensure the fqdn is resolved as localhost
|
|
|
31
|
+grep "$FQDN" /etc/hosts >/dev/null || echo "127.0.0.1 $FQDN" >>/etc/hosts
|
|
|
32
|
+
|
|
|
33
|
+# Get first ep from taosd -C
|
|
|
34
|
+FIRSET_EP=$(taosd -C|grep -E 'firstEp\s+(\S+)' -o |head -n1|sed 's/firstEp *//')
|
|
|
35
|
+# parse first ep host and port
|
|
|
36
|
+FIRST_EP_HOST=${FIRSET_EP%:*}
|
|
|
37
|
+FIRST_EP_PORT=${FIRSET_EP#*:}
|
|
|
38
|
+
|
|
|
39
|
+# in case of custom server port
|
|
|
40
|
+SERVER_PORT=$(taosd -C|grep -E 'serverPort\s+(\S+)' -o |head -n1|sed 's/serverPort *//')
|
|
|
41
|
+SERVER_PORT=${SERVER_PORT:-6030}
|
|
|
42
|
+
|
|
|
43
|
+set +e
|
|
|
44
|
+ulimit -c unlimited
|
|
|
45
|
+# set core files pattern, maybe failed
|
|
|
46
|
+sysctl -w kernel.core_pattern=/corefile/core-$FQDN-%e-%p >/dev/null >&1
|
|
|
47
|
+set -e
|
|
|
48
|
+
|
|
|
49
|
+if [ $# -gt 0 ]; then
|
|
|
50
|
+ exec $@
|
|
|
51
|
+ exit 0
|
|
|
52
|
+fi
|
|
|
53
|
+
|
|
|
54
|
+NEEDS_INITDB=0
|
|
|
55
|
+
|
|
|
56
|
+# if dnode has been created or has mnode ep set or the host is first ep or not for cluster, just start.
|
|
|
57
|
+if [ -f "$DATA_DIR/dnode/dnode.json" ] ||
|
|
|
58
|
+ [ -f "$DATA_DIR/dnode/mnodeEpSet.json" ] ||
|
|
|
59
|
+ [ "$FQDN" = "$FIRST_EP_HOST" ]; then
|
|
|
60
|
+ echo "start taosd with mnode ep set"
|
|
|
61
|
+ taosd &
|
|
|
62
|
+ while true; do
|
|
|
63
|
+ es=$(taos -h $FIRST_EP_HOST -P $FIRST_EP_PORT --check | grep "^[0-9]*:")
|
|
|
64
|
+ echo ${es}
|
|
|
65
|
+ if [ "${es%%:*}" -eq 2 ]; then
|
|
|
66
|
+
|
|
|
67
|
+ # Initialization scripts should only work in first node.
|
|
|
68
|
+ if [ "$FQDN" = "$FIRST_EP_HOST" ]; then
|
|
|
69
|
+ if [ ! -f "${DATA_DIR}/.docker-entrypoint-root-password-changed" ]; then
|
|
|
70
|
+ if [ "$TAOS_ROOT_PASSWORD" != "taosdata" ]; then
|
|
|
71
|
+ # change default root password
|
|
|
72
|
+ taos -s "ALTER USER root PASS '$TAOS_ROOT_PASSWORD'"
|
|
|
73
|
+ touch "${DATA_DIR}/.docker-entrypoint-root-password-changed"
|
|
|
74
|
+ fi
|
|
|
75
|
+ fi
|
|
|
76
|
+ # Initialization scripts should only work in first node.
|
|
|
77
|
+ if [ ! -f "${DATA_DIR}/.docker-entrypoint-inited" ]; then
|
|
|
78
|
+ NEEDS_INITDB=1
|
|
|
79
|
+ fi
|
|
|
80
|
+ fi
|
|
|
81
|
+
|
|
|
82
|
+ break
|
|
|
83
|
+ fi
|
|
|
84
|
+ sleep 1s
|
|
|
85
|
+ done
|
|
|
86
|
+# others will first wait the first ep ready.
|
|
|
87
|
+else
|
|
|
88
|
+ if [ "$TAOS_FIRST_EP" = "" ]; then
|
|
|
89
|
+ echo "run TDengine with single node."
|
|
|
90
|
+ taosd &
|
|
|
91
|
+ fi
|
|
|
92
|
+ while true; do
|
|
|
93
|
+ es=$(taos -h $FIRST_EP_HOST -P $FIRST_EP_PORT --check | grep "^[0-9]*:")
|
|
|
94
|
+ echo ${es}
|
|
|
95
|
+ if [ "${es%%:*}" -eq 2 ]; then
|
|
|
96
|
+ echo "execute create dnode"
|
|
|
97
|
+ sh -c "taos -p'$TAOS_ROOT_PASSWORD' -h $FIRST_EP_HOST -P $FIRST_EP_PORT -s 'create dnode \"$FQDN:$SERVER_PORT\";'"
|
|
|
98
|
+ break
|
|
|
99
|
+ fi
|
|
|
100
|
+ sleep 1s
|
|
|
101
|
+ done
|
|
|
102
|
+ if ps aux | grep -v grep | grep taosd > dev/null; then
|
|
|
103
|
+ echo "TDengine is running"
|
|
|
104
|
+ else
|
|
|
105
|
+ taosd &
|
|
|
106
|
+ fi
|
|
|
107
|
+fi
|
|
|
108
|
+
|
|
|
109
|
+if [ "$DISABLE_ADAPTER" = "0" ]; then
|
|
|
110
|
+ which taosadapter >/dev/null && taosadapter -c /etc/taos/taosadapter.toml &
|
|
|
111
|
+ # wait for 6041 port ready
|
|
|
112
|
+ for _ in $(seq 1 20); do
|
|
|
113
|
+ nc -z localhost 6041 && break
|
|
|
114
|
+ sleep 0.5
|
|
|
115
|
+ done
|
|
|
116
|
+fi
|
|
|
117
|
+
|
|
|
118
|
+if [ "$DISABLE_KEEPER" = "0" ]; then
|
|
|
119
|
+ sleep 3
|
|
|
120
|
+ which taoskeeper >/dev/null && taoskeeper &
|
|
|
121
|
+ # wait for 6043 port ready
|
|
|
122
|
+ for _ in $(seq 1 20); do
|
|
|
123
|
+ nc -z localhost 6043 && break
|
|
|
124
|
+ sleep 0.5
|
|
|
125
|
+ done
|
|
|
126
|
+fi
|
|
|
127
|
+
|
|
|
128
|
+if [ "$DISABLE_EXPLORER" = "0" ]; then
|
|
|
129
|
+ which taos-explorer >/dev/null && taos-explorer &
|
|
|
130
|
+ # wait for 6060 port ready
|
|
|
131
|
+ for _ in $(seq 1 20); do
|
|
|
132
|
+ nc -z localhost 6060 && break
|
|
|
133
|
+ sleep 0.5
|
|
|
134
|
+ done
|
|
|
135
|
+fi
|
|
|
136
|
+
|
|
|
137
|
+if [ "$NEEDS_INITDB" = "1" ]; then
|
|
|
138
|
+ # check if initdb.d exists
|
|
|
139
|
+ if [ -d "${INITDB_DIR}" ]; then
|
|
|
140
|
+ # execute initdb scripts in sql
|
|
|
141
|
+ for FILE in "$INITDB_DIR"*.sql; do
|
|
|
142
|
+ echo "Initialize db with file $FILE"
|
|
|
143
|
+ MAX_RETRIES=5
|
|
|
144
|
+ RETRY_COUNT=0
|
|
|
145
|
+ SUCCESS=0
|
|
|
146
|
+ while [ $RETRY_COUNT -lt $MAX_RETRIES ] && [ "$SUCCESS" = "0" ]; do
|
|
|
147
|
+ set -x
|
|
|
148
|
+ OUTPUT=$(sh -c "taos -f $FILE -p'$TAOS_ROOT_PASSWORD'")
|
|
|
149
|
+ set +x
|
|
|
150
|
+ echo $OUTPUT
|
|
|
151
|
+ if [[ "$OUTPUT" =~ "DB error" ]]; then
|
|
|
152
|
+ echo "Retrying in 2 seconds..."
|
|
|
153
|
+ sleep 2
|
|
|
154
|
+ else
|
|
|
155
|
+ SUCCESS=1
|
|
|
156
|
+ fi
|
|
|
157
|
+ done
|
|
|
158
|
+ done
|
|
|
159
|
+ fi
|
|
|
160
|
+
|
|
|
161
|
+ touch "${DATA_DIR}/.docker-entrypoint-inited"
|
|
|
162
|
+fi
|
|
|
163
|
+
|
|
|
164
|
+while true; do sleep 1000; done
|