2
0

fix: upgrade db

This commit is contained in:
zhangsz
2025-02-14 19:32:32 +08:00
parent 585fb8ba17
commit 24145b7aea
2 changed files with 26 additions and 15 deletions

View File

@@ -157,17 +157,28 @@ case "$1" in
done
;;
upgdb)
CONTAINER_NAME="wfc-mysql"
mysql_container_name=wfc-mysql
# upgrade database
cd ${docker_work_dir}
docker-compose up -d wfc-mysql
docker-compose up -d ${mysql_container_name}
sleep 10
# 获取 MySQL 容器的 IP 地址
mysql_container_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ${mysql_container_name})
# 在容器内生成 my.cnf 文件
docker exec ${mysql_container_name} bash -c "cat <<EOF > ${docker_my_conf_file}
[client]
user=root
password=\${MYSQL_ROOT_PASSWORD}
host=${mysql_container_ip}
port=3306
EOF"
# 检查容器健康状态
timeout=30
timeout=60
interval=2
elapsed=0
while [ $elapsed -lt $timeout ]; do
health_status=$(docker inspect --format='{{.State.Health.Status}}' $CONTAINER_NAME)
health_status=$(docker inspect --format='{{.State.Health.Status}}' $mysql_container_name)
if [ "$health_status" == "healthy" ]; then
echo "Upgrade database: "
${wfc_work_dir}/bin/wfcupgdb.sh all
@@ -177,7 +188,7 @@ case "$1" in
elapsed=$((elapsed + interval))
done
echo "Container $CONTAINER_NAME is not healthy after $timeout seconds, please check the container status."
echo "Container $mysql_container_name is not healthy after $timeout seconds, please check the container status."
;;
base)
# build docker compose