-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·50 lines (42 loc) · 1.42 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
BROKER_COUNT="${BROKER_COUNT:-3}"
BROKER_PREFIX="${BROKER_PREFIX:-server}"
IMAGE_NAME="${IMAGE_NAME:-ubuntu-kafka}"
NETWORK_NAME="${NETWORK_NAME:-my-kafka-cluster-net}"
OUTSIDE_DOMAIN_PREFIX="${OUTSIDE_DOMAIN_PREFIX:-mydomain.com}"
INTERNAL_PORT="${INTERNAL_PORT:-9092}"
EXTERNAL_PORT="${EXTERNAL_PORT:-8092}"
LOCALHOST_PORT="${LOCALHOST_PORT:-7092}"
IMAGE_NAME=ubuntu-kafka
networkExists=`docker network ls | grep $NETWORK_NAME`
if [[ ! -z "$networkExists" ]]
then
echo "Network $NETWORK_NAME already exists"
else
echo "Creating Network $NETWORK_NAME"
docker network create $NETWORK_NAME
fi
for ((i = 0; i < BROKER_COUNT; i++)); do
name="$BROKER_PREFIX-$i"
serverId=`docker ps -q -f "name=$name"`
if [[ ! -z $serverId ]]
then
echo "Stopping $name"
docker kill "$name"
fi
done
sleep 2
for ((i = 0; i < BROKER_COUNT; i++)); do
name="$BROKER_PREFIX-$i"
echo "Starting $name"
localhostport=$((LOCALHOST_PORT + i))
localhostportForward="-p$localhostport:$localhostport"
docker run -d --rm --name "$name" \
-e "KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=$BROKER_COUNT" \
-e "BROKER_PREFIX=$BROKER_PREFIX" -e "BROKER_ID=$i" \
-e "BROKER_COUNT=$BROKER_COUNT" \
-e "OUTSIDE_DOMAIN_PREFIX=$OUTSIDE_DOMAIN_PREFIX" \
-e "INTERNAL_PORT=$INTERNAL_PORT" \
-e "EXTERNAL_PORT=$EXTERNAL_PORT" \
-e "LOCALHOST_PORT=$LOCALHOST_PORT" \
$localhostportForward --network $NETWORK_NAME -t $IMAGE_NAME
done