-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrunKafka.sh
executable file
·38 lines (31 loc) · 1.27 KB
/
runKafka.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
#!/usr/bin/env bash
source ./globals.sh
function pullAndStartKafkaDocker {
# Pulling image and running container
docker_image_uri="apache/kafka:$KAFKA_VERSION"
echo "Pulling Kafka Docker image: $docker_image_uri"
docker pull -q $docker_image_uri
echo "Creating and starting Kafka Docker container from image ..."
docker_container_id=$(docker run --name "$KAFKA_DOCKER_CONTAINER_NAME" -dq -p $KAFKA_PORT:$KAFKA_PORT $docker_image_uri)
echo "Created and running Kafka Docker Instance. Container Name: $KAFKA_DOCKER_CONTAINER_NAME"
# Saving container ID to file
storeKafkaContainerId "$docker_container_id"
echo "Kafka Docker container running on port $KAFKA_PORT: $docker_container_id"
}
function main {
if ! $(checkKafkaContainerExists); then
# No container by that name exists
# Removing the existing ID file
rm -f $KAFKA_DOCKER_ID_FILE
# Pulling and starting fresh
pullAndStartKafkaDocker
elif ! $(checkKafkaContainerRunning); then
# Docker container exists but not running. Starting instance
echo "Starting Kafka Docker container. Name: $KAFKA_DOCKER_CONTAINER_NAME"
startKafkaContainer
else
# Docker container is running. Do nothing
echo "Kafka Docker container is already running: $KAFKA_DOCKER_CONTAINER_NAME";
fi
}
main