restart_dataops.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env bash
  2. #
  3. # DataOps Platform 重启脚本(Supervisor + dataops.env)
  4. #
  5. set -euo pipefail
  6. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  7. # shellcheck source=dataops-common.sh
  8. source "${SCRIPT_DIR}/dataops-common.sh"
  9. restart_app() {
  10. echo_info "正在重启 ${APP_NAME}..."
  11. supervisorctl restart "${APP_NAME}"
  12. sleep 8
  13. local status
  14. status="$(supervisorctl status "${APP_NAME}" | awk '{print $2}')"
  15. if [[ "${status}" == "RUNNING" ]]; then
  16. echo_info "${APP_NAME} 重启成功"
  17. supervisorctl status "${APP_NAME}"
  18. else
  19. echo_error "${APP_NAME} 重启失败,状态: ${status}"
  20. echo_info "查看日志: tail -f ${SUPERVISOR_LOG}"
  21. exit 1
  22. fi
  23. }
  24. main() {
  25. echo "=========================================="
  26. echo " DataOps Platform 重启脚本"
  27. echo "=========================================="
  28. if [[ "${EUID}" -ne 0 ]]; then
  29. echo_error "请使用 sudo 运行此脚本"
  30. exit 1
  31. fi
  32. check_env_file
  33. load_env_file
  34. check_venv
  35. check_run_script
  36. check_supervisor
  37. ensure_gunicorn_config "${SCRIPT_DIR}"
  38. ensure_run_script
  39. configure_supervisor
  40. restart_app
  41. if ! health_check; then
  42. echo_error "重启完成但服务未就绪,请查看上方诊断日志"
  43. exit 1
  44. fi
  45. local app_port
  46. app_port="$(resolve_listen_port)"
  47. echo ""
  48. echo_info "重启完成"
  49. echo_info "访问: http://127.0.0.1:${app_port}/api/system/health"
  50. }
  51. main "$@"