#!/bin/bash
# Flask App Status Script
# Shows current status of the Jadwa AI Flask app

APP_PORT=5006
APP_DIR="/home/ashraffarid2010/jadwaai.com"

echo "=== Jadwa AI Flask App Status ==="
echo ""

# Check if process is running
if pgrep -f "gunicorn.*$APP_PORT" > /dev/null; then
    echo "✓ Process Status: RUNNING"
    echo "  PIDs: $(pgrep -f "gunicorn.*$APP_PORT" | tr '\n' ' ')"
else
    echo "✗ Process Status: NOT RUNNING"
fi

echo ""

# Check if app is responding
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:$APP_PORT/ --max-time 5)
if [ "$HTTP_CODE" = "200" ]; then
    echo "✓ HTTP Response: OK (HTTP $HTTP_CODE)"
else
    echo "✗ HTTP Response: FAIL (HTTP $HTTP_CODE)"
fi

echo ""

# Check recent logs
if [ -f "$APP_DIR/logs/monitor.log" ]; then
    echo "=== Latest Monitoring Log ==="
    tail -5 "$APP_DIR/logs/monitor.log"
fi

echo ""

# Check if nginx config exists
if [ -f "/etc/nginx/conf.d/00-jadwaai.com.conf" ]; then
    echo "✓ Nginx Config: Present"
else
    echo "✗ Nginx Config: Missing"
fi

echo ""
echo "=== End of Status Report ==="
