-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathjmsctl.sh
More file actions
executable file
·382 lines (354 loc) · 8.33 KB
/
Copy pathjmsctl.sh
File metadata and controls
executable file
·382 lines (354 loc) · 8.33 KB
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
#!/usr/bin/env bash
#
export SHELLOPTS
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
cd "${PROJECT_DIR}" || exit 1
. "${PROJECT_DIR}/scripts/utils.sh"
action=${1-}
target=${2-}
args=("$@")
skip_jdmc=false
if [[ "${target}" == "--skip-jdmc" || "${target}" == "--skip-kotl" ]]; then
case "${action}" in
start|stop|restart|close|status|down)
skip_jdmc=true
target=""
;;
esac
fi
function check_config_file() {
if [[ ! -f "${CONFIG_FILE}" ]]; then
echo "$(gettext 'Configuration file not found'): ${CONFIG_FILE}"
echo "$(gettext 'If you are upgrading from v1.5.x, please copy the config.txt To') ${CONFIG_FILE}"
return 3
fi
if [[ -f .env ]]; then
if ! ls -l .env | grep "${CONFIG_FILE}" &>/dev/null; then
echo ".env $(gettext 'There is a problem with the soft connection, Please update it again')"
rm -f .env
fi
fi
if [[ ! -f ".env" ]]; then
ln -s "${CONFIG_FILE}" .env
fi
if [[ ! -f "./compose/.env" ]]; then
ln -s "${CONFIG_FILE}" ./compose/.env
fi
gen_safe_config >/dev/null
}
function pre_check() {
check_config_file || return 3
}
function usage() {
echo "$(gettext 'JumpServer Deployment Management Script')"
echo
echo "Usage: "
echo " ./jmsctl.sh [COMMAND] [ARGS...]"
echo " ./jmsctl.sh --help"
echo
echo "Installation Commands: "
echo " install $(gettext 'Install JumpServer')"
echo " upgrade $(gettext 'Upgrade JumpServer')"
echo
echo "Management Commands: "
echo " config $(gettext 'Configuration Tools')"
echo " start [--skip-jdmc] $(gettext 'Start JumpServer')"
echo " stop [--skip-jdmc] $(gettext 'Stop JumpServer')"
echo " restart [--skip-jdmc] $(gettext 'Restart JumpServer')"
echo " status [--skip-jdmc] $(gettext 'Check JumpServer')"
echo " down $(gettext 'Offline JumpServer')"
echo " uninstall $(gettext 'Uninstall JumpServer')"
echo
echo "More Commands: "
echo " load_image $(gettext 'Loading docker image')"
echo " backup_db $(gettext 'Backup database')"
echo " backup_no_audit $(gettext 'Backup database without audit data')"
echo " backup_audit $(gettext 'Backup audits tables')"
echo " restore_db [file] $(gettext 'Data recovery through database backup file')"
echo " raw $(gettext 'Execute the original docker compose command')"
echo " tail [service] $(gettext 'View log')"
echo
}
function service_to_docker_name() {
service=$1
if [[ "${service:0:3}" != "jms" ]]; then
service=jms_${service}
fi
echo "${service}"
}
EXE=""
function should_manage_jdmc() {
[[ "${skip_jdmc}" != "true" ]]
}
function is_jdmc_target() {
[[ "${target}" == "jdmc" || "${target}" == "kotl" ]]
}
function start() {
set_openbao || return 1
configure_jdmc || return 1
gen_safe_config >/dev/null
EXE=$(get_docker_compose_cmd_line)
${EXE} up -d || return 1
ensure_current_installer_link || return 1
if should_manage_jdmc; then
start_jdmc
fi
}
function stop() {
if is_jdmc_target; then
stop_jdmc
elif [[ "${target}" == "ignore_db" ]]; then
if should_manage_jdmc; then
stop_jdmc || return 1
fi
cmd=$(get_docker_compose_cmd_line "ignore_db")
${cmd} down -v
elif [[ -n "${target}" ]]; then
${EXE} stop "${target}" && ${EXE} rm -f "${target}"
else
if should_manage_jdmc; then
stop_jdmc || return 1
fi
${EXE} down -v
fi
}
function close() {
if [[ -n "${target}" ]]; then
if is_jdmc_target; then
stop_jdmc
return
fi
${EXE} stop "${target}"
return
fi
if should_manage_jdmc; then
stop_jdmc || return 1
fi
services=$(get_docker_compose_services ignore_db)
for i in ${services}; do
${EXE} stop "${i}"
done
}
function pull() {
if [[ -n "${target}" ]]; then
${EXE} pull "${target}"
return
fi
${EXE} pull
}
function restart() {
if is_jdmc_target; then
restart_jdmc
return
fi
stop || return 1
echo -e "\n"
if [[ -n "${target}" && "${target}" != "ignore_db" ]]; then
${EXE} up -d "${target}"
return
fi
start
}
function clean() {
rm -f scripts/docker/*
rm -f scripts/images/*
}
function check_update() {
current_version=$(get_current_version)
latest_version=$(get_latest_version)
if [[ "${current_version}" == "${latest_version}" ]]; then
echo_green "$(gettext 'The current version is up to date'): ${latest_version}"
echo
return
fi
if [[ -n "${latest_version}" ]] && [[ ${latest_version} =~ v.* ]]; then
echo -e "\033[32m$(gettext 'The latest version is'): ${latest_version}\033[0m"
else
exit 1
fi
}
function video-worker() {
EXE=$(get_video_worker_cmd_line)
if [[ ! "${EXE}" ]]; then
log_error "video-worker is only available in the enterprise edition"
return 1
fi
case "${target}" in
start) ${EXE} up -d ;;
stop) ${EXE} down -v ;;
restart)
${EXE} down -v && ${EXE} up -d
;;
status) ${EXE} ps ;;
*)
log_error "Usage: ./jmsctl.sh video-worker {start|stop|restart|status}"
return 2
;;
esac
}
function check_os() {
if [[ -n "$UNCHECK_DEPENDENCIES" ]]; then
return 0
fi
if [[ "${OS}" == 'Darwin' ]]; then
echo
echo "$(gettext 'Unsupported Operating System Error')"
echo "$(gettext 'macOS installer please see'): https://github.com/jumpserver/Dockerfile"
return 1
fi
if [[ "${OS}" =~ MINGW.* ]]; then
echo
echo "$(gettext 'Unsupported Operating System Error')"
echo "$(gettext 'Windows installer please see'): https://github.com/jumpserver/Dockerfile"
return 1
fi
return 0
}
function main() {
check_os || return 3
if [[ "${action}" == "help" || "${action}" == "h" || "${action}" == "-h" || "${action}" == "--help" ]]; then
echo ""
elif [[ "${action}" == "install" || "${action}" == "config" || "${action}" == "reconfig" ]]; then
echo ""
else
pre_check || return 3
EXE=$(get_docker_compose_cmd_line)
fi
case "${action}" in
install)
bash "${SCRIPT_DIR}/4_install_jumpserver.sh"
;;
upgrade)
bash "${SCRIPT_DIR}/7_upgrade.sh" "$target"
;;
check_update)
check_update
;;
config)
bash "${SCRIPT_DIR}/config.sh" "$target"
;;
reconfig)
${EXE} down -v
bash "${SCRIPT_DIR}/1_config_jumpserver.sh"
;;
start)
start
;;
restart)
restart
;;
stop)
stop
;;
pull)
pull
;;
close)
close
;;
status)
${EXE} ps
if should_manage_jdmc; then
status_jdmc
fi
;;
down)
if [[ -z "${target}" ]]; then
if should_manage_jdmc; then
stop_jdmc || exit 1
fi
${EXE} down -v
elif is_jdmc_target; then
stop_jdmc
else
${EXE} stop "${target}" && ${EXE} rm -f "${target}"
fi
;;
uninstall)
bash "${SCRIPT_DIR}/8_uninstall.sh"
;;
migrate_db)
if ! perform_db_migrations; then
log_error "$(gettext 'Failed to change the table structure')!"
exit 1
fi
;;
backup_db)
bash "${SCRIPT_DIR}/5_db_backup.sh"
;;
backup_no_audit)
bash "${SCRIPT_DIR}/5_db_backup.sh" "no_audit"
;;
backup_audit)
bash "${SCRIPT_DIR}/5_db_backup.sh" "audit"
;;
restore_db)
bash "${SCRIPT_DIR}/6_db_restore.sh" "$target"
;;
load_image)
bash "${SCRIPT_DIR}/3_load_images.sh"
;;
pull_images)
pull_images
;;
pull_mysql)
docker pull registry.cn-beijing.aliyuncs.com/jumpservice/mysql:8.0
docker tag registry.cn-beijing.aliyuncs.com/jumpservice/mysql:8.0 mysql:8.0
;;
cmd)
echo "${EXE}"
;;
tail)
if is_jdmc_target; then
tail_jdmc
elif [[ -z "${target}" ]]; then
${EXE} logs --tail 100 -f
else
docker_name=$(service_to_docker_name "${target}")
docker logs -f "${docker_name}" --tail 100
fi
;;
show_services)
get_docker_compose_services
;;
init_db)
perform_db_migrations
;;
restart_db)
db_redis_restart "${target}"
;;
stop_db)
db_redis_stop "${target}"
;;
start_db)
db_redis_start "${target}"
;;
cmd_db)
get_db_compose_cmd "${target}"
;;
video-worker)
video-worker
;;
raw)
${EXE} "${args[@]:1}"
;;
version)
get_current_version
;;
help)
usage
;;
--help)
usage
;;
-h)
usage
;;
*)
echo "No such command: ${action}"
usage
return 2
;;
esac
}
main "$@"