stop_dataops.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. #
  3. # DataOps Platform 停止脚本
  4. # 使用 supervisorctl 停止 gunicorn 服务
  5. #
  6. set -e
  7. # 配置变量
  8. APP_NAME="dataops-platform"
  9. APP_DIR="/opt/dataops-platform"
  10. # 颜色输出
  11. RED='\033[0;31m'
  12. GREEN='\033[0;32m'
  13. YELLOW='\033[1;33m'
  14. NC='\033[0m' # No Color
  15. echo_info() {
  16. echo -e "${GREEN}[INFO]${NC} $1"
  17. }
  18. echo_warn() {
  19. echo -e "${YELLOW}[WARN]${NC} $1"
  20. }
  21. echo_error() {
  22. echo -e "${RED}[ERROR]${NC} $1"
  23. }
  24. # 停止应用
  25. stop_app() {
  26. echo_info "正在停止 ${APP_NAME}..."
  27. # 检查 supervisor 是否运行
  28. if ! pgrep -x "supervisord" > /dev/null; then
  29. echo_warn "supervisord 未运行"
  30. # 尝试直接杀死 gunicorn 进程
  31. if pgrep -f "gunicorn.*${APP_NAME}" > /dev/null; then
  32. echo_info "发现 gunicorn 进程,正在终止..."
  33. pkill -f "gunicorn.*${APP_NAME}" || true
  34. echo_info "gunicorn 进程已终止"
  35. else
  36. echo_info "${APP_NAME} 未在运行"
  37. fi
  38. return 0
  39. fi
  40. # 检查应用状态
  41. status=$(sudo supervisorctl status ${APP_NAME} 2>/dev/null | awk '{print $2}' || echo "UNKNOWN")
  42. if [ "$status" = "STOPPED" ] || [ "$status" = "UNKNOWN" ]; then
  43. echo_info "${APP_NAME} 已经停止"
  44. return 0
  45. fi
  46. # 停止应用
  47. sudo supervisorctl stop ${APP_NAME}
  48. # 等待停止
  49. sleep 2
  50. # 检查停止状态
  51. status=$(sudo supervisorctl status ${APP_NAME} | awk '{print $2}')
  52. if [ "$status" = "STOPPED" ]; then
  53. echo_info "${APP_NAME} 已停止"
  54. else
  55. echo_warn "状态: ${status}"
  56. fi
  57. sudo supervisorctl status ${APP_NAME}
  58. }
  59. # 主函数
  60. main() {
  61. echo "=========================================="
  62. echo " DataOps Platform 停止脚本"
  63. echo "=========================================="
  64. stop_app
  65. echo ""
  66. echo_info "停止完成!"
  67. }
  68. main "$@"