forked from PandoraMedia/kbrowse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-zookeeper-and-kafka
executable file
·93 lines (72 loc) · 2.53 KB
/
run-zookeeper-and-kafka
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
#
# Copyright 2017-present Pandora Media, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Run a local Zookeeper/Kafka cluster, and insert some test data.
set -e -o pipefail
# Shutdown child processes on exit.
ZOOKEEPER_PID=''
KAFKA_SERVER_PID=''
function _stop {
EXITING_CODE=$?
if [ $EXITING_CODE != 0 ]; then
echo
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
echo Error in run-zookeeper-and-kafka
echo
fi
echo
if [ ! -z "$ZOOKEEPER_PID" ]; then
echo Stopping Zookeeper
kill -9 $ZOOKEEPER_PID
fi
if [ ! -z "$KAFKA_SERVER_PID" ]; then
echo Stopping Kafka Server
kill -9 $KAFKA_SERVER_PID
fi
exit $EXITING_CODE
}
trap _stop SIGINT SIGKILL SIGTERM TERM
# Fetch binaries and reset data
./fetch-kafka-tgz
rm -rf kafka/kafka_2*/ kafka-logs zookeeper
tar xf kafka*.tgz
mv kafka_2*/ kafka
ZOOKEEPER_CONFIG=kafka/config/zookeeper-kbrowse.properties
sed -e 's|dataDir=/tmp/zookeeper|dataDir=zookeeper|' \
kafka/config/zookeeper.properties > $ZOOKEEPER_CONFIG
echo Starting Zookeeper
./kafka/bin/zookeeper-server-start.sh $ZOOKEEPER_CONFIG > /dev/null &
ZOOKEEPER_PID=$!
# Wait for Zookeeper to be up, so that Kafka server can connect.
sleep 8
KAFKA_SERVER_CONFIG=kafka/config/server-kbrowse.properties
sed -e 's|#listeners.*|listeners=PLAINTEXT://localhost:9092|' \
-e 's|log.dirs=/tmp/kafka-logs|log.dirs=kafka-logs|' \
kafka/config/server.properties > $KAFKA_SERVER_CONFIG
echo Starting Kafka Server
./kafka/bin/kafka-server-start.sh $KAFKA_SERVER_CONFIG > /dev/null &
KAFKA_SERVER_PID=$!
# Wait for Kafka server to be up, so consumers can connect.
sleep 5
# Enter some initial test data.
echo
./kafka/bin/kafka-topics.sh --zookeeper localhost:2181 --create --topic kbrowse --partitions 10 --replication-factor 1
echo Inserting test data...
echo k,v | ./kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic kbrowse --property parse.key=true --property key.separator=,
echo
echo
echo Zookeeper/Kafka ready...
while true; do sleep 1; done