redpanda / start.sh
Subham9126's picture
Upload 5 files
30ea1a1 verified
Raw
History Blame Contribute Delete
2.77 kB
#!/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