| 12345678910111213141516171819202122232425262728293031 |
- #!/usr/bin/env bash
- set -euo pipefail
- PIDFILE=${PIDFILE:-server.pid}
- stop_pid() {
- local pid="$1"
- if [ -n "$pid" ] && ps -p "$pid" > /dev/null 2>&1; then
- kill "$pid" 2>/dev/null || true
- sleep 1
- if ps -p "$pid" > /dev/null 2>&1; then
- kill -9 "$pid" 2>/dev/null || true
- fi
- echo "Stopped stale process $pid"
- fi
- }
- if [ -f "$PIDFILE" ]; then
- PID=$(cat "$PIDFILE" 2>/dev/null || true)
- stop_pid "$PID"
- rm -f "$PIDFILE"
- fi
- # Sweep up any stale listeners started from this project.
- PIDS=$(pgrep -f 'uvicorn .*main:app|python.*server.py|uvicorn .*server:app' || true)
- if [ -n "$PIDS" ]; then
- for pid in $PIDS; do
- stop_pid "$pid"
- done
- else
- echo "No stale processes found"
- fi
|