#!/bin/bash
# Legacy compatibility wrapper. Keep it read-only so cron/manual calls
# cannot revive `gold_trader.py --daemon` after the runtime moved to pipeline.

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
LOG="$ROOT/logs/gold_trader.health.log"
NOW=$(date "+%Y-%m-%d %H:%M:%S")

PIPELINE_PID=$(pgrep -f "src/pipeline.py --source ea_feed --runtime-intent live_trade" 2>/dev/null | /usr/bin/head -1)
MONITOR_PID=$(pgrep -f "gold_trader.py.*--monitor-only" 2>/dev/null | /usr/bin/head -1)

{
    echo "[$NOW] Health check"
    if [ -n "$PIPELINE_PID" ]; then
        echo "[$NOW] pipeline live_trade alive (PID=$PIPELINE_PID)"
    else
        echo "[$NOW] pipeline live_trade missing"
    fi
    if [ -n "$MONITOR_PID" ]; then
        echo "[$NOW] gold_trader monitor-only alive (PID=$MONITOR_PID)"
    else
        echo "[$NOW] gold_trader monitor-only missing"
    fi
    echo "[$NOW] legacy auto-restart disabled by design"
} >> "$LOG"
