From 7aec0b769b3162fcd7a53c3f1c78991f3e82d585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Saint-Jacques?= Date: Wed, 21 Jan 2015 13:01:50 -0500 Subject: [PATCH] Refactor wrapper scripts - stricter bash options for security: - errexit: exit on command failure - nounset: exit on unset variable - pipefail: exit code non-zero if any of a pipe exec fail - minor spacing issues - removed some duplicate code --- bin/kafka-console-consumer.sh | 8 +- bin/kafka-console-producer.sh | 9 +- bin/kafka-consumer-offset-checker.sh | 8 +- bin/kafka-consumer-perf-test.sh | 9 +- bin/kafka-mirror-maker.sh | 8 +- bin/kafka-preferred-replica-election.sh | 4 +- bin/kafka-producer-perf-test.sh | 9 +- bin/kafka-reassign-partitions.sh | 4 +- bin/kafka-replay-log-producer.sh | 8 +- bin/kafka-replica-verification.sh | 8 +- bin/kafka-run-class.sh | 141 ++++++++++++-------------------- bin/kafka-server-start.sh | 25 +++--- bin/kafka-server-stop.sh | 9 +- bin/kafka-simple-consumer-shell.sh | 8 +- bin/kafka-topics.sh | 8 +- bin/zookeeper-server-start.sh | 24 +++--- bin/zookeeper-server-stop.sh | 9 +- bin/zookeeper-shell.sh | 12 +-- 18 files changed, 146 insertions(+), 165 deletions(-) diff --git a/bin/kafka-console-consumer.sh b/bin/kafka-console-consumer.sh index 07c90a9..f09a29f 100755 --- a/bin/kafka-console-consumer.sh +++ b/bin/kafka-console-consumer.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. @@ -14,8 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -if [ "x$KAFKA_HEAP_OPTS" = "x" ]; then - export KAFKA_HEAP_OPTS="-Xmx512M" -fi +set -o errexit -o nounset -o pipefail + +export KAFKA_HEAP_OPTS=${KAFKA_HEAP_OPTS:-"-Xmx512M"} exec $(dirname $0)/kafka-run-class.sh kafka.tools.ConsoleConsumer $@ diff --git a/bin/kafka-console-producer.sh b/bin/kafka-console-producer.sh index ccca66d..2666150 100755 --- a/bin/kafka-console-producer.sh +++ b/bin/kafka-console-producer.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. @@ -14,7 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -if [ "x$KAFKA_HEAP_OPTS" = "x" ]; then - export KAFKA_HEAP_OPTS="-Xmx512M" -fi +set -o errexit -o nounset -o pipefail + +export KAFKA_HEAP_OPTS=${KAFKA_HEAP_OPTS:-"-Xmx512M"} + exec $(dirname $0)/kafka-run-class.sh kafka.tools.ConsoleProducer $@ diff --git a/bin/kafka-consumer-offset-checker.sh b/bin/kafka-consumer-offset-checker.sh index c275f7e..5aa3b11 100755 --- a/bin/kafka-consumer-offset-checker.sh +++ b/bin/kafka-consumer-offset-checker.sh @@ -1,17 +1,19 @@ -#!/bin/bash +#!/usr/bin/env bash # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. +set -o errexit -o nounset -o pipefail + exec $(dirname $0)/kafka-run-class.sh kafka.tools.ConsumerOffsetChecker $@ diff --git a/bin/kafka-consumer-perf-test.sh b/bin/kafka-consumer-perf-test.sh index ebc513a..e89fb84 100755 --- a/bin/kafka-consumer-perf-test.sh +++ b/bin/kafka-consumer-perf-test.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. @@ -14,7 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -if [ "x$KAFKA_HEAP_OPTS" = "x" ]; then - export KAFKA_HEAP_OPTS="-Xmx512M" -fi +set -o errexit -o nounset -o pipefail + +export KAFKA_HEAP_OPTS=${KAFKA_HEAP_OPTS:-"-Xmx512M"} + exec $(dirname $0)/kafka-run-class.sh kafka.tools.ConsumerPerformance $@ diff --git a/bin/kafka-mirror-maker.sh b/bin/kafka-mirror-maker.sh index 56e342c..12ac15b 100755 --- a/bin/kafka-mirror-maker.sh +++ b/bin/kafka-mirror-maker.sh @@ -1,17 +1,19 @@ -#!/bin/bash +#!/usr/bin/env bash # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. +set -o errexit -o nounset -o pipefail + exec $(dirname $0)/kafka-run-class.sh kafka.tools.MirrorMaker $@ diff --git a/bin/kafka-preferred-replica-election.sh b/bin/kafka-preferred-replica-election.sh index ed167c2..b93c317 100755 --- a/bin/kafka-preferred-replica-election.sh +++ b/bin/kafka-preferred-replica-election.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. @@ -14,4 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. +set -o errexit -o nounset -o pipefail + exec $(dirname $0)/kafka-run-class.sh kafka.admin.PreferredReplicaLeaderElectionCommand $@ diff --git a/bin/kafka-producer-perf-test.sh b/bin/kafka-producer-perf-test.sh index 84ac949..6cddc0d 100755 --- a/bin/kafka-producer-perf-test.sh +++ b/bin/kafka-producer-perf-test.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. @@ -14,7 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -if [ "x$KAFKA_HEAP_OPTS" = "x" ]; then - export KAFKA_HEAP_OPTS="-Xmx512M" -fi +set -o errexit -o nounset -o pipefail + +export KAFKA_HEAP_OPTS=${KAFKA_HEAP_OPTS:-"-Xmx512M"} + exec $(dirname $0)/kafka-run-class.sh kafka.tools.ProducerPerformance $@ diff --git a/bin/kafka-reassign-partitions.sh b/bin/kafka-reassign-partitions.sh index 95b4ae0..24817ad 100755 --- a/bin/kafka-reassign-partitions.sh +++ b/bin/kafka-reassign-partitions.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. @@ -14,4 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. +set -o errexit -o nounset -o pipefail + exec $(dirname $0)/kafka-run-class.sh kafka.admin.ReassignPartitionsCommand $@ diff --git a/bin/kafka-replay-log-producer.sh b/bin/kafka-replay-log-producer.sh index 8e2e713..7fe50a4 100755 --- a/bin/kafka-replay-log-producer.sh +++ b/bin/kafka-replay-log-producer.sh @@ -1,17 +1,19 @@ -#!/bin/bash +#!/usr/bin/env bash # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. +set -o errexit -o nounset -o pipefail + exec $(dirname $0)/kafka-run-class.sh kafka.tools.ReplayLogProducer $@ diff --git a/bin/kafka-replica-verification.sh b/bin/kafka-replica-verification.sh index ee6d19e..53a82f6 100755 --- a/bin/kafka-replica-verification.sh +++ b/bin/kafka-replica-verification.sh @@ -1,17 +1,19 @@ -#!/bin/bash +#!/usr/bin/env bash # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. +set -o errexit -o nounset -o pipefail + exec $(dirname $0)/kafka-run-class.sh kafka.tools.ReplicaVerificationTool $@ diff --git a/bin/kafka-run-class.sh b/bin/kafka-run-class.sh index 22a9865..872cc8c 100755 --- a/bin/kafka-run-class.sh +++ b/bin/kafka-run-class.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. @@ -14,118 +14,71 @@ # See the License for the specific language governing permissions and # limitations under the License. -if [ $# -lt 1 ]; -then +set -o errexit -o nounset -o pipefail + +if [ $# -lt 1 ]; then echo "USAGE: $0 [-daemon] [-name servicename] [-loggc] classname [opts]" exit 1 fi base_dir=$(dirname $0)/.. -# create logs directory -if [ "x$LOG_DIR" = "x" ]; then - LOG_DIR="$base_dir/logs" -fi - -if [ ! -d "$LOG_DIR" ]; then - mkdir -p "$LOG_DIR" -fi - -if [ -z "$SCALA_VERSION" ]; then - SCALA_VERSION=2.10.4 -fi - -if [ -z "$SCALA_BINARY_VERSION" ]; then - SCALA_BINARY_VERSION=2.10 +: ${LOG_DIR:=${base_dir}/logs} +if [ ! -d "${LOG_DIR}" ]; then + mkdir -p "${LOG_DIR}" fi +: ${SCALA_VERSION:=2.10.4} +: ${SCALA_BINARY_VERSION:=2.10} # run ./gradlew copyDependantLibs to get all dependant jars in a local dir -for file in $base_dir/core/build/dependant-libs-${SCALA_VERSION}*/*.jar; -do - CLASSPATH=$CLASSPATH:$file -done - -for file in $base_dir/examples/build/libs//kafka-examples*.jar; -do - CLASSPATH=$CLASSPATH:$file -done - -for file in $base_dir/contrib/hadoop-consumer/build/libs//kafka-hadoop-consumer*.jar; -do - CLASSPATH=$CLASSPATH:$file -done - -for file in $base_dir/contrib/hadoop-producer/build/libs//kafka-hadoop-producer*.jar; -do - CLASSPATH=$CLASSPATH:$file -done - -for file in $base_dir/clients/build/libs/kafka-clients*.jar; -do - CLASSPATH=$CLASSPATH:$file -done - -# classpath addition for release -for file in $base_dir/libs/*.jar; -do - CLASSPATH=$CLASSPATH:$file -done - -for file in $base_dir/core/build/libs/kafka_${SCALA_BINARY_VERSION}*.jar; -do - CLASSPATH=$CLASSPATH:$file +CLASSPATH=${CLASSPATH:-} +for file in ${base_dir}/core/bild/dependant-libs-${SCALA_VERSION}*/*.jar \ + ${base_dir}/contrib/hadoop-consumer/build/libs/kafka-hadoop-{consumer,producer}*.jar \ + ${base_dir}/clients/build/libs/kafka-clients*.jar \ + ${base_dir}/libs/*.jar \ + ${base_dir}/core/build/libs/kafka_${SCALA_BINARY_VERSION}*.jar; do + CLASSPATH=${file}:${CLASSPATH} done # JMX settings -if [ -z "$KAFKA_JMX_OPTS" ]; then - KAFKA_JMX_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false " -fi +: ${KAFKA_JMX_OPTS:="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"} # JMX port to use -if [ $JMX_PORT ]; then - KAFKA_JMX_OPTS="$KAFKA_JMX_OPTS -Dcom.sun.management.jmxremote.port=$JMX_PORT " +if [ ! -z "${JMX_PORT:-}" ]; then + KAFKA_JMX_OPTS="${KAFKA_JMX_OPTS} -Dcom.sun.management.jmxremote.port=${JMX_PORT}" fi -# Log4j settings -if [ -z "$KAFKA_LOG4J_OPTS" ]; then - KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:$base_dir/config/tools-log4j.properties" -fi - -KAFKA_LOG4J_OPTS="-Dkafka.logs.dir=$LOG_DIR $KAFKA_LOG4J_OPTS" +# log4j configuration +: ${KAFKA_LOG4J_OPTS:="-Dlog4j.configuration=file:$base_dir/config/tools-log4j.properties"} +KAFKA_LOG4J_OPTS="-Dkafka.logs.dir=${LOG_DIR} ${KAFKA_LOG4J_OPTS}" # Generic jvm settings you want to add -if [ -z "$KAFKA_OPTS" ]; then - KAFKA_OPTS="" -fi - -# Which java to use -if [ -z "$JAVA_HOME" ]; then - JAVA="java" -else - JAVA="$JAVA_HOME/bin/java" -fi +: ${KAFKA_OPTS:=} # Memory options -if [ -z "$KAFKA_HEAP_OPTS" ]; then - KAFKA_HEAP_OPTS="-Xmx256M" -fi +: ${KAFKA_HEAP_OPTS:="-Xmx256M"} + +# JVM GC options +: ${KAFKA_JVM_GC:="-XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+CMSScavengeBeforeRemark -XX:+DisableExplicitGC"} # JVM performance options -if [ -z "$KAFKA_JVM_PERFORMANCE_OPTS" ]; then - KAFKA_JVM_PERFORMANCE_OPTS="-server -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+CMSScavengeBeforeRemark -XX:+DisableExplicitGC -Djava.awt.headless=true" -fi +: ${KAFKA_JVM_PERFORMANCE_OPTS:="-server $KAFKA_JVM_GC -Djava.awt.headless=true"} +JAVA=java +if [ ! -z "${JAVA_HOME}" ]; then + JAVA=${JAVA_HOME}/bin/java +fi while [ $# -gt 0 ]; do COMMAND=$1 - case $COMMAND in + case ${COMMAND} in -name) DAEMON_NAME=$2 - CONSOLE_OUTPUT_FILE=$LOG_DIR/$DAEMON_NAME.out + CONSOLE_OUTPUT_FILE=${LOG_DIR}/${DAEMON_NAME}.out shift 2 ;; -loggc) - if [ -z "$KAFKA_GC_LOG_OPTS"] ; then + if [ -z "${KAFKA_GC_LOG_OPTS:-}" ] ; then GC_LOG_ENABLED="true" fi shift @@ -141,16 +94,24 @@ while [ $# -gt 0 ]; do done # GC options -GC_FILE_SUFFIX='-gc.log' -GC_LOG_FILE_NAME='' -if [ "x$GC_LOG_ENABLED" = "xtrue" ]; then - GC_LOG_FILE_NAME=$DAEMON_NAME$GC_FILE_SUFFIX - KAFKA_GC_LOG_OPTS="-Xloggc:$LOG_DIR/$GC_LOG_FILE_NAME -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps " +: ${KAFKA_GC_LOG_OPTS:=} +if [ "${GC_LOG_ENABLED:-false}" = "true" ]; then + KAFKA_GC_LOG_OPTS="-Xloggc:${LOG_DIR}/${DAEMON_NAME}-gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps" fi +declare -a KAFKA_ARGS=( \ + $KAFKA_HEAP_OPTS \ + $KAFKA_JVM_PERFORMANCE_OPTS \ + $KAFKA_GC_LOG_OPTS \ + $KAFKA_JMX_OPTS \ + $KAFKA_LOG4J_OPTS \ + "-cp $CLASSPATH" \ + $KAFKA_OPTS \ +) + # Launch mode -if [ "x$DAEMON_MODE" = "xtrue" ]; then - nohup $JAVA $KAFKA_HEAP_OPTS $KAFKA_JVM_PERFORMANCE_OPTS $KAFKA_GC_LOG_OPTS $KAFKA_JMX_OPTS $KAFKA_LOG4J_OPTS -cp $CLASSPATH $KAFKA_OPTS "$@" > "$CONSOLE_OUTPUT_FILE" 2>&1 < /dev/null & +if [ "${DAEMON_MODE:-false}" = "true" ]; then + nohup ${JAVA} ${KAFKA_ARGS[@]} "$@" > ${CONSOLE_OUTPUT_FILE} 2>&1 < /dev/null & else - exec $JAVA $KAFKA_HEAP_OPTS $KAFKA_JVM_PERFORMANCE_OPTS $KAFKA_GC_LOG_OPTS $KAFKA_JMX_OPTS $KAFKA_LOG4J_OPTS -cp $CLASSPATH $KAFKA_OPTS "$@" + exec ${JAVA} ${KAFKA_ARGS[@]} "$@" fi diff --git a/bin/kafka-server-start.sh b/bin/kafka-server-start.sh index dc01d46..f7a0aa0 100755 --- a/bin/kafka-server-start.sh +++ b/bin/kafka-server-start.sh @@ -1,44 +1,41 @@ -#!/bin/bash +#!/usr/bin/env bash # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. +set -o errexit -o nounset -o pipefail + if [ $# -lt 1 ]; then - echo "USAGE: $0 [-daemon] server.properties [--override property=value]*" - exit 1 + echo "USAGE: $0 [-daemon] server.properties [--override property=value]*" + exit 1 fi base_dir=$(dirname $0) -if [ "x$KAFKA_LOG4J_OPTS" = "x" ]; then - export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:$base_dir/../config/log4j.properties" -fi - -if [ "x$KAFKA_HEAP_OPTS" = "x" ]; then - export KAFKA_HEAP_OPTS="-Xmx1G -Xms1G" -fi +export KAFKA_LOG4J_OPTS=${KAFKA_LOG4J_OPTS:-"-Dlog4j.configuration=file:$base_dir/../config/log4j.properties"} +export KAFKA_HEAP_OPTS=${KAFKA_HEAP_OPTS:-"-Xmx1G -Xms1G"} EXTRA_ARGS="-name kafkaServer -loggc" COMMAND=$1 case $COMMAND in -daemon) - EXTRA_ARGS="-daemon "$EXTRA_ARGS + EXTRA_ARGS="-daemon ${EXTRA_ARGS}" shift ;; *) ;; esac -exec $base_dir/kafka-run-class.sh $EXTRA_ARGS kafka.Kafka $@ +exec ${base_dir}/kafka-run-class.sh ${EXTRA_ARGS} kafka.Kafka $@ diff --git a/bin/kafka-server-stop.sh b/bin/kafka-server-stop.sh index cd8160c..0c2c69e 100755 --- a/bin/kafka-server-stop.sh +++ b/bin/kafka-server-stop.sh @@ -1,16 +1,19 @@ -#!/bin/sh +#!/usr/bin/env bash # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. + +set -o errexit -o nounset -o pipefail + ps ax | grep -i 'kafka\.Kafka' | grep java | grep -v grep | awk '{print $1}' | xargs kill -SIGTERM diff --git a/bin/kafka-simple-consumer-shell.sh b/bin/kafka-simple-consumer-shell.sh index 9316f79..3945795 100755 --- a/bin/kafka-simple-consumer-shell.sh +++ b/bin/kafka-simple-consumer-shell.sh @@ -1,17 +1,19 @@ -#!/bin/bash +#!/usr/bin/env bash # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. +set -o errexit -o nounset -o pipefail + exec $(dirname $0)/kafka-run-class.sh kafka.tools.SimpleConsumerShell $@ diff --git a/bin/kafka-topics.sh b/bin/kafka-topics.sh index b39b272..ca4046e 100755 --- a/bin/kafka-topics.sh +++ b/bin/kafka-topics.sh @@ -1,17 +1,19 @@ -#!/bin/bash +#!/usr/bin/env bash # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. +set -o errexit -o nounset -o pipefail + exec $(dirname $0)/kafka-run-class.sh kafka.admin.TopicCommand $@ diff --git a/bin/zookeeper-server-start.sh b/bin/zookeeper-server-start.sh index d968786..d8a4fe6 100755 --- a/bin/zookeeper-server-start.sh +++ b/bin/zookeeper-server-start.sh @@ -1,33 +1,30 @@ -#!/bin/bash +#!/usr/bin/env bash # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. +set -o errexit -o nounset -o pipefail + if [ $# -lt 1 ]; then - echo "USAGE: $0 zookeeper.properties" - exit 1 + echo "USAGE: $0 zookeeper.properties" + exit 1 fi base_dir=$(dirname $0) -if [ "x$KAFKA_LOG4J_OPTS" = "x" ]; then - export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:$base_dir/../config/log4j.properties" -fi - -if [ "x$KAFKA_HEAP_OPTS" = "x" ]; then - export KAFKA_HEAP_OPTS="-Xmx512M -Xms512M" -fi +export KAFKA_LOG4J_OPTS=${KAFKA_LOG4J_OPTS:-"-Dlog4j.configuration=file:$base_dir/../config/log4j.properties"} +export KAFKA_HEAP_OPTS=${KAFKA_HEAP_OPTS:-"-Xmx512M -Xms512M"} EXTRA_ARGS="-name zookeeper -loggc" @@ -41,5 +38,4 @@ case $COMMAND in ;; esac -exec $base_dir/kafka-run-class.sh $EXTRA_ARGS org.apache.zookeeper.server.quorum.QuorumPeerMain $@ - +exec ${base_dir}/kafka-run-class.sh ${EXTRA_ARGS} org.apache.zookeeper.server.quorum.QuorumPeerMain $@ diff --git a/bin/zookeeper-server-stop.sh b/bin/zookeeper-server-stop.sh index 975d9ae..209e437 100755 --- a/bin/zookeeper-server-stop.sh +++ b/bin/zookeeper-server-stop.sh @@ -1,16 +1,19 @@ -#!/bin/sh +#!/usr/bin/env bash # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. + +set -o errexit -o nounset -o pipefail + ps ax | grep -i 'zookeeper' | grep -v grep | awk '{print $1}' | xargs kill -SIGINT diff --git a/bin/zookeeper-shell.sh b/bin/zookeeper-shell.sh index 95007fa..55ac6cb 100755 --- a/bin/zookeeper-shell.sh +++ b/bin/zookeeper-shell.sh @@ -1,23 +1,25 @@ -#!/bin/sh +#!/usr/bin/env bash # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. +set -o errexit -o nounset -o pipefail + if [ $# -lt 1 ]; then - echo "USAGE: $0 zookeeper_host:port[/path] [args...]" - exit 1 + echo "USAGE: $0 zookeeper_host:port[/path] [args...]" + exit 1 fi exec $(dirname $0)/kafka-run-class.sh org.apache.zookeeper.ZooKeeperMain -server "$@" -- 2.2.1