#!/bin/bash
set -e
echo "Starting all containers..."
podman-compose up -d
echo ""
echo "Containers starting... This may take 1-2 minutes for all services to be ready."
echo "Services have restart policies and will automatically retry on failure."
echo ""
echo "To check status: podman ps"
echo "To view logs: podman logs debezium-cdc-fun_<service>_1"
echo ""
echo "Waiting 90 seconds for services to stabilize..."
sleep 90
echo ""
echo "Checking service health..."
echo -n "Postgres: "
podman exec debezium-cdc-fun-postgres-1 pg_isready -U postgres || echo "Not ready yet"
echo -n "Kafka: "
podman logs debezium-cdc-fun_kafka_1 2>&1 | grep -q "started (kafka.server.KafkaServer)" && echo "Ready" || echo "Not ready yet - checking restart count..."
echo -n "Debezium Connect: "
curl -s http://localhost:8083/ > /dev/null && echo "Ready" || echo "Not ready yet"
echo -n "Java App: "
curl -s http://localhost:8080/getdata > /dev/null && echo "Ready" || echo "Not ready yet"
echo ""
echo "If services are not ready, wait another minute and check logs."
echo ""
echo "When Debezium Connect is ready, register the connector with:"
echo "curl -i -X POST -H \"Content-Type: application/json\" --data @debezium-connector.json http://localhost:8083/connectors"
echo ""
echo "Endpoints:"
echo "  Java app: http://localhost:8080"
echo "  Debezium Connect: http://localhost:8083"
echo "  PostgreSQL: localhost:5432"
