From d302342f0285413bd4fbd240ee3e84cf89586058 Mon Sep 17 00:00:00 2001 From: Olia Lisa Date: Mon, 12 Jan 2026 15:56:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=20base.sh=20=E4=B8=AD=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E9=87=8D=E5=90=AF=E5=AE=B9=E5=99=A8=E7=9A=84=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E5=B9=B6=E5=9C=A8=20install.sh=20=E4=B8=AD?= =?UTF-8?q?=E7=9B=B8=E5=BA=94=E5=9C=B0=E8=B0=83=E7=94=A8=E8=AF=A5=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E4=BB=A5=E7=A1=AE=E4=BF=9D=E9=85=8D=E7=BD=AE=E6=9B=B4?= =?UTF-8?q?=E6=94=B9=E5=90=8E=E5=AE=B9=E5=99=A8=E8=87=AA=E5=8A=A8=E9=87=8D?= =?UTF-8?q?=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/utils/base.sh | 24 ++++++++++++++++++++++++ install.sh | 3 +++ 2 files changed, 27 insertions(+) diff --git a/bin/utils/base.sh b/bin/utils/base.sh index 995bfaf..d209876 100644 --- a/bin/utils/base.sh +++ b/bin/utils/base.sh @@ -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 } \ No newline at end of file diff --git a/install.sh b/install.sh index 641b798..0a95e80 100644 --- a/install.sh +++ b/install.sh @@ -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 "无效的选择, 请重新选择."