From 8be068ec4b335c468070c2bf90a254fd4cfbee7f Mon Sep 17 00:00:00 2001 From: xiaoz Date: Thu, 23 Nov 2023 17:37:12 +0800 Subject: [PATCH] fix bug --- dnmp.sh | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/dnmp.sh b/dnmp.sh index 3df36a1..06e0c52 100644 --- a/dnmp.sh +++ b/dnmp.sh @@ -34,7 +34,7 @@ init(){ sed -i "s/USER=root/USER=${USER}/g" ${CURRENT_DIR}/.env # 询问用户MySQL初始化密码,默认root3306,运行前请修改为其它复杂密码,密码如果为空,则设置为root3306,且密码不能低于8位字符 - read -p "Please set the MySQL root password (default: root3306)" MYSQL_ROOT_PASSWORD + read -p "Please set the MySQL root password (default: root3306):" MYSQL_ROOT_PASSWORD # 如果密码为空 if [ "${MYSQL_ROOT_PASSWORD}" = "" ] then @@ -51,6 +51,9 @@ init(){ sed -i "s/MYSQL_ROOT_PASSWORD=root3306/MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}/g" ${CURRENT_DIR}/mysql/.env # 加载环境变量 source ${CURRENT_DIR}/.env + # 提示用户初始化完成 + echo '------------------------------------------------------' + echo "Initialization completed, please run the start command." } # 服务运行前必要检查 @@ -81,27 +84,30 @@ start(){ run_check # 获取用户传递的第二个参数 service=$2 + echo $service # 如果service为空,或者为all,则运行所有服务 if [ "${service}" = "" ] || [ "${service}" = "all" ] then # 遍历服务列表 - for service in ${services[@]} + for svc in "${services[@]}" do # 拼接当前目录 + service,判断目录是否存在 - if [ -d "${CURRENT_DIR}/${service}" ] + if [ -d "${CURRENT_DIR}/${svc}" ] then # 进入到service目录 - cd ${CURRENT_DIR}/${service} + cd ${CURRENT_DIR}/${svc} + # 重置目录权限 + chown -R ${USER_ID}:${GROUP_ID} ${CURRENT_DIR}/${svc} # 运行docker-compose docker-compose up -d echo '------------------------------------------------------' - echo "The ${service} service start success." + echo "The ${svc} service start success." echo '------------------------------------------------------' # 回到当前目录 cd ${CURRENT_DIR} else # 目录不存在,则直接提示服务不存在 - echo "The ${service} service does not exist." + echo "The ${svc} service does not exist." fi done exit @@ -137,23 +143,23 @@ stop(){ if [ "${service}" = "" ] || [ "${service}" = "all" ] then # 遍历服务列表 - for service in ${services[@]} + for svc in "${services[@]}" do # 拼接当前目录 + service,判断目录是否存在 - if [ -d "${CURRENT_DIR}/${service}" ] + if [ -d "${CURRENT_DIR}/${svc}" ] then # 进入到service目录 - cd ${CURRENT_DIR}/${service} + cd ${CURRENT_DIR}/${svc} # 停止docker-compose docker-compose stop echo '------------------------------------------------------' - echo "The ${service} service stop success." + echo "The ${svc} service stop success." echo '------------------------------------------------------' # 回到当前目录 cd ${CURRENT_DIR} else # 目录不存在,则直接提示服务不存在 - echo "The ${service} service does not exist." + echo "The ${svc} service does not exist." fi done exit