#!/usr/bin/env bash # Restart the AMC server cleanly set -e PORT=7400 # Find and kill existing server PID=$(lsof -ti :$PORT 2>/dev/null || true) if [[ -n "$PID" ]]; then echo "Stopping AMC server (PID $PID)..." kill "$PID" 2>/dev/null || true sleep 1 fi # Start server in background echo "Starting AMC server on port $PORT..." cd "$(dirname "$0")/.." nohup python3 -m amc_server.server > /tmp/amc-server.log 2>&1 & # Wait for startup sleep 1 NEW_PID=$(lsof -ti :$PORT 2>/dev/null || true) if [[ -n "$NEW_PID" ]]; then echo "AMC server running (PID $NEW_PID)" else echo "Failed to start server. Check /tmp/amc-server.log" exit 1 fi