在 base.sh 中添加重启容器的功能,并在 install.sh 中相应地调用该功能以确保配置更改后容器自动重启
This commit is contained in:
parent
3c049ba1db
commit
d302342f02
@ -143,3 +143,27 @@ check_config_file(){
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
||||||
|
}
|
||||||
@ -73,11 +73,13 @@ main(){
|
|||||||
# 修改域名
|
# 修改域名
|
||||||
check_config_file
|
check_config_file
|
||||||
bash ./bin/update_domain.sh
|
bash ./bin/update_domain.sh
|
||||||
|
restart_docker
|
||||||
;;
|
;;
|
||||||
5)
|
5)
|
||||||
# 修改端口
|
# 修改端口
|
||||||
check_config_file
|
check_config_file
|
||||||
bash ./bin/update_port.sh
|
bash ./bin/update_port.sh
|
||||||
|
restart_docker
|
||||||
;;
|
;;
|
||||||
6)
|
6)
|
||||||
# 启动容器
|
# 启动容器
|
||||||
@ -92,6 +94,7 @@ main(){
|
|||||||
8)
|
8)
|
||||||
# 更新镜像
|
# 更新镜像
|
||||||
bash ./bin/update_docker_images.sh
|
bash ./bin/update_docker_images.sh
|
||||||
|
restart_docker
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "无效的选择, 请重新选择."
|
echo "无效的选择, 请重新选择."
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user