-
Notifications
You must be signed in to change notification settings - Fork 9
/
koctl
executable file
·147 lines (140 loc) · 4.46 KB
/
koctl
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
#!/bin/bash
action=$1
target=$2
KO_BASE=/opt
set -e
if [[ "${action}" == "upgrade" ]];then
export KO_BASE=`head -9 $(which koctl)|grep KO_BASE=|awk -F= '{print $2}'`
if [[ ${KO_BASE} == "" ]];then
echo "获取KubeOperator安装路径失败,请确认安装路径后检查 $(which koctl),KO_BASE 参数是否正确"
exit 0
fi
if [[ -f $(pwd)/kubeoperator/scripts/const.sh ]];then
sed -i -e "1,9s#KO_BASE=.*#KO_BASE=${KO_BASE}#g" $(pwd)/kubeoperator/scripts/const.sh | tee -a ${CWD}/upgrade.log
else
echo "开始在线升级"
fi
fi
if [[ -f ${KO_BASE}/kubeoperator/scripts/const.sh ]];then
source ${KO_BASE}/kubeoperator/scripts/const.sh
elif [ -f $(pwd)/kubeoperator/scripts/const.sh ]; then
source $(pwd)/kubeoperator/scripts/const.sh
else
export LATEST_KO_VERSION=$(curl -s https://github.com/KubeOperator/KubeOperator/releases/latest/download 2>&1 |grep -Eo "v([0-9]{1,}\.)+[0-9]{1,}")
if [ ! -z `echo ${target}|grep -Eo "v([0-9]{1,}\.)+[0-9]{1,}"` ];then
LATEST_KO_VERSION=${target}
fi
export KO_INSTALL_URL="https://github.com/KubeOperator/KubeOperator/releases/download/${LATEST_KO_VERSION}/installer-${LATEST_KO_VERSION}.tar.gz"
wget --no-check-certificate "${KO_INSTALL_URL}" -P $(pwd) | tee -a ${CWD}/upgrade.log
tar zxf $(pwd)/installer-${LATEST_KO_VERSION}.tar.gz -C $(pwd) > /dev/null 2>&1 | tee -a ${CWD}/upgrade.log
mkdir -p "${KO_BASE}/kubeoperator/scripts"
\cp -rp $(pwd)/installer/kubeoperator/scripts/* ${KO_BASE}/kubeoperator/scripts
source $(pwd)/installer/kubeoperator/scripts/const.sh
rm -rf $(pwd)/installer-${LATEST_KO_VERSION}.tar.gz
rm -rf $(pwd)/installer
fi
function usage() {
echo "KubeOperator 控制脚本"
echo
echo "Usage: "
echo " ./koctl.sh [COMMAND] [ARGS...]"
echo " ./koctl.sh --help"
echo "Commands: "
echo " status 查看 KubeOperator 服务运行状态"
echo " start 启动 KubeOperator 服务"
echo " stop 停止 KubeOperator 服务"
echo " restart 重启 KubeOperator 服务"
echo " reload 重新加载 KubeOperator 服务"
echo " uninstall 卸载 KubeOperator 服务"
echo " pull 在线拉取 KubeOperator 最新镜像"
echo " logs 查看 KubeOperator 日志信息"
echo " version 查看 KubeOperator 版本信息"
echo " backup 备份 KubeOperator,备份前需先停止 KubeOperator 服务"
echo " restore 恢复到 KubeOperator 指定的备份,例:koctl restore /opt/kubeoperator_backup/kubeoperator-backup-xxx.tar.gz"
echo " upgrade 升级 KubeOperator 版本,在线升级默认升级到最新版本,也可指定升级版本,例: koctl upgrade v3.0.1,离线升级请参考官方文档"
}
function status() {
echo
cd ${KO_BASE}/kubeoperator; docker-compose ps
}
function start() {
colorMsg $green "[Starting KubeOperator]"
cd ${KO_BASE}/kubeoperator; docker-compose up -d ${target}
}
function stop() {
colorMsg $green "[Stopping KubeOperator]"
cd ${KO_BASE}/kubeoperator; docker-compose down ${target}
}
function restart() {
stop
start
}
function reload() {
echo
cd ${KO_BASE}/kubeoperator; docker-compose up -d ${target}
}
function logs() {
echo
cd ${KO_BASE}/kubeoperator; docker-compose logs ${target}
}
function pull() {
echo
cd ${KO_BASE}/kubeoperator; docker-compose pull ${target}
}
function version() {
echo "$CURRENT_KO_VERSION"
}
function main() {
case "${action}" in
status)
status
;;
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
reload
;;
uninstall)
bash "${KO_BASE}/kubeoperator/scripts/uninstall.sh" ${target}
;;
version)
version
;;
pull)
pull
;;
logs)
logs
;;
upgrade)
if [ -f $(pwd)/kubeoperator/scripts/upgrade.sh ]; then
bash "$(pwd)/kubeoperator/scripts/upgrade.sh" ${target}
elif [ -f ${KO_BASE}/kubeoperator/scripts/upgrade.sh ]; then
bash "${KO_BASE}/kubeoperator/scripts/upgrade.sh" ${target}
fi
;;
backup)
bash "${KO_BASE}/kubeoperator/scripts/backup.sh"
;;
restore)
bash "${KO_BASE}/kubeoperator/scripts/restore.sh" ${target}
;;
help)
usage
;;
--help)
usage
;;
*)
echo "不支持的参数,请使用 help 或 --help 参数获取帮助"
;;
esac
}
main