#!/bin/bash # # Stop Reranker Service # set -e cd "$(dirname "$0")/.." PID_FILE="logs/reranker.pid" RERANKER_PORT="${RERANKER_PORT:-6007}" echo "========================================" echo "Stopping Reranker Service" echo "========================================" if [ -f "${PID_FILE}" ]; then PID="$(cat "${PID_FILE}" 2>/dev/null || true)" if [ -n "${PID}" ] && kill -0 "${PID}" 2>/dev/null; then echo "Stopping PID from file: ${PID}" kill -TERM "${PID}" 2>/dev/null || true sleep 1 if kill -0 "${PID}" 2>/dev/null; then kill -KILL "${PID}" 2>/dev/null || true fi fi rm -f "${PID_FILE}" fi PORT_PIDS="$(lsof -ti:${RERANKER_PORT} 2>/dev/null || true)" if [ -n "${PORT_PIDS}" ]; then echo "Stopping process on port ${RERANKER_PORT}: ${PORT_PIDS}" for PID in ${PORT_PIDS}; do kill -TERM "${PID}" 2>/dev/null || true done sleep 1 PORT_PIDS="$(lsof -ti:${RERANKER_PORT} 2>/dev/null || true)" for PID in ${PORT_PIDS}; do kill -KILL "${PID}" 2>/dev/null || true done fi # Cleanup orphaned vLLM engine workers that may survive a failed startup. ENGINE_PIDS="$(pgrep -f 'VLLM::EngineCore' 2>/dev/null || true)" if [ -n "${ENGINE_PIDS}" ]; then echo "Stopping orphaned vLLM engine processes: ${ENGINE_PIDS}" for PID in ${ENGINE_PIDS}; do kill -TERM "${PID}" 2>/dev/null || true done sleep 1 ENGINE_PIDS="$(pgrep -f 'VLLM::EngineCore' 2>/dev/null || true)" for PID in ${ENGINE_PIDS}; do kill -KILL "${PID}" 2>/dev/null || true done fi echo "Reranker service stopped."