-
Notifications
You must be signed in to change notification settings - Fork 1
/
mo_ctl.sh
executable file
·188 lines (173 loc) · 4.63 KB
/
mo_ctl.sh
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
#!/bin/bash
################################################################
# Copyright (C) 2023 Matrix Origin. All Rights Reserved
# Visit us at https://www.matrixorigin.cn/
################################################################
if ! pwd >/dev/null 2>&1; then
nowtime="$(date '+%Y-%m-%d_%H:%M:%S.%N')"
nowtime="$(echo "${nowtime}" | cut -b 1-23)"
echo "${nowtime} [ERROR] You're currently on a path that no loner exists, please change to a valid directory and re-execute mo_ctl command"
exit 1
fi
# Work dir
WORK_DIR=$(cd "$(dirname "$0")" || exit; pwd)
# conf
CONF_FILE="${WORK_DIR}/conf/env.sh"
CONF_FILE_DEFAULT="${WORK_DIR}/conf/env.sh.default"
# bin
BIN_DIR="${WORK_DIR}/bin"
# log
LOG_DIR="${WORK_DIR}/log"
# scripts
#SCRIPT_LIST=("basic" "help" "precheck" "deploy" \
# "status" "start" "stop" "restart" \
# "connect" "pprof" "set_conf" "get_conf" "get_cid" \
# "mysql_to_mo" "ddl_convert" "watchdog" "upgrade" \
# "get_branch" "uninstall" "sql" "csv_convert" \
# "version" "auto_backup" "auto_clean_logs" \
# "build_image" "monitor" "restore" \
#)
PIDS=""
MO_V_TYPE="unknown"
function main()
{
# Get confs and scripts
source "${CONF_FILE}"
for script in `ls ${BIN_DIR}/ | grep .sh`; do
source "${BIN_DIR}/${script}"
done
rc=0
all_vars="$*"
var_2=`echo ${all_vars} | awk '{print $2}'`
option_1=`echo "${all_vars}" | awk '{print $1}'`
option_2=`echo "${all_vars}" | awk '{print $2}'`
option_3=`echo "${all_vars}" | awk '{print $3}'`
option_4=`echo "${all_vars}" | awk '{print $4}'`
# deprecated
# option_1=$1
# option_2=$2
# option_3=$3
# option_4=$4
if [[ ${option_2} == "help" ]]; then
help_2
return 0
fi
current_path=`pwd`
case "${option_1}" in
"" | "help")
help_1
;;
"precheck")
precheck
;;
"deploy")
deploy "${option_2}" "${option_3}" "${option_4}"
;;
"status")
status
;;
"start")
start
;;
"stop")
stop "${option_2}"
;;
"restart")
restart "${option_2}"
;;
"connect")
connect
;;
"get_cid")
get_cid "${option_2}"
;;
"pprof")
pprof "${option_2}" "${option_3}"
;;
"set_conf")
shift_vars=`echo "${all_vars#* }"`
if [[ "${var_2}" == "" ]]; then
add_log "E" "Set content is empty, please check again"
help_set_conf
return 1
fi
set_conf "${shift_vars}"
;;
"get_conf")
get_conf "${option_2}"
;;
"ddl_convert")
ddl_convert "${option_2}" "${option_3}" "${option_4}"
;;
"watchdog")
watchdog "${option_2}"
;;
"upgrade")
upgrade "${option_2}"
;;
"get_branch")
get_branch "${option_2}"
;;
"uninstall")
uninstall
;;
"sql")
if [[ "${var_2}" == "" ]]; then
add_log "E" "Query is empty, please check again"
help_sql
return 1
fi
#shift_vars=`echo "${all_vars#* }"`
shift_vars="${all_vars#* }"
sql "${shift_vars}"
;;
"csv_convert")
csv_convert
;;
"version")
version
;;
"auto_backup")
auto_backup "${option_2}" "${option_3}"
;;
"backup")
if [[ "${option_2}" == "list" ]]; then
backup_list "${option_3}"
else
backup
fi
;;
"restore")
if [[ "${option_2}" == "list" ]]; then
restore_list "${option_3}"
else
restore
fi
;;
"clean_backup")
clean_backup
;;
"clean_logs")
clean_logs
;;
"auto_clean_logs")
auto_clean_logs "${option_2}"
;;
"build_image")
build_image
;;
"monitor")
monitor "${option_2}" "${option_3}"
;;
*)
add_log "E" "Invalid option_1: ${option_1}, please refer to usage help info below"
help_1
cd "${current_path}" || exit
return 1
;;
esac
rc=$?
cd "${current_path}" || exit
return ${rc}
}
main "$*"