From 6cf59b443e9a5fc0d8589869550f70a74dc36ebd Mon Sep 17 00:00:00 2001 From: xuwei-fit2cloud Date: Tue, 7 Nov 2023 17:23:07 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BF=AE=E6=94=B9healthcheck?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- installer/dectl | 27 +++++++++++++++++++-------- installer/install.sh | 21 +-------------------- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/installer/dectl b/installer/dectl index 44096b4a14..1024756a13 100644 --- a/installer/dectl +++ b/installer/dectl @@ -66,21 +66,32 @@ function _init_apisix() { function _healthcheck() { echo - for b in {1..30} + container_name=$(grep "container_name" $DE_RUNNING_BASE/docker-compose.yml | awk -F': ' '{print $2}') + sleep 1 + if [ -z $(docker ps --filter "name=$container_name" -q) ];then + echo "未找到容器 $container_name,请检查配置文件。" + exit 1 + fi + + for b in {1..90} do - sleep 3 - http_code=$(curl -sILw "%{http_code}\n" http://localhost:${DE_PORT} -o /dev/null) - if [[ $http_code == 000 ]];then - echo "DataEase 服务状态 : 正在启动" - elif [[ $http_code == 200 ]];then - echo "DataEase 服务状态 : 正常运行" - break; + sleep 1 + read status healthy<<<$(docker inspect $container_name --format '{{.State.Status}} {{.State.Health.Status}}') + if [[ "$healthy" == "starting" ]];then + printf "\rDataEase 服务状态 : 正在启动 ... %3ds" $b + elif [[ "$status" == "running" ]] && [[ "$healthy" == "healthy" ]];then + printf "\rDataEase 服务状态 : 正常运行 " + echo + return; else + echo echo -e "DataEase 服务状态 : \033[31m无法访问\033[0m" exit 1 fi done echo + echo "【警告】服务在等待时间内未完全启动!请稍后使用 dectl status 检查服务运行状况。" + echo } function _get_current_version() { de_current_version=$(grep "^ image:.*dataease:" ${DE_RUNNING_BASE}/docker-compose.yml | awk -F'dataease:' '{print $2}') diff --git a/installer/install.sh b/installer/install.sh index 5debe525d7..54e87767e5 100644 --- a/installer/install.sh +++ b/installer/install.sh @@ -238,24 +238,5 @@ log "启动服务" dectl start | tee -a ${CURRENT_DIR}/install.log dectl status 2>&1 | tee -a ${CURRENT_DIR}/install.log -for b in {1..30} -do - sleep 3 - http_code=$(curl -sILw "%{http_code}\n" http://localhost:${DE_PORT} -o /dev/null) - if [[ $http_code == 000 ]];then - log "服务启动中,请稍候 ..." - elif [[ $http_code == 200 ]];then - log "服务启动成功!" - break; - else - log "服务启动出错!" - exit 1 - fi -done - -if [[ $http_code != 200 ]];then - log "【警告】服务在等待时间内未完全启动!请稍后使用 dectl status 检查服务运行状况。" -fi - echo -e "======================= 安装完成 =======================\n" 2>&1 | tee -a ${CURRENT_DIR}/install.log - +echo -e "系统登录信息如下:\n 用户名: admin\n 初始密码: dataease" 2>&1 | tee -a ${CURRENT_DIR}/install.log \ No newline at end of file