You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

launch_backend_service.sh 2.7KB

Change launch backend script to handle errors gracefully (#3334) ### What problem does this PR solve? The `launch_backend_service.sh` script enters infinite loops for both the task executors and the backend server. When an error occurs in any of these processes, the script continuously restarts them without properly handling termination signals. This behavior causes the script to even ignore interrupts, leading to persistent error messages and making it difficult to exit the script gracefully. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) ### Explanation of Modifications 1. **Signal Trapping with `trap`:** - The `trap cleanup SIGINT SIGTERM` line ensures that when a `SIGINT` or `SIGTERM` signal is received, the cleanup function is invoked. - The `cleanup` function sets the `STOP` flag to `true`, iterates through all child process IDs stored in the `PIDS` array, and sends a `kill` signal to each process to terminate them gracefully. 2. **Retry Limits:** - Introduced a `MAX_RETRIES` variable to limit the number of restart attempts for both `task_executor.py` and `ragflow_server.py` - The loops now check if the retry count has reached the maximum limit. If so, they invoke the `cleanup` function to terminate all processes and exit the script. 3. **Process Tracking with `PIDS` Array:** - After launching each background process (`task_exe` and `run_server`), their Process IDs (PIDs) are stored in the `PIDS` array. - This allows the `cleanup` function to terminate all child processes effectively when needed. 4. **Graceful Shutdown:** - When the `cleanup` function is called, it iterates over all child PIDs and sends a termination signal (`kill`) to each, ensuring that all subprocesses are stopped before the script exits. 5. **Logging Enhancements:** - Added `echo` statements to provide clearer logs about the state of each process, including attempts, successes, failures, and retries. 6. **Exit on Successful Completion:** - If `ragflow_server.py` or a `task_executor.py` process exits with a success code (0), the loop breaks, preventing unnecessary retries. Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
11 月之前
Change launch backend script to handle errors gracefully (#3334) ### What problem does this PR solve? The `launch_backend_service.sh` script enters infinite loops for both the task executors and the backend server. When an error occurs in any of these processes, the script continuously restarts them without properly handling termination signals. This behavior causes the script to even ignore interrupts, leading to persistent error messages and making it difficult to exit the script gracefully. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) ### Explanation of Modifications 1. **Signal Trapping with `trap`:** - The `trap cleanup SIGINT SIGTERM` line ensures that when a `SIGINT` or `SIGTERM` signal is received, the cleanup function is invoked. - The `cleanup` function sets the `STOP` flag to `true`, iterates through all child process IDs stored in the `PIDS` array, and sends a `kill` signal to each process to terminate them gracefully. 2. **Retry Limits:** - Introduced a `MAX_RETRIES` variable to limit the number of restart attempts for both `task_executor.py` and `ragflow_server.py` - The loops now check if the retry count has reached the maximum limit. If so, they invoke the `cleanup` function to terminate all processes and exit the script. 3. **Process Tracking with `PIDS` Array:** - After launching each background process (`task_exe` and `run_server`), their Process IDs (PIDs) are stored in the `PIDS` array. - This allows the `cleanup` function to terminate all child processes effectively when needed. 4. **Graceful Shutdown:** - When the `cleanup` function is called, it iterates over all child PIDs and sends a termination signal (`kill`) to each, ensuring that all subprocesses are stopped before the script exits. 5. **Logging Enhancements:** - Added `echo` statements to provide clearer logs about the state of each process, including attempts, successes, failures, and retries. 6. **Exit on Successful Completion:** - If `ragflow_server.py` or a `task_executor.py` process exits with a success code (0), the loop breaks, preventing unnecessary retries. Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
11 月之前
Change launch backend script to handle errors gracefully (#3334) ### What problem does this PR solve? The `launch_backend_service.sh` script enters infinite loops for both the task executors and the backend server. When an error occurs in any of these processes, the script continuously restarts them without properly handling termination signals. This behavior causes the script to even ignore interrupts, leading to persistent error messages and making it difficult to exit the script gracefully. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) ### Explanation of Modifications 1. **Signal Trapping with `trap`:** - The `trap cleanup SIGINT SIGTERM` line ensures that when a `SIGINT` or `SIGTERM` signal is received, the cleanup function is invoked. - The `cleanup` function sets the `STOP` flag to `true`, iterates through all child process IDs stored in the `PIDS` array, and sends a `kill` signal to each process to terminate them gracefully. 2. **Retry Limits:** - Introduced a `MAX_RETRIES` variable to limit the number of restart attempts for both `task_executor.py` and `ragflow_server.py` - The loops now check if the retry count has reached the maximum limit. If so, they invoke the `cleanup` function to terminate all processes and exit the script. 3. **Process Tracking with `PIDS` Array:** - After launching each background process (`task_exe` and `run_server`), their Process IDs (PIDs) are stored in the `PIDS` array. - This allows the `cleanup` function to terminate all child processes effectively when needed. 4. **Graceful Shutdown:** - When the `cleanup` function is called, it iterates over all child PIDs and sends a termination signal (`kill`) to each, ensuring that all subprocesses are stopped before the script exits. 5. **Logging Enhancements:** - Added `echo` statements to provide clearer logs about the state of each process, including attempts, successes, failures, and retries. 6. **Exit on Successful Completion:** - If `ragflow_server.py` or a `task_executor.py` process exits with a success code (0), the loop breaks, preventing unnecessary retries. Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
11 月之前
Change launch backend script to handle errors gracefully (#3334) ### What problem does this PR solve? The `launch_backend_service.sh` script enters infinite loops for both the task executors and the backend server. When an error occurs in any of these processes, the script continuously restarts them without properly handling termination signals. This behavior causes the script to even ignore interrupts, leading to persistent error messages and making it difficult to exit the script gracefully. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) ### Explanation of Modifications 1. **Signal Trapping with `trap`:** - The `trap cleanup SIGINT SIGTERM` line ensures that when a `SIGINT` or `SIGTERM` signal is received, the cleanup function is invoked. - The `cleanup` function sets the `STOP` flag to `true`, iterates through all child process IDs stored in the `PIDS` array, and sends a `kill` signal to each process to terminate them gracefully. 2. **Retry Limits:** - Introduced a `MAX_RETRIES` variable to limit the number of restart attempts for both `task_executor.py` and `ragflow_server.py` - The loops now check if the retry count has reached the maximum limit. If so, they invoke the `cleanup` function to terminate all processes and exit the script. 3. **Process Tracking with `PIDS` Array:** - After launching each background process (`task_exe` and `run_server`), their Process IDs (PIDs) are stored in the `PIDS` array. - This allows the `cleanup` function to terminate all child processes effectively when needed. 4. **Graceful Shutdown:** - When the `cleanup` function is called, it iterates over all child PIDs and sends a termination signal (`kill`) to each, ensuring that all subprocesses are stopped before the script exits. 5. **Logging Enhancements:** - Added `echo` statements to provide clearer logs about the state of each process, including attempts, successes, failures, and retries. 6. **Exit on Successful Completion:** - If `ragflow_server.py` or a `task_executor.py` process exits with a success code (0), the loop breaks, preventing unnecessary retries. Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
11 月之前
Change launch backend script to handle errors gracefully (#3334) ### What problem does this PR solve? The `launch_backend_service.sh` script enters infinite loops for both the task executors and the backend server. When an error occurs in any of these processes, the script continuously restarts them without properly handling termination signals. This behavior causes the script to even ignore interrupts, leading to persistent error messages and making it difficult to exit the script gracefully. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) ### Explanation of Modifications 1. **Signal Trapping with `trap`:** - The `trap cleanup SIGINT SIGTERM` line ensures that when a `SIGINT` or `SIGTERM` signal is received, the cleanup function is invoked. - The `cleanup` function sets the `STOP` flag to `true`, iterates through all child process IDs stored in the `PIDS` array, and sends a `kill` signal to each process to terminate them gracefully. 2. **Retry Limits:** - Introduced a `MAX_RETRIES` variable to limit the number of restart attempts for both `task_executor.py` and `ragflow_server.py` - The loops now check if the retry count has reached the maximum limit. If so, they invoke the `cleanup` function to terminate all processes and exit the script. 3. **Process Tracking with `PIDS` Array:** - After launching each background process (`task_exe` and `run_server`), their Process IDs (PIDs) are stored in the `PIDS` array. - This allows the `cleanup` function to terminate all child processes effectively when needed. 4. **Graceful Shutdown:** - When the `cleanup` function is called, it iterates over all child PIDs and sends a termination signal (`kill`) to each, ensuring that all subprocesses are stopped before the script exits. 5. **Logging Enhancements:** - Added `echo` statements to provide clearer logs about the state of each process, including attempts, successes, failures, and retries. 6. **Exit on Successful Completion:** - If `ragflow_server.py` or a `task_executor.py` process exits with a success code (0), the loop breaks, preventing unnecessary retries. Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
11 月之前
Change launch backend script to handle errors gracefully (#3334) ### What problem does this PR solve? The `launch_backend_service.sh` script enters infinite loops for both the task executors and the backend server. When an error occurs in any of these processes, the script continuously restarts them without properly handling termination signals. This behavior causes the script to even ignore interrupts, leading to persistent error messages and making it difficult to exit the script gracefully. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) ### Explanation of Modifications 1. **Signal Trapping with `trap`:** - The `trap cleanup SIGINT SIGTERM` line ensures that when a `SIGINT` or `SIGTERM` signal is received, the cleanup function is invoked. - The `cleanup` function sets the `STOP` flag to `true`, iterates through all child process IDs stored in the `PIDS` array, and sends a `kill` signal to each process to terminate them gracefully. 2. **Retry Limits:** - Introduced a `MAX_RETRIES` variable to limit the number of restart attempts for both `task_executor.py` and `ragflow_server.py` - The loops now check if the retry count has reached the maximum limit. If so, they invoke the `cleanup` function to terminate all processes and exit the script. 3. **Process Tracking with `PIDS` Array:** - After launching each background process (`task_exe` and `run_server`), their Process IDs (PIDs) are stored in the `PIDS` array. - This allows the `cleanup` function to terminate all child processes effectively when needed. 4. **Graceful Shutdown:** - When the `cleanup` function is called, it iterates over all child PIDs and sends a termination signal (`kill`) to each, ensuring that all subprocesses are stopped before the script exits. 5. **Logging Enhancements:** - Added `echo` statements to provide clearer logs about the state of each process, including attempts, successes, failures, and retries. 6. **Exit on Successful Completion:** - If `ragflow_server.py` or a `task_executor.py` process exits with a success code (0), the loop breaks, preventing unnecessary retries. Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
11 月之前
Change launch backend script to handle errors gracefully (#3334) ### What problem does this PR solve? The `launch_backend_service.sh` script enters infinite loops for both the task executors and the backend server. When an error occurs in any of these processes, the script continuously restarts them without properly handling termination signals. This behavior causes the script to even ignore interrupts, leading to persistent error messages and making it difficult to exit the script gracefully. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) ### Explanation of Modifications 1. **Signal Trapping with `trap`:** - The `trap cleanup SIGINT SIGTERM` line ensures that when a `SIGINT` or `SIGTERM` signal is received, the cleanup function is invoked. - The `cleanup` function sets the `STOP` flag to `true`, iterates through all child process IDs stored in the `PIDS` array, and sends a `kill` signal to each process to terminate them gracefully. 2. **Retry Limits:** - Introduced a `MAX_RETRIES` variable to limit the number of restart attempts for both `task_executor.py` and `ragflow_server.py` - The loops now check if the retry count has reached the maximum limit. If so, they invoke the `cleanup` function to terminate all processes and exit the script. 3. **Process Tracking with `PIDS` Array:** - After launching each background process (`task_exe` and `run_server`), their Process IDs (PIDs) are stored in the `PIDS` array. - This allows the `cleanup` function to terminate all child processes effectively when needed. 4. **Graceful Shutdown:** - When the `cleanup` function is called, it iterates over all child PIDs and sends a termination signal (`kill`) to each, ensuring that all subprocesses are stopped before the script exits. 5. **Logging Enhancements:** - Added `echo` statements to provide clearer logs about the state of each process, including attempts, successes, failures, and retries. 6. **Exit on Successful Completion:** - If `ragflow_server.py` or a `task_executor.py` process exits with a success code (0), the loop breaks, preventing unnecessary retries. Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
11 月之前
Change launch backend script to handle errors gracefully (#3334) ### What problem does this PR solve? The `launch_backend_service.sh` script enters infinite loops for both the task executors and the backend server. When an error occurs in any of these processes, the script continuously restarts them without properly handling termination signals. This behavior causes the script to even ignore interrupts, leading to persistent error messages and making it difficult to exit the script gracefully. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) ### Explanation of Modifications 1. **Signal Trapping with `trap`:** - The `trap cleanup SIGINT SIGTERM` line ensures that when a `SIGINT` or `SIGTERM` signal is received, the cleanup function is invoked. - The `cleanup` function sets the `STOP` flag to `true`, iterates through all child process IDs stored in the `PIDS` array, and sends a `kill` signal to each process to terminate them gracefully. 2. **Retry Limits:** - Introduced a `MAX_RETRIES` variable to limit the number of restart attempts for both `task_executor.py` and `ragflow_server.py` - The loops now check if the retry count has reached the maximum limit. If so, they invoke the `cleanup` function to terminate all processes and exit the script. 3. **Process Tracking with `PIDS` Array:** - After launching each background process (`task_exe` and `run_server`), their Process IDs (PIDs) are stored in the `PIDS` array. - This allows the `cleanup` function to terminate all child processes effectively when needed. 4. **Graceful Shutdown:** - When the `cleanup` function is called, it iterates over all child PIDs and sends a termination signal (`kill`) to each, ensuring that all subprocesses are stopped before the script exits. 5. **Logging Enhancements:** - Added `echo` statements to provide clearer logs about the state of each process, including attempts, successes, failures, and retries. 6. **Exit on Successful Completion:** - If `ragflow_server.py` or a `task_executor.py` process exits with a success code (0), the loop breaks, preventing unnecessary retries. Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
11 月之前
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