commit e8a23f2b11b3fb72ec66dc5dbd135cb48d519a9a Author: Claude Code Date: Sat Mar 28 18:58:03 2026 -0400 feat: gateway management scripts (start, stop, status) diff --git a/.env b/.env new file mode 120000 index 0000000..1b735f0 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +../Mortdecai-2.0/.env \ No newline at end of file diff --git a/scripts/start-gateway.sh b/scripts/start-gateway.sh new file mode 100755 index 0000000..78c5cfb --- /dev/null +++ b/scripts/start-gateway.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# Start the Mortdecai gateway (uvicorn on port 8500) +set -e + +GATEWAY_DIR="$HOME/bin/Mortdecai-2.0" +PID_FILE="/tmp/mortdecai-gateway.pid" +LOG_FILE="/tmp/mortdecai-gateway.log" + +# Check if already running +if [ -f "$PID_FILE" ] && kill -0 "$(cat "$PID_FILE")" 2>/dev/null; then + echo "Gateway already running (PID $(cat "$PID_FILE"))" + exit 0 +fi + +cd "$GATEWAY_DIR" +source .env 2>/dev/null + +nohup python3 -m uvicorn gateway.api:app --host 0.0.0.0 --port 8500 > "$LOG_FILE" 2>&1 & +echo $! > "$PID_FILE" + +# Wait for health +for i in $(seq 1 10); do + if curl -sf http://localhost:8500/v2/health > /dev/null 2>&1; then + echo "Gateway started (PID $(cat "$PID_FILE"))" + exit 0 + fi + sleep 1 +done + +echo "ERROR: Gateway failed to start within 10s. Check $LOG_FILE" +exit 1 diff --git a/scripts/status.sh b/scripts/status.sh new file mode 100755 index 0000000..2c0ec55 --- /dev/null +++ b/scripts/status.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# Check Mortdecai gateway status +echo "=== Gateway ===" +STATUS=$(curl -sf http://localhost:8500/v2/status 2>/dev/null) +if [ -n "$STATUS" ]; then + echo "$STATUS" | python3 -m json.tool 2>/dev/null || echo "$STATUS" +else + echo "DOWN — gateway not reachable on port 8500" +fi + +echo "" +echo "=== Process ===" +pgrep -f "uvicorn gateway.api" -a 2>/dev/null || echo "Not running" + +echo "" +echo "=== Recent Logs (errors only) ===" +grep -i "error\|warning\|traceback" /tmp/mortdecai-gateway.log 2>/dev/null | tail -5 || echo "No log file" diff --git a/scripts/stop-gateway.sh b/scripts/stop-gateway.sh new file mode 100755 index 0000000..25713fb --- /dev/null +++ b/scripts/stop-gateway.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# Stop the Mortdecai gateway +PID_FILE="/tmp/mortdecai-gateway.pid" + +if [ -f "$PID_FILE" ]; then + PID=$(cat "$PID_FILE") + if kill -0 "$PID" 2>/dev/null; then + kill "$PID" + echo "Gateway stopped (PID $PID)" + else + echo "Gateway not running (stale PID file)" + fi + rm -f "$PID_FILE" +else + # Fallback: find by process name + PID=$(pgrep -f "uvicorn gateway.api" 2>/dev/null | head -1) + if [ -n "$PID" ]; then + kill "$PID" + echo "Gateway stopped (PID $PID)" + else + echo "Gateway not running" + fi +fi