Repository: samza-hello-samza Updated Branches: refs/heads/latest de8231e51 -> 2214946c0 (forced update)
SAMZA-935 - hello-samza add kafka wait for dependent services Project: http://git-wip-us.apache.org/repos/asf/samza-hello-samza/repo Commit: http://git-wip-us.apache.org/repos/asf/samza-hello-samza/commit/2214946c Tree: http://git-wip-us.apache.org/repos/asf/samza-hello-samza/tree/2214946c Diff: http://git-wip-us.apache.org/repos/asf/samza-hello-samza/diff/2214946c Branch: refs/heads/latest Commit: 2214946c0b5498f9942e4ecdd4327fea4081b689 Parents: 70ad4c5 Author: Vishal Kuo <[email protected]> Authored: Sat Apr 23 12:44:43 2016 -0700 Committer: Navina Ramesh <[email protected]> Committed: Sat Apr 23 12:56:34 2016 -0700 ---------------------------------------------------------------------- bin/grid | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/samza-hello-samza/blob/2214946c/bin/grid ---------------------------------------------------------------------- diff --git a/bin/grid b/bin/grid index 042cabe..74ee026 100755 --- a/bin/grid +++ b/bin/grid @@ -39,6 +39,12 @@ DOWNLOAD_KAFKA=http://www.us.apache.org/dist/kafka/0.8.2.1/kafka_2.10-0.8.2.1.tg DOWNLOAD_YARN=https://archive.apache.org/dist/hadoop/common/hadoop-2.6.1/hadoop-2.6.1.tar.gz DOWNLOAD_ZOOKEEPER=http://archive.apache.org/dist/zookeeper/zookeeper-3.4.3/zookeeper-3.4.3.tar.gz +SERVICE_WAIT_TIMEOUT_SEC=10 +ZOOKEEPER_PORT=2181 +RESOURCEMANAGER_PORT=8032 +NODEMANAGER_PORT=8042 +KAFKA_PORT=9092 + bootstrap() { echo "Bootstrapping the system..." stop_all @@ -126,6 +132,7 @@ start_zookeeper() { if [ -f $DEPLOY_ROOT_DIR/$SYSTEM/bin/zkServer.sh ]; then cd $DEPLOY_ROOT_DIR/$SYSTEM bin/zkServer.sh start + wait_for_service "zookeeper" $ZOOKEEPER_PORT cd - > /dev/null else echo 'Zookeeper is not installed. Run: bin/grid install zookeeper' @@ -135,7 +142,9 @@ start_zookeeper() { start_yarn() { if [ -f $DEPLOY_ROOT_DIR/$SYSTEM/sbin/yarn-daemon.sh ]; then $DEPLOY_ROOT_DIR/$SYSTEM/sbin/yarn-daemon.sh start resourcemanager + wait_for_service "resourcemanager" $RESOURCEMANAGER_PORT $DEPLOY_ROOT_DIR/$SYSTEM/sbin/yarn-daemon.sh start nodemanager + wait_for_service "nodemanager" $NODEMANAGER_PORT else echo 'YARN is not installed. Run: bin/grid install yarn' fi @@ -147,11 +156,29 @@ start_kafka() { cd $DEPLOY_ROOT_DIR/$SYSTEM nohup bin/kafka-server-start.sh config/server.properties > logs/kafka.log 2>&1 & cd - > /dev/null + wait_for_service "kafka" $KAFKA_PORT else echo 'Kafka is not installed. Run: bin/grid install kafka' fi } +wait_for_service() { + local SERVICE_NAME=$1 + local PORT=$2 + echo "Waiting for $SERVICE_NAME to start..." + local CURRENT_WAIT_TIME=0 + until $(nc -w 1 localhost $PORT); do + printf '.' + sleep 1 + if [ $((++CURRENT_WAIT_TIME)) -eq $SERVICE_WAIT_TIMEOUT_SEC ]; then + printf "\nError: timed out while waiting for $SERVICE_NAME to start.\n" + exit 1 + fi + done + printf '\n' + echo "$SERVICE_NAME has started"; +} + stop_all() { $DIR/grid stop kafka $DIR/grid stop yarn
