#!/bin/bash
# Stop Qwen3-VL server

PID_FILE="/tmp/qwen3vl.pid"

if [ -f "$PID_FILE" ]; then
    PID=$(cat "$PID_FILE")
    if ps -p "$PID" > /dev/null 2>&1; then
        kill "$PID"
        sleep 2
        if ps -p "$PID" > /dev/null 2>&1; then
            kill -9 "$PID"
        fi
        echo "Qwen3-VL stopped (PID: $PID)"
    else
        echo "Process already stopped (PID: $PID)"
    fi
    rm "$PID_FILE"
else
    echo "No PID file found at $PID_FILE"
    echo "Searching for running process..."
    RUNNING_PID=$(ps aux | grep "Qwen3VL-8B" | grep -v grep | awk '{print $2}')
    if [ -n "$RUNNING_PID" ]; then
        echo "Found running process (PID: $RUNNING_PID)"
        kill "$RUNNING_PID"
        echo "Process killed"
    else
        echo "No running process found"
    fi
fi