-
Notifications
You must be signed in to change notification settings - Fork 64
/
jmsctl.sh
executable file
·271 lines (251 loc) · 5.81 KB
/
jmsctl.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
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
#!/usr/bin/env bash
#
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=("$@")
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
}
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 $(gettext 'Start JumpServer')"
echo " stop $(gettext 'Stop JumpServer')"
echo " restart $(gettext 'Restart JumpServer')"
echo " status $(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 " 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 start() {
${EXE} up -d
}
function stop() {
if [[ -n "${target}" ]]; then
${EXE} stop "${target}" && ${EXE} rm -f "${target}"
return
fi
${EXE} down -v
}
function close() {
if [[ -n "${target}" ]]; then
${EXE} stop "${target}"
return
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() {
stop
echo -e "\n"
start
}
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
return
fi
if [[ "${target}" == "start" ]]; then
${EXE} up -d
fi
if [[ "${target}" == "stop" ]]; then
${EXE} down -v
fi
if [[ "${target}" == "restart" ]]; then
${EXE} down -v
${EXE} up -d
fi
if [[ "${target}" == "status" ]]; then
${EXE} ps
fi
}
function main() {
if [[ "${OS}" == 'Darwin' ]]; then
echo
echo "$(gettext 'Unsupported Operating System Error')"
echo "$(gettext 'macOS installer please see'): https://github.com/jumpserver/Dockerfile"
exit 0
fi
if [[ "${OS}" =~ MINGW.* ]]; then
echo
echo "$(gettext 'Unsupported Operating System Error')"
echo "$(gettext 'Windows installer please see'): https://github.com/jumpserver/Dockerfile"
exit 0
fi
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
;;
down)
if [[ -z "${target}" ]]; then
${EXE} down -v
else
${EXE} stop "${target}" && ${EXE} rm -f "${target}"
fi
;;
uninstall)
bash "${SCRIPT_DIR}/8_uninstall.sh"
;;
backup_db)
bash "${SCRIPT_DIR}/5_db_backup.sh"
;;
restore_db)
bash "${SCRIPT_DIR}/6_db_restore.sh" "$target"
;;
load_image)
bash "${SCRIPT_DIR}/3_load_images.sh"
;;
pull_images)
pull_images
;;
cmd)
echo "${EXE}"
;;
tail)
if [[ -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
;;
video-worker)
video-worker
;;
raw)
${EXE} "${args[@]:1}"
;;
version)
get_current_version
;;
help)
usage
;;
--help)
usage
;;
-h)
usage
;;
*)
echo "No such command: ${action}"
usage
;;
esac
}
main "$@"