Переглянути джерело

fix: 覆盖 entrypoint.sh 使 taosadapter 读取配置文件

上游镜像的 entrypoint.sh 启动 taosadapter 时缺少 -c 参数,
导致 /etc/taos/taosadapter.toml 配置未生效。

- 新增 deploy/config/entrypoint.sh,在启动 taosadapter 时添加
  -c /etc/taos/taosadapter.toml 参数
- 精简 taosadapter.toml,禁用 keeper 上传和未使用的插件
- 更新 start-tdengine-operator.sh,挂载修改后的 entrypoint.sh
mqy20260511
humanleft 2 тижднів тому
джерело
коміт
bfd6fef24c

+ 164
- 0
deploy/config/entrypoint.sh Переглянути файл

@@ -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

+ 10
- 66
deploy/config/taosadapter.toml Переглянути файл

@@ -1,96 +1,40 @@
1
-# taosAdapter configuration file
2
-# Deployed as independent container for Node.js service REST API access
1
+# taosAdapter configuration (runs inside tdengine-operator container)
2
+# Mounted to /etc/taos/taosadapter.toml
3 3
 
4
-debug = true
5
-taosConfigDir = ""
4
+debug = false
6 5
 port = 6041
7 6
 logLevel = "info"
8 7
 
9 8
 [cors]
10 9
 allowAllOrigins = true
11 10
 
12
-[ssl]
13
-enable = false
14
-certFile = ""
15
-keyFile = ""
16
-
17 11
 [log]
18 12
 rotationCount = 30
19 13
 rotationTime = "24h"
20 14
 rotationSize = "1GB"
21
-enableRecordHttpSql = false
22
-sqlRotationCount = 2
23
-sqlRotationTime =  "24h"
24
-sqlRotationSize = "1GB"
25 15
 
26
-[monitor]
27
-collectDuration = "3s"
28
-incgroup = false
29
-pauseQueryMemoryThreshold = 70
30
-pauseAllMemoryThreshold = 80
31
-identity = ""
32
-writeToTD = false
33
-user = "root"
34
-password = "taosdata"
35
-writeInterval = "30s"
16
+# Disable keeper upload (keeper is not running)
17
+[uploadKeeper]
18
+enable = false
36 19
 
20
+# Disable unused plugins
37 21
 [opentsdb]
38
-enable = true
22
+enable = false
39 23
 
40 24
 [influxdb]
41
-enable = true
25
+enable = false
42 26
 
43 27
 [statsd]
44 28
 enable = false
45
-port = 6044
46
-db = "statsd"
47
-user = "root"
48
-password = "taosdata"
49
-worker = 10
50
-gatherInterval = "5s"
51
-protocol = "udp"
52
-maxTCPConnections = 250
53
-tcpKeepAlive = false
54
-allowPendingMessages = 50000
55
-deleteCounters = true
56
-deleteGauges = true
57
-deleteSets = true
58
-deleteTimings = true
59 29
 
60 30
 [collectd]
61 31
 enable = false
62
-port = 6045
63
-db = "collectd"
64
-user = "root"
65
-password = "taosdata"
66
-worker = 10
67 32
 
68 33
 [opentsdb_telnet]
69 34
 enable = false
70
-maxTCPConnections = 250
71
-tcpKeepAlive = false
72
-dbs = ["opentsdb_telnet", "collectd", "icinga2", "tcollector"]
73
-ports = [6046, 6047, 6048, 6049]
74
-user = "root"
75
-password = "taosdata"
76
-batchSize = 1
77
-flushInterval = "0s"
78 35
 
79 36
 [node_exporter]
80 37
 enable = false
81
-db = "node_exporter"
82
-user = "root"
83
-password = "taosdata"
84
-urls = ["http://localhost:9100"]
85
-responseTimeout = "5s"
86
-httpUsername = ""
87
-httpPassword = ""
88
-httpBearerTokenString = ""
89
-caCertFile = ""
90
-certFile = ""
91
-keyFile = ""
92
-insecureSkipVerify = true
93
-gatherDuration = "5s"
94 38
 
95 39
 [prometheus]
96
-enable = true
40
+enable = false

+ 6
- 0
deploy/scripts/start-tdengine-operator.sh Переглянути файл

@@ -4,6 +4,8 @@
4 4
 # Network: host (required for TDengine FQDN mechanism)
5 5
 # taosadapter runs inside this container, listening on host port 6041
6 6
 # taoskeeper and taos-explorer are disabled (deployed separately)
7
+# Note: entrypoint.sh is overridden to add `-c /etc/taos/taosadapter.toml`
8
+#       because the upstream image starts taosadapter without config flag.
7 9
 
8 10
 set -e
9 11
 
@@ -12,6 +14,8 @@ IMAGE="docker.io/tdengine/tdengine:3.3.6.13"
12 14
 DATA_DIR="/mnt/tdengine-operator/data"
13 15
 LOG_DIR="/mnt/tdengine-operator/log"
14 16
 CFG_FILE="/mnt/tdengine-operator/taos.cfg"
17
+ADAPTER_CFG="/mnt/iot-platform/config/taosadapter.toml"
18
+ENTRYPOINT_FILE="/mnt/iot-platform/config/entrypoint.sh"
15 19
 
16 20
 echo "Starting ${CONTAINER_NAME}..."
17 21
 
@@ -27,6 +31,8 @@ podman run -d \
27 31
     -v "${DATA_DIR}:/var/lib/taos" \
28 32
     -v "${LOG_DIR}:/var/log/taos" \
29 33
     -v "${CFG_FILE}:/etc/taos/taos.cfg:ro" \
34
+    -v "${ADAPTER_CFG}:/etc/taos/taosadapter.toml:ro" \
35
+    -v "${ENTRYPOINT_FILE}:/usr/bin/entrypoint.sh:ro" \
30 36
     "${IMAGE}"
31 37
 
32 38
 echo "${CONTAINER_NAME} started."

Завантаження…
Відмінити
Зберегти