start_dataops.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. start_app() {
  10. echo_info "正在启动 ${APP_NAME}..."
  11. local status
  12. status="$(supervisorctl status "${APP_NAME}" 2>/dev/null | awk '{print $2}' || echo "UNKNOWN")"
  13. if [[ "${status}" == "RUNNING" ]]; then
  14. echo_warn "${APP_NAME} 已在运行"
  15. supervisorctl status "${APP_NAME}"
  16. return 0
  17. fi
  18. supervisorctl start "${APP_NAME}"
  19. sleep 3
  20. status="$(supervisorctl status "${APP_NAME}" | awk '{print $2}')"
  21. if [[ "${status}" == "RUNNING" ]]; then
  22. echo_info "${APP_NAME} 启动成功"
  23. supervisorctl status "${APP_NAME}"
  24. else
  25. echo_error "${APP_NAME} 启动失败,状态: ${status}"
  26. echo_info "查看日志: tail -f ${SUPERVISOR_LOG}"
  27. exit 1
  28. fi
  29. }
  30. main() {
  31. echo "=========================================="
  32. echo " DataOps Platform 启动脚本"
  33. echo "=========================================="
  34. if [[ "${EUID}" -ne 0 ]]; then
  35. echo_error "请使用 sudo 运行此脚本"
  36. exit 1
  37. fi
  38. check_env_file
  39. load_env_file
  40. check_venv
  41. check_run_script
  42. check_supervisor
  43. start_app
  44. if ! health_check; then
  45. echo_error "启动完成但服务未就绪,请查看上方诊断日志"
  46. exit 1
  47. fi
  48. local app_port
  49. app_port="$(resolve_listen_port)"
  50. echo ""
  51. echo_info "启动完成"
  52. echo_info "访问: http://127.0.0.1:${app_port}/api/system/health"
  53. }
  54. main "$@"