forked from KubeOperator/KubeOperator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kubeopsctl.sh
executable file
·94 lines (87 loc) · 2.18 KB
/
kubeopsctl.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
BASE_DIR=$(cd "$(dirname "$0")";pwd)
source ${BASE_DIR}/scripts/utils.sh
PROJECT_DIR=${BASE_DIR}
SCRIPT_DIR=${BASE_DIR}/scripts
action=$1
target=$2
args=$@
function usage() {
echo "kubeOperator 部署安装脚本"
echo
echo "Usage: "
echo " kubeopsctl [COMMAND] [ARGS...]"
echo " kubeopsctl --help"
echo
echo "Commands: "
echo " install 部署安装 kubeOperator"
echo " start 启动 kubeOperator"
echo " restart [service] 重启, 并不会重建服务容器"
echo " reload [service] 重建容器如何需要并重启服务"
echo " status 查看 kubeOperator 状态"
echo " down [service] 删掉容器 不带参数删掉所有"
echo " python 进入 api, 运行 python manage.py shell"
echo " db 连接数据库"
echo " ... 其他 docker-compose 执行的命令 如 logs 等等"
}
function service_to_docker_name() {
service=$1
if [[ "${service:0:3}" != "f2o" ]];then
service=jms_${service}
fi
echo ${service}
}
function main() {
EXE=docker-compose
case "${action}" in
install)
bash ${SCRIPT_DIR}/4_install.sh
;;
start)
${EXE} up -d
;;
restart)
${EXE} restart ${target}
;;
reload)
${EXE} up -d &> /dev/null
${EXE} restart ${target}
;;
status)
${EXE} ps
;;
down)
if [[ -z "${target}" ]];then
${EXE} down
else
${EXE} stop ${target} && ${EXE} rm ${target}
fi
;;
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
;;
python)
docker exec -it kubeops_api python manage.py shell
;;
db)
docker exec -it kubeops_api python manage.py dbshell
;;
exec)
docker_name=$(service_to_docker_name ${target})
docker exec -it ${docker_name} sh
;;
help)
usage
;;
--help)
usage
;;
*)
${EXE} ${args}
esac
}
main