#!/bin/bash set -euo pipefail echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo " Redpanda → HF Spaces" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" # ── 1. Start Redpanda ───────────────────────────────────────────────────────── echo "[1/4] Starting Redpanda..." /usr/bin/redpanda --redpanda-cfg /etc/redpanda/redpanda.yaml --smp 1 --memory 512M --reserve-memory 0M & REDPANDA_PID=$! # ── 2. Wait for broker ready ────────────────────────────────────────────────── echo "[2/4] Waiting for Redpanda..." ATTEMPTS=0 until curl -sf http://127.0.0.1:9644/v1/status/ready > /dev/null 2>&1; do ATTEMPTS=$((ATTEMPTS+1)) if [ $ATTEMPTS -gt 60 ]; then echo "ERROR: Redpanda failed to start after 120s" kill $REDPANDA_PID 2>/dev/null || true exit 1 fi echo " ... waiting (${ATTEMPTS}/60)" sleep 2 done echo " ✓ Redpanda ready" # ── 3. Create topics ────────────────────────────────────────────────────────── echo "[3/4] Initializing topics..." /init-topics.sh # ── 4. Start nginx on :7860 ─────────────────────────────────────────────────── echo "[4/4] Starting nginx on :7860..." # Debian nginx binary lives at /usr/sbin/nginx # pid to /tmp — writable by uid 1000 /usr/sbin/nginx -g "daemon off;" & NGINX_PID=$! echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo " ✅ All services up on port 7860" echo "" echo " GET /health → broker ready check" echo " * /kafka/... → HTTP REST proxy (pandaproxy)" echo " * /admin/... → admin API" echo " * /schema/... → schema registry" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" # ── Graceful shutdown ───────────────────────────────────────────────────────── cleanup() { echo "Shutting down..." kill $NGINX_PID 2>/dev/null || true kill $REDPANDA_PID 2>/dev/null || true exit 0 } trap cleanup SIGTERM SIGINT wait $REDPANDA_PID