#!/bin/bash
set -e

# Momentry Runtime Stop Script

echo "Stopping Momentry Runtime..."

PID_FILE="/Users/accusys/momentry_core_0.1/momentry_runtime/logs/momentry.pid"

if [ -f "$PID_FILE" ]; then
    PID=$(cat "$PID_FILE")
    if kill -0 "$PID" 2>/dev/null; then
        echo "Stopping API server (PID: $PID)..."
        kill "$PID"
        rm -f "$PID_FILE"
        echo "Momentry Runtime stopped."
    else
        echo "Process not running."
        rm -f "$PID_FILE"
    fi
else
    echo "PID file not found. Trying to find and kill momentry processes..."
    pkill -f "momentry server" || true
    echo "Momentry Runtime stopped."
fi
