stop_stress.sh 926 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/bin/bash
  2. # Gracefully stop 24-PTC stress test and drive all PTC to 0%
  3. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  4. PID_FILE="${SCRIPT_DIR}/stress.pid"
  5. if [ -f "${PID_FILE}" ]; then
  6. PID=$(cat "${PID_FILE}")
  7. else
  8. PID=$(pgrep -f "stress_test_35ptc_24h.py")
  9. fi
  10. if [ -z "${PID}" ] || ! ps -p "${PID}" > /dev/null 2>&1; then
  11. echo "[INFO] No running stress test found."
  12. rm -f "${PID_FILE}"
  13. exit 0
  14. fi
  15. echo "[INFO] Sending SIGTERM to PID ${PID} to trigger safe shutdown (PTC 0%)..."
  16. kill -TERM "${PID}"
  17. # Wait up to 10 seconds for graceful shutdown
  18. for i in $(seq 1 10); do
  19. if ! ps -p "${PID}" > /dev/null 2>&1; then
  20. echo "[OK] Stress test process ${PID} terminated gracefully."
  21. rm -f "${PID_FILE}"
  22. exit 0
  23. fi
  24. sleep 1
  25. done
  26. echo "[WARNING] Process did not terminate within 10s, forcing kill..."
  27. kill -9 "${PID}" 2>/dev/null
  28. rm -f "${PID_FILE}"
  29. echo "[DONE]"