|
|
@ -34,7 +34,7 @@ init(){ |
|
|
|
sed -i "s/USER=root/USER=${USER}/g" ${CURRENT_DIR}/.env |
|
|
|
sed -i "s/USER=root/USER=${USER}/g" ${CURRENT_DIR}/.env |
|
|
|
|
|
|
|
|
|
|
|
# 询问用户MySQL初始化密码,默认root3306,运行前请修改为其它复杂密码,密码如果为空,则设置为root3306,且密码不能低于8位字符 |
|
|
|
# 询问用户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}" = "" ] |
|
|
|
if [ "${MYSQL_ROOT_PASSWORD}" = "" ] |
|
|
|
then |
|
|
|
then |
|
|
@ -51,6 +51,9 @@ init(){ |
|
|
|
sed -i "s/MYSQL_ROOT_PASSWORD=root3306/MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}/g" ${CURRENT_DIR}/mysql/.env |
|
|
|
sed -i "s/MYSQL_ROOT_PASSWORD=root3306/MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}/g" ${CURRENT_DIR}/mysql/.env |
|
|
|
# 加载环境变量 |
|
|
|
# 加载环境变量 |
|
|
|
source ${CURRENT_DIR}/.env |
|
|
|
source ${CURRENT_DIR}/.env |
|
|
|
|
|
|
|
# 提示用户初始化完成 |
|
|
|
|
|
|
|
echo '------------------------------------------------------' |
|
|
|
|
|
|
|
echo "Initialization completed, please run the start command." |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
# 服务运行前必要检查 |
|
|
|
# 服务运行前必要检查 |
|
|
@ -81,27 +84,30 @@ start(){ |
|
|
|
run_check |
|
|
|
run_check |
|
|
|
# 获取用户传递的第二个参数 |
|
|
|
# 获取用户传递的第二个参数 |
|
|
|
service=$2 |
|
|
|
service=$2 |
|
|
|
|
|
|
|
echo $service |
|
|
|
# 如果service为空,或者为all,则运行所有服务 |
|
|
|
# 如果service为空,或者为all,则运行所有服务 |
|
|
|
if [ "${service}" = "" ] || [ "${service}" = "all" ] |
|
|
|
if [ "${service}" = "" ] || [ "${service}" = "all" ] |
|
|
|
then |
|
|
|
then |
|
|
|
# 遍历服务列表 |
|
|
|
# 遍历服务列表 |
|
|
|
for service in ${services[@]} |
|
|
|
for svc in "${services[@]}" |
|
|
|
do |
|
|
|
do |
|
|
|
# 拼接当前目录 + service,判断目录是否存在 |
|
|
|
# 拼接当前目录 + service,判断目录是否存在 |
|
|
|
if [ -d "${CURRENT_DIR}/${service}" ] |
|
|
|
if [ -d "${CURRENT_DIR}/${svc}" ] |
|
|
|
then |
|
|
|
then |
|
|
|
# 进入到service目录 |
|
|
|
# 进入到service目录 |
|
|
|
cd ${CURRENT_DIR}/${service} |
|
|
|
cd ${CURRENT_DIR}/${svc} |
|
|
|
|
|
|
|
# 重置目录权限 |
|
|
|
|
|
|
|
chown -R ${USER_ID}:${GROUP_ID} ${CURRENT_DIR}/${svc} |
|
|
|
# 运行docker-compose |
|
|
|
# 运行docker-compose |
|
|
|
docker-compose up -d |
|
|
|
docker-compose up -d |
|
|
|
echo '------------------------------------------------------' |
|
|
|
echo '------------------------------------------------------' |
|
|
|
echo "The ${service} service start success." |
|
|
|
echo "The ${svc} service start success." |
|
|
|
echo '------------------------------------------------------' |
|
|
|
echo '------------------------------------------------------' |
|
|
|
# 回到当前目录 |
|
|
|
# 回到当前目录 |
|
|
|
cd ${CURRENT_DIR} |
|
|
|
cd ${CURRENT_DIR} |
|
|
|
else |
|
|
|
else |
|
|
|
# 目录不存在,则直接提示服务不存在 |
|
|
|
# 目录不存在,则直接提示服务不存在 |
|
|
|
echo "The ${service} service does not exist." |
|
|
|
echo "The ${svc} service does not exist." |
|
|
|
fi |
|
|
|
fi |
|
|
|
done |
|
|
|
done |
|
|
|
exit |
|
|
|
exit |
|
|
@ -137,23 +143,23 @@ stop(){ |
|
|
|
if [ "${service}" = "" ] || [ "${service}" = "all" ] |
|
|
|
if [ "${service}" = "" ] || [ "${service}" = "all" ] |
|
|
|
then |
|
|
|
then |
|
|
|
# 遍历服务列表 |
|
|
|
# 遍历服务列表 |
|
|
|
for service in ${services[@]} |
|
|
|
for svc in "${services[@]}" |
|
|
|
do |
|
|
|
do |
|
|
|
# 拼接当前目录 + service,判断目录是否存在 |
|
|
|
# 拼接当前目录 + service,判断目录是否存在 |
|
|
|
if [ -d "${CURRENT_DIR}/${service}" ] |
|
|
|
if [ -d "${CURRENT_DIR}/${svc}" ] |
|
|
|
then |
|
|
|
then |
|
|
|
# 进入到service目录 |
|
|
|
# 进入到service目录 |
|
|
|
cd ${CURRENT_DIR}/${service} |
|
|
|
cd ${CURRENT_DIR}/${svc} |
|
|
|
# 停止docker-compose |
|
|
|
# 停止docker-compose |
|
|
|
docker-compose stop |
|
|
|
docker-compose stop |
|
|
|
echo '------------------------------------------------------' |
|
|
|
echo '------------------------------------------------------' |
|
|
|
echo "The ${service} service stop success." |
|
|
|
echo "The ${svc} service stop success." |
|
|
|
echo '------------------------------------------------------' |
|
|
|
echo '------------------------------------------------------' |
|
|
|
# 回到当前目录 |
|
|
|
# 回到当前目录 |
|
|
|
cd ${CURRENT_DIR} |
|
|
|
cd ${CURRENT_DIR} |
|
|
|
else |
|
|
|
else |
|
|
|
# 目录不存在,则直接提示服务不存在 |
|
|
|
# 目录不存在,则直接提示服务不存在 |
|
|
|
echo "The ${service} service does not exist." |
|
|
|
echo "The ${svc} service does not exist." |
|
|
|
fi |
|
|
|
fi |
|
|
|
done |
|
|
|
done |
|
|
|
exit |
|
|
|
exit |
|
|
|