Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

launch_backend_service.sh 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/bin/bash
  2. # Exit immediately if a command exits with a non-zero status
  3. set -e
  4. # Unset HTTP proxies that might be set by Docker daemon
  5. export http_proxy=""; export https_proxy=""; export no_proxy=""; export HTTP_PROXY=""; export HTTPS_PROXY=""; export NO_PROXY=""
  6. export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/
  7. PY=python3
  8. # Set default number of workers if WS is not set or less than 1
  9. if [[ -z "$WS" || $WS -lt 1 ]]; then
  10. WS=1
  11. fi
  12. # Maximum number of retries for each task executor and server
  13. MAX_RETRIES=5
  14. # Flag to control termination
  15. STOP=false
  16. # Array to keep track of child PIDs
  17. PIDS=()
  18. # Function to handle termination signals
  19. cleanup() {
  20. echo "Termination signal received. Shutting down..."
  21. STOP=true
  22. # Terminate all child processes
  23. for pid in "${PIDS[@]}"; do
  24. if kill -0 "$pid" 2>/dev/null; then
  25. echo "Killing process $pid"
  26. kill "$pid"
  27. fi
  28. done
  29. exit 0
  30. }
  31. # Trap SIGINT and SIGTERM to invoke cleanup
  32. trap cleanup SIGINT SIGTERM
  33. # Function to execute task_executor with retry logic
  34. task_exe(){
  35. local task_id=$1
  36. local retry_count=0
  37. while ! $STOP && [ $retry_count -lt $MAX_RETRIES ]; do
  38. echo "Starting task_executor.py for task $task_id (Attempt $((retry_count+1)))"
  39. $PY rag/svr/task_executor.py "$task_id"
  40. EXIT_CODE=$?
  41. if [ $EXIT_CODE -eq 0 ]; then
  42. echo "task_executor.py for task $task_id exited successfully."
  43. break
  44. else
  45. echo "task_executor.py for task $task_id failed with exit code $EXIT_CODE. Retrying..." >&2
  46. retry_count=$((retry_count + 1))
  47. sleep 2
  48. fi
  49. done
  50. if [ $retry_count -ge $MAX_RETRIES ]; then
  51. echo "task_executor.py for task $task_id failed after $MAX_RETRIES attempts. Exiting..." >&2
  52. cleanup
  53. fi
  54. }
  55. # Function to execute ragflow_server with retry logic
  56. run_server(){
  57. local retry_count=0
  58. while ! $STOP && [ $retry_count -lt $MAX_RETRIES ]; do
  59. echo "Starting ragflow_server.py (Attempt $((retry_count+1)))"
  60. $PY api/ragflow_server.py
  61. EXIT_CODE=$?
  62. if [ $EXIT_CODE -eq 0 ]; then
  63. echo "ragflow_server.py exited successfully."
  64. break
  65. else
  66. echo "ragflow_server.py failed with exit code $EXIT_CODE. Retrying..." >&2
  67. retry_count=$((retry_count + 1))
  68. sleep 2
  69. fi
  70. done
  71. if [ $retry_count -ge $MAX_RETRIES ]; then
  72. echo "ragflow_server.py failed after $MAX_RETRIES attempts. Exiting..." >&2
  73. cleanup
  74. fi
  75. }
  76. # Start task executors
  77. for ((i=0;i<WS;i++))
  78. do
  79. task_exe "$i" &
  80. PIDS+=($!)
  81. done
  82. # Start the main server
  83. run_server &
  84. PIDS+=($!)
  85. # Wait for all background processes to finish
  86. wait