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 done
;; ;;
upgdb) upgdb)
CONTAINER_NAME="wfc-mysql" mysql_container_name=wfc-mysql
# upgrade database # upgrade database
cd ${docker_work_dir} 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 interval=2
elapsed=0 elapsed=0
while [ $elapsed -lt $timeout ]; do 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 if [ "$health_status" == "healthy" ]; then
echo "Upgrade database: " echo "Upgrade database: "
${wfc_work_dir}/bin/wfcupgdb.sh all ${wfc_work_dir}/bin/wfcupgdb.sh all
@@ -177,7 +188,7 @@ case "$1" in
elapsed=$((elapsed + interval)) elapsed=$((elapsed + interval))
done 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) base)
# build docker compose # build docker compose

View File

@@ -8,16 +8,16 @@ docker_mysql_conf_d=/etc/mysql/conf.d
docker_my_conf_file=${docker_mysql_conf_d}/my.cnf docker_my_conf_file=${docker_mysql_conf_d}/my.cnf
mysql_container_name=wfc-mysql mysql_container_name=wfc-mysql
# 获取 MySQL 容器的 IP 地址 # # 获取 MySQL 容器的 IP 地址
mysql_container_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ${mysql_container_name}) # mysql_container_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ${mysql_container_name})
# 在容器内生成 my.cnf 文件 # # 在容器内生成 my.cnf 文件
docker exec ${mysql_container_name} bash -c "cat <<EOF > ${docker_my_conf_file} # docker exec ${mysql_container_name} bash -c "cat <<EOF > ${docker_my_conf_file}
[client] # [client]
user=root # user=root
password=\${MYSQL_ROOT_PASSWORD} # password=\${MYSQL_ROOT_PASSWORD}
host=${mysql_container_ip} # host=${mysql_container_ip}
port=$ # port=3306
EOF" # EOF"
case "$1" in case "$1" in
system) system)