在 run.sh 中优化容器状态检查逻辑;在 install.sh 中添加配置文件检查功能以验证 JSON 格式

This commit is contained in:
Olia Lisa 2026-01-11 11:55:59 +08:00
parent 4425a908f4
commit 9d1a13a140
2 changed files with 24 additions and 5 deletions

View File

@ -24,12 +24,10 @@ run() {
bash "$script_dir/create_config.sh" # 创建配置
fi
# 检查容器是否已启动,如果启动则先关闭
# 如果容器已经启动, 则先停止容器
local compose_file="$script_dir/../docker-compose.yml"
if docker-compose -f "$compose_file" ps | grep -q "Up"; then
echo "检测到容器正在运行,正在关闭容器..."
docker-compose -f "$compose_file" down
echo "容器已关闭"
fi
# 启动docker容器

View File

@ -29,6 +29,25 @@ install(){
fi
}
check_config_file(){
local script_dir="$(cd "$(dirname "$0")"; pwd)/bin" # 脚本所在目录
local config_file="$script_dir/../config/config.json"
# 检查配置文件是否存在
if [ ! -e "$config_file" ]; then
echo "配置文件不存在, 请先生成配置文件."
exit 1
fi
# 检查配置文件是否为有效的JSON格式
if jq '.' "$config_file" >/dev/null 2>&1; then
echo "有效的JSON文件"
else
echo "无效的JSON文件"
fi
}
main(){
local script_dir="$(cd "$(dirname "$0")"; pwd)/bin" # 脚本所在目录
source "${script_dir}/utils/base.sh"
@ -64,24 +83,26 @@ main(){
;;
3)
# 查看分享链接
check_config_file
bash ./bin/print_share_link.sh
;;
4)
# 修改域名
check_config_file
bash ./bin/update_domain.sh
;;
5)
# 修改端口
check_config_file
bash ./bin/update_port.sh
;;
6)
# 启动容器
echo "启动容器.."
check_config_file
bash ./bin/run.sh
;;
7)
# 停止容器
echo "正在停止容器.."
docker-compose -f ./docker-compose.yml down
;;
8)