数据解析模块
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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