oceanbase

Форк
0
264 строки · 7.3 Кб
1
#!/bin/bash
2
CWD=$(cd `dirname $0`;pwd)
3
cd "${CWD}"
4
source _env
5
export HOST_IP_MODE=1
6
export ENV_TELEMETRY_REPORTER="docker_${OB_CLUSTER_NAME}"
7

8
STAMP="$(date +%s)"
9
STEP=1
10
PHASE_START_TIME=0
11

12
function timediff() {
13
  start_time=$1
14
  end_time=$2
15

16
  start_s=${start_time%.*}
17
  start_nanos=${start_time#*.}
18
  end_s=${end_time%.*}
19
  end_nanos=${end_time#*.}
20

21
  if [ "$end_nanos" -lt "$start_nanos" ];then
22
      end_s=$(( 10#$end_s - 1 ))
23
      end_nanos=$(( 10#$end_nanos + 10**9 ))
24
  fi
25

26
  time=$(( 10#$end_s - 10#$start_s )).`printf "%03d\n" $(( (10#$end_nanos - 10#$start_nanos)/10**6 ))`
27
  echo $time
28
}
29

30
function print_start_phase() {
31
  echo "///////////////////////         STEP ${STEP}: $@         ///////////////////////"
32
  STEP=$[ ${STEP} + 1 ]
33
  PHASE_START_TIME=$(date +%s.%N)
34
}
35

36
function print_end_phase() {
37
  cur_time=$(date +%s.%N)
38
  echo "/////////////////////// phase end: $(timediff ${PHASE_START_TIME} ${cur_time}) s ///////////////////////"
39
}
40

41
function is_true() {
42
  value=$1
43
  # convert value to upper case string(can work in bash 4.x)
44
  value=${value^^}
45
  
46
  if [ "x${value}" == "xNO" ] || [ "x${value}" == "xFALSE" ] || [ "x${value}" == "x0" ]; then
47
    return 1
48
  fi
49
  return 0
50
}
51

52
function get_mode() {
53
  if test -z ${MODE}
54
  then
55
    MODE="MINI"
56
  fi
57
  MODE=${MODE^^}
58
}
59

60
function exit_while_error() {
61
  if test -z ${EXIT_WHILE_ERROR}
62
  then
63
    return 0 
64
  fi
65

66
  return `is_true ${EXIT_WHILE_ERROR}`
67
}
68

69
function fastboot() {
70
  if test -z ${FASTBOOT}
71
  then
72
    return 0
73
  fi
74

75
  return `is_true ${FASTBOOT}`
76
}
77

78
function remove_disk_check_logic_in_obd() {
79
  # make sure obd copy the plugin code
80
  obd cluster list
81
  start_check_files=('/root/.obd/plugins/oceanbase/3.1.0/start_check.py' '/root/.obd/plugins/oceanbase/4.0.0.0/start_check.py')
82
  for start_check_file in ${start_check_files[@]}
83
  do
84
    sed -i "s/critical('(%s) %s not enough disk space\. (Avail/alert('(%s) %s not enough disk space\. (Avail/g" $start_check_file
85
    sed -i "s/critical(EC_OBSERVER_NOT_ENOUGH_DISK_4_CLOG/alert(EC_OBSERVER_NOT_ENOUGH_DISK_4_CLOG/g" $start_check_file
86
  done
87
}
88

89
function run_custom_scripts {
90
  INIT_SCRIPTS_ROOT="${1}";
91

92
  # Check whether parameter has been passed on
93
  if [ -z "${INIT_SCRIPTS_ROOT}" ]; then
94
    echo "No INIT_SCRIPTS_ROOT passed on, no scripts will be run.";
95
    return;
96
  fi;
97

98
  # Execute custom provided files (only if directory exists and has files in it)
99
  if [ -d "${INIT_SCRIPTS_ROOT}" ] && [ -n "$(ls -A "${INIT_SCRIPTS_ROOT}")" ]; then
100
    echo -e "Executing user defined scripts..."
101
    run_custom_scripts_recursive ${INIT_SCRIPTS_ROOT}
102
    echo -e "DONE: Executing user defined scripts.\n"
103
  fi;
104
}
105

106
function run_custom_scripts_recursive {
107
  local f
108
  for f in "${1}"/*; do
109
    echo -e "running ${f} ...";
110
    obclient -h127.1 -uroot@${OB_TENANT_NAME} -A -P${OB_MYSQL_PORT} < ${f}
111
    echo "DONE: running ${f}";
112
  done
113
}
114

115
function deploy_failed {
116
  echo "deploy failed!"
117
  if exit_while_error
118
  then
119
    exit 1
120
  else
121
    echo "Please check the log file ${OB_HOME_PATH}/log/observer.log"
122
  fi
123
}
124

125
# We should decide whether the observer's data exists and
126
# whether the obd has the information of the cluster
127

128
if [ -f "$HOME/.obd/cluster/${OB_CLUSTER_NAME}/config.yaml" ]; then
129
  echo "find obd deploy information, skip configuring..." 
130
  echo "start ob cluster ..."
131
  obd cluster start $OB_CLUSTER_NAME
132

133
else # nothing here, bootstrap
134
  print_start_phase "Config Generation"
135
  TMPFILE="boot.${STAMP}.yaml"
136

137
  get_mode
138
  if [ "x${MODE}" == "xNORMAL" ]; then
139
    echo "oceanbase-ce docker in normal mode"
140
    cp -f boot-tmp.yaml $TMPFILE
141
  elif [ "x${MODE}" == "xMINI" ]; then
142
    echo "oceanbase-ce docker in mini mode"
143
    cp -f boot-mini-tmp.yaml $TMPFILE
144
  elif [ "x${MODE}" == "xSLIM" ]; then
145
    echo "oceanbase-ce docker in slim mode"
146
    cp -f boot-mini-tmp.yaml $TMPFILE
147
  else
148
    cp -f boot-mini-tmp.yaml $TMPFILE
149
  fi
150

151
  if [ "x${MODE}" != "xSLIM" ]; then
152
    cat obagent.yaml >> $TMPFILE
153
  fi
154

155
  if [ "x${MODE}" == "xSLIM" ]; then
156
    cat ob-configserver.yaml >> $TMPFILE
157
  fi
158

159
  sed -i "s|@OB_SERVER_IP@|${OB_SERVER_IP}|g" $TMPFILE
160
  sed -i "s|@OB_HOME_PATH@|${OB_HOME_PATH}|g" $TMPFILE
161
  sed -i "s|@OB_MYSQL_PORT@|${OB_MYSQL_PORT}|g" $TMPFILE
162
  sed -i "s|@OB_RPC_PORT@|${OB_RPC_PORT}|g" $TMPFILE
163
  sed -i "s|@OB_CLUSTER_NAME@|${OB_CLUSTER_NAME}|g" $TMPFILE
164
  sed -i "s|@OB_MEMORY_LIMIT@|${OB_MEMORY_LIMIT}|g" $TMPFILE
165
  sed -i "s|@OB_SYSTEM_MEMORY@|${OB_SYSTEM_MEMORY}|g" $TMPFILE
166
  sed -i "s|@OB_DATAFILE_SIZE@|${OB_DATAFILE_SIZE}|g" $TMPFILE
167
  sed -i "s|@OB_LOG_DISK_SIZE@|${OB_LOG_DISK_SIZE}|g" $TMPFILE
168
  sed -i "s|@OB_ROOT_PASSWORD@|${OB_ROOT_PASSWORD}|g" $TMPFILE
169

170
  [ "${OB_DATA_DIR}" ] && echo "    data_dir: ${OB_DATA_DIR}" >> $TMPFILE
171
  [ "${OB_REDO_DIR}" ] && echo "    redo_dir: ${OB_REDO_DIR}" >> $TMPFILE
172
  print_end_phase
173

174
  print_start_phase "Ob-deploy mirror clone"
175
  mkdir -p $OB_HOME_PATH
176
  obd mirror clone /root/pkg/*.rpm \
177
  && obd mirror list local
178
  print_end_phase
179

180
  print_start_phase "Ob-deploy deploy"
181
  remove_disk_check_logic_in_obd
182

183
  if fastboot; then
184
    obd devmode enable && obd cluster deploy "${OB_CLUSTER_NAME}" -c $TMPFILE;
185
    if [ $? -ne 0 ]; then
186
      deploy_failed
187
    fi
188
    print_end_phase
189

190
    print_start_phase "Ob-deploy restore store dir"
191
    rm -rf ${OB_HOME_PATH}/store && tar -Sxzvf /root/boot/store.tar.gz -C ${OB_HOME_PATH}
192
    BLOCK_CNT=`cat /root/boot/block_cnt`
193
    for i in $(seq 0 $[ $BLOCK_CNT - 1 ])
194
    do
195
      fallocate -o 0 -l 67108864 ${OB_HOME_PATH}/store/clog/log_pool/$i
196
      echo "restore block id $i"
197
    done
198
    print_end_phase
199

200
    print_start_phase "Ob-deploy import etc"
201
    cp -r /root/boot/etc/* ${OB_HOME_PATH}/etc
202
    print_end_phase
203

204
    print_start_phase "Ob-deploy start"
205
    obd cluster start ${OB_CLUSTER_NAME}
206
    print_end_phase
207

208
    if [ "x${MODE}" == "xSLIM" ]; then
209
      run_custom_scripts /root/boot/init.d
210
    fi
211

212
  else
213
    print_start_phase "Ob-deploy autodeploy"
214
    obd devmode enable && obd cluster autodeploy "${OB_CLUSTER_NAME}" -c $TMPFILE;
215
    print_end_phase
216

217
    print_start_phase "Ob-deploy Create Tenant"
218
    create_tenant_cmd="obd cluster tenant create ${OB_CLUSTER_NAME} -n ${OB_TENANT_NAME}"
219
    if ! [ -z "${OB_TENANT_MINI_CPU}" ]; then
220
      create_tenant_cmd="${create_tenant_cmd} --min-cpu=${OB_TENANT_MINI_CPU}"
221
    fi;
222
    if ! [ -z "${OB_TENANT_MEMORY_SIZE}" ]; then
223
      create_tenant_cmd="${create_tenant_cmd} --memory-size=${OB_TENANT_MEMORY_SIZE}"
224
    fi;
225
    if ! [ -z "${OB_TENANT_LOG_DISK_SIZE}" ]; then
226
      create_tenant_cmd="${create_tenant_cmd} --log-disk-size=${OB_TENANT_LOG_DISK_SIZE}"
227
    fi;
228
    eval ${create_tenant_cmd}
229
    if [ $? -ne 0 ]; then
230
      deploy_failed
231
    fi
232

233
    if [ "x${MODE}" != "xSLIM" ]; then
234
      obclient -h127.1 -uroot@${OB_TENANT_NAME} -A -P${OB_MYSQL_PORT} < init_tenant_user.sql
235
    else
236
      run_custom_scripts /root/boot/init.d
237
    fi
238
    print_end_phase
239
  fi
240

241
  if [ $? -ne 0 ]; then
242
    deploy_failed
243
  fi
244
  mv -f $TMPFILE ${OB_HOME_PATH}/boot.yaml && echo "deploy success!"
245
fi
246

247
if [ $? -eq 0 ]; then
248
  echo "boot success!"
249
  # close the enable_rich_error_msg
250
  PASSWORD_ARG=""
251
  if [ "${OB_ROOT_PASSWORD}" != "" ]; then
252
    PASSWORD_ARG="-p${OB_ROOT_PASSWORD}"
253
  fi
254
  obclient -h127.1 -uroot@sys -A -P${OB_MYSQL_PORT} ${PASSWORD_ARG} -e "alter system set enable_rich_error_msg = false;"
255
else
256
  echo "boot failed!"
257
  if exit_while_error
258
  then
259
    exit 1
260
  else
261
    echo "Please check the log file ${OB_HOME_PATH}/log/observer.log"
262
  fi
263
fi
264
exec tail -f /dev/null
265

266

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.