Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

2.6 KB
Raw Blame
#!/usr/bin/env bash
#
# Boot the multinode ClickHouse smoke-test stack in the background.
# One ClickHouse server per logical cluster (data + ai_events + aux + ops + sessions + logs).
# This is opt-in tooling for verifying migration routing — `bin/start` is unaffected.
#

set -euo pipefail

SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
# Repo root is three levels up from tools/infra-scripts/clickhouse-multinode/.
cd "$SCRIPT_DIR/../../.."

COMPOSE_FILE="docker-compose.multinode-clickhouse.yml"
CH_SERVICES=(clickhouse-data clickhouse-ai-events clickhouse-aux clickhouse-ops clickhouse-sessions clickhouse-logs
    clickhouse-ingestion-events clickhouse-ingestion-small clickhouse-ingestion-medium)
SERVICES=(zookeeper kafka db redis7 "${CH_SERVICES[@]}")

case "${1:-up}" in
    up)
        docker compose -f "$COMPOSE_FILE" up -d "${SERVICES[@]}"
        echo
        echo "Multinode ClickHouse stack starting. Published ports:"
        echo "  clickhouse-data              localhost:9000 (HTTP 8123)"
        echo "  clickhouse-ai-events         localhost:9100 (HTTP 8124)"
        echo "  clickhouse-aux               localhost:9200 (HTTP 8125)"
        echo "  clickhouse-ops               localhost:9300 (HTTP 8126)"
        echo "  clickhouse-sessions          localhost:9400 (HTTP 8127)"
        echo "  clickhouse-logs              localhost:9500 (HTTP 8128)"
        echo "  clickhouse-ingestion-events  localhost:9600 (HTTP 8129)"
        echo "  clickhouse-ingestion-small   localhost:9700 (HTTP 8130)"
        echo "  clickhouse-ingestion-medium  localhost:9800 (HTTP 8131)"
        echo
        # Migrations run from the host shell but route by the hostnames in
        # system.clusters, so the host has to resolve every node.
        echo "Each node name must resolve on this host:"
        echo "  echo '127.0.0.1 ${CH_SERVICES[*]}' | sudo tee -a /etc/hosts"
        echo
        echo "To run migrations against this stack, set:"
        echo "  export MULTINODE_CLICKHOUSE=1"
        echo "  export CLICKHOUSE_HOST=localhost"
        echo "  export CLICKHOUSE_MIGRATIONS_HOST=localhost"
        echo "Then run: python manage.py migrate_clickhouse"
        echo
        echo "Or run the full smoke test: tools/infra-scripts/clickhouse-multinode/multinode-migration-smoke"
        ;;
    down)
        docker compose -f "$COMPOSE_FILE" down -v
        ;;
    logs)
        docker compose -f "$COMPOSE_FILE" logs -f "${@:2}"
        ;;
    ps)
        docker compose -f "$COMPOSE_FILE" ps
        ;;
    *)
        echo "Usage: $0 [up|down|logs|ps]" >&2
        exit 2
        ;;
esac