|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -ex |
| 3 | + |
| 4 | +if [[ -z "$KAFKA_HOST" ]]; then |
| 5 | + KAFKA_HOST=127.0.0.1 |
| 6 | +fi |
| 7 | + |
| 8 | +if [[ -z "$KAFKA_PORT" ]]; then |
| 9 | + KAFKA_PORT=9092 |
| 10 | +fi |
| 11 | + |
| 12 | +KAFKA_BROKER="${KAFKA_HOST}:${KAFKA_PORT}" |
| 13 | + |
| 14 | +echo "[setup] Kafka broker: $KAFKA_BROKER" |
| 15 | + |
| 16 | +echo "[setup] Waiting for Kafka broker..." |
| 17 | +until nc -z "$KAFKA_HOST" "$KAFKA_PORT"; do |
| 18 | + echo "[setup] Kafka not ready, retrying in 2s..." |
| 19 | + sleep 2 |
| 20 | +done |
| 21 | +echo "[setup] Kafka is ready!" |
| 22 | +echo |
| 23 | + |
| 24 | + |
| 25 | +if [[ -n "$TOPICS_TO_CREATE" ]]; then |
| 26 | + echo "[setup] Topics to create: $topic" |
| 27 | + echo |
| 28 | + common_opts="--create --if-not-exists --bootstrap-server $KAFKA_BROKER --partitions 1 --replication-factor 1" |
| 29 | + if [[ -n "$JAAS_CONFIG" ]]; then |
| 30 | + common_opts="$common_opts --command-config $JAAS_CONFIG" |
| 31 | + fi |
| 32 | + for topic in $TOPICS_TO_CREATE; do |
| 33 | + echo "[setup] Creating topic: $topic" |
| 34 | + kafka-topics.sh \ |
| 35 | + $common_opts \ |
| 36 | + --topic "$topic" \ |
| 37 | + echo "[setup] Topic '$topic' created (or already exists)." |
| 38 | + echo |
| 39 | + done |
| 40 | +fi |
| 41 | + |
| 42 | +if [[ "$CREATE_NOTIFICATION_PATHS" == "true" ]]; then |
| 43 | + if [[ -z "$ZOOKEEPER_ENDPOINT" ]]; then |
| 44 | + echo "[setup] Zookeeper endpoint not set" |
| 45 | + exit 1 |
| 46 | + fi |
| 47 | + |
| 48 | + echo "[setup] Creating Zookeeper paths..." |
| 49 | + zookeeper-shell.sh localhost:2181/backbeat <<EOF |
| 50 | +create / |
| 51 | +create /bucket-notification |
| 52 | +create /bucket-notification/raft-id-dispatcher |
| 53 | +create /bucket-notification/raft-id-dispatcher/owners |
| 54 | +create /bucket-notification/raft-id-dispatcher/leaders |
| 55 | +create /bucket-notification/raft-id-dispatcher/provisions |
| 56 | +create /bucket-notification/raft-id-dispatcher/provisions/1 |
| 57 | +create /bucket-notification/raft-id-dispatcher/provisions/2 |
| 58 | +create /bucket-notification/raft-id-dispatcher/provisions/3 |
| 59 | +quit |
| 60 | +EOF |
| 61 | + echo "[setup] Zookeeper paths created." |
| 62 | + echo |
| 63 | +fi |
0 commit comments