#!/bin/bash set -e # Record startup time (for dashboard) date -u +'%Y-%m-%d %H:%M UTC' > /app/last_startup.txt # If this is a factory rebuild (no marker), record it if [ ! -f /app/last_factory_rebuild.txt ]; then cp /app/last_startup.txt /app/last_factory_rebuild.txt fi # ── One‑time cleanup: remove old economic‑event notes (lines containing "Economic event:") # Safe even if the notes file doesn't exist yet. sed -i '/Economic event:/d' /app/notes.txt 2>/dev/null || true # Helper: run a command forever, restarting on any exit run_forever() { local name="$1" shift echo "Starting $name with auto-restart..." while true; do "$@" 2>&1 || true # redirect stderr to stdout so we see errors echo "[$name] Process exited. Restarting in 5 seconds..." sleep 5 done } # ── Launch all services ────────────────────────────────── echo "Starting arbitrage bot..." run_forever "arbitrage_bot" python arbitrage_launcher.py & echo "Starting PolyHub listener..." run_forever "polyhub_listener" python polyhub_listener.py & echo "Starting Hermes Agent..." run_forever "hermes_agent" python hermes_agent.py & # LLM-Wiki module – just ensure directory exists once (other scripts import it) python -c "from llm_wiki import ensure_wiki_dir; ensure_wiki_dir()" echo "Starting Balance Updater..." run_forever "balance_updater" python balance_updater.py & echo "Starting Daily Report..." run_forever "daily_report" python daily_report.py & echo "Starting Dry Run Simulator..." run_forever "dry_run_simulator" python dry_run_simulator.py & echo "Starting Wiki Cleanup daemon..." run_forever "wiki_cleanup" python wiki_cleanup.py & echo "Starting External Data daemon..." run_forever "external_data" python external_data_daemon.py & echo "Starting Git Backup daemon..." bash backup.sh & # ── Optional debug: uncomment the next line to check FMP_API_KEY length ── # python -c "import os; print('FMP key length:', len(os.getenv('FMP_API_KEY','')))" echo "Starting Web UI on port ${PORT:-7860}..." exec uvicorn web_ui:app --host 0.0.0.0 --port ${PORT:-7860}