在 base.sh 中添加重启容器的功能,并在 install.sh 中相应地调用该功能以确保配置更改后容器自动重启

This commit is contained in:
Olia Lisa 2026-01-12 15:56:27 +08:00
parent 3c049ba1db
commit d302342f02
2 changed files with 27 additions and 0 deletions

View File

@ -142,4 +142,28 @@ check_config_file(){
echo "配置文件不是有效的JSON格式, 请重新生成配置文件."
exit 1
fi
}
restart_docker() {
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../" # 脚本文件夹绝对路径
# 如果容器未运行,提示启动
local running_count=$(docker-compose -f $script_dir/../docker-compose.yml ps -q | wc -l)
if [ "$running_count" -eq 0 ]; then
read -p "容器未启动,是否启动容器?(y/n): " choice
case "$choice" in
Y|y)
docker-compose -f $script_dir/../docker-compose.yml up -d
return
;;
*)
echo "已取消启动"
return
;;
esac
fi
echo "正在重启容器..."
docker-compose -f $script_dir/../docker-compose.yml down
docker-compose -f $script_dir/../docker-compose.yml up -d
}

View File

@ -73,11 +73,13 @@ main(){
# 修改域名
check_config_file
bash ./bin/update_domain.sh
restart_docker
;;
5)
# 修改端口
check_config_file
bash ./bin/update_port.sh
restart_docker
;;
6)
# 启动容器
@ -92,6 +94,7 @@ main(){
8)
# 更新镜像
bash ./bin/update_docker_images.sh
restart_docker
;;
*)
echo "无效的选择, 请重新选择."