#!/bin/bash
# 重启推荐服务

cd "$(dirname "$0")"

# 查找 recommendations_main 进程
PID=$(ps aux | grep "trading_system.recommendations_main" | grep -v grep | awk '{print $2}')

if [ -z "$PID" ]; then
    echo "未找到运行中的推荐服务，直接启动..."
    ./start_recommendations.sh
else
    echo "找到推荐服务，PID: $PID，正在重启..."
    kill $PID 2>/dev/null || true
    sleep 2
    if ps -p $PID > /dev/null 2>&1; then
        kill -9 $PID 2>/dev/null || true
        sleep 1
    fi
    echo "正在启动新服务..."
    ./start_recommendations.sh
fi
