#!/bin/bash # 定义要停止的目录顺序(可以根据需要调整顺序) directories=("capability" "data" "flowable" "gateway2" "pbs" "system" "task" "project") base_dir="/home/app" # 记录是否有失败的停止操作 has_error=0 # 遍历目录并执行stop.sh for dir in "${directories[@]}"; do script_path="${base_dir}/${dir}/stop.sh" # 检查脚本是否存在 if [ -f "$script_path" ]; then echo "正在停止 ${dir} 服务..." # 检查脚本是否可执行,如不可执行则添加执行权限 if [ ! -x "$script_path" ]; then echo "为 ${script_path} 添加执行权限..." chmod +x "$script_path" fi # 执行停止脚本 "$script_path" # 检查上一个命令的执行结果 if [ $? -eq 0 ]; then echo "${dir} 服务停止成功" else echo "警告: ${dir} 服务停止失败" has_error=1 # 标记有错误发生 fi else echo "警告: ${script_path} 不存在,跳过该服务" has_error=1 # 标记有错误发生 fi echo "----------------------------------------" done # 根据是否有错误返回不同的退出码 if [ $has_error -eq 0 ]; then echo "所有服务停止成功" exit 0 else echo "部分服务停止失败,请检查" exit 1 fi