github.com/adnan-c/fabric_e2e_couchdb@v0.6.1-preview.0.20170228180935-21ce6b23cf91/images/kafka/kafka-run-class.sh (about)

     1  #!/bin/bash
     2  # Licensed to the Apache Software Foundation (ASF) under one or more
     3  # contributor license agreements.  See the NOTICE file distributed with
     4  # this work for additional information regarding copyright ownership.
     5  # The ASF licenses this file to You under the Apache License, Version 2.0
     6  # (the "License"); you may not use this file except in compliance with
     7  # the License.  You may obtain a copy of the License at
     8  #
     9  #    http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  if [ $# -lt 1 ];
    18  then
    19    echo "USAGE: $0 [-daemon] [-name servicename] [-loggc] classname [opts]"
    20    exit 1
    21  fi
    22  
    23  base_dir=$(dirname $0)/..
    24  
    25  if [ -z "$SCALA_VERSION" ]; then
    26  	SCALA_VERSION=2.10.5
    27  fi
    28  
    29  if [ -z "$SCALA_BINARY_VERSION" ]; then
    30  	SCALA_BINARY_VERSION=2.10
    31  fi
    32  
    33  # run ./gradlew copyDependantLibs to get all dependant jars in a local dir
    34  shopt -s nullglob
    35  for dir in $base_dir/core/build/dependant-libs-${SCALA_VERSION}*;
    36  do
    37    CLASSPATH=$CLASSPATH:$dir/*
    38  done
    39  
    40  for file in $base_dir/examples/build/libs//kafka-examples*.jar;
    41  do
    42    CLASSPATH=$CLASSPATH:$file
    43  done
    44  
    45  for file in $base_dir/clients/build/libs/kafka-clients*.jar;
    46  do
    47    CLASSPATH=$CLASSPATH:$file
    48  done
    49  
    50  for file in $base_dir/tools/build/libs/kafka-tools*.jar;
    51  do
    52    CLASSPATH=$CLASSPATH:$file
    53  done
    54  
    55  for dir in $base_dir/tools/build/dependant-libs-${SCALA_VERSION}*;
    56  do
    57    CLASSPATH=$CLASSPATH:$dir/*
    58  done
    59  
    60  for cc_pkg in "api" "runtime" "file" "json"
    61  do
    62    for file in $base_dir/connect/${cc_pkg}/build/libs/connect-${cc_pkg}*.jar;
    63    do
    64      CLASSPATH=$CLASSPATH:$file
    65    done
    66    if [ -d "$base_dir/connect/${cc_pkg}/build/dependant-libs" ] ; then
    67      CLASSPATH=$CLASSPATH:$base_dir/connect/${cc_pkg}/build/dependant-libs/*
    68    fi
    69  done
    70  
    71  # classpath addition for release
    72  CLASSPATH=$CLASSPATH:$base_dir/libs/*
    73  
    74  for file in $base_dir/core/build/libs/kafka_${SCALA_BINARY_VERSION}*.jar;
    75  do
    76    CLASSPATH=$CLASSPATH:$file
    77  done
    78  shopt -u nullglob
    79  
    80  # JMX settings
    81  if [ -z "$KAFKA_JMX_OPTS" ]; then
    82    KAFKA_JMX_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false  -Dcom.sun.management.jmxremote.ssl=false "
    83  fi
    84  
    85  # JMX port to use
    86  if [  $JMX_PORT ]; then
    87    KAFKA_JMX_OPTS="$KAFKA_JMX_OPTS -Dcom.sun.management.jmxremote.port=$JMX_PORT "
    88  fi
    89  
    90  # Log directory to use
    91  if [ "x$LOG_DIR" = "x" ]; then
    92      LOG_DIR="$base_dir/logs"
    93  fi
    94  
    95  # Log4j settings
    96  if [ -z "$KAFKA_LOG4J_OPTS" ]; then
    97    # Log to console. This is a tool.
    98    KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:$base_dir/config/tools-log4j.properties"
    99  else
   100    # create logs directory
   101    if [ ! -d "$LOG_DIR" ]; then
   102      mkdir -p "$LOG_DIR"
   103    fi
   104  fi
   105  
   106  KAFKA_LOG4J_OPTS="-Dkafka.logs.dir=$LOG_DIR $KAFKA_LOG4J_OPTS"
   107  
   108  # Generic jvm settings you want to add
   109  if [ -z "$KAFKA_OPTS" ]; then
   110    KAFKA_OPTS=""
   111  fi
   112  
   113  # Which java to use
   114  if [ -z "$JAVA_HOME" ]; then
   115    JAVA="java"
   116  else
   117    JAVA="$JAVA_HOME/bin/java"
   118  fi
   119  
   120  # Memory options
   121  if [ -z "$KAFKA_HEAP_OPTS" ]; then
   122    KAFKA_HEAP_OPTS="-Xmx256M"
   123  fi
   124  
   125  # JVM performance options
   126  if [ -z "$KAFKA_JVM_PERFORMANCE_OPTS" ]; then
   127    KAFKA_JVM_PERFORMANCE_OPTS="-server -XX:+UseG1GC -XX:MaxGCPauseMillis=20 -XX:InitiatingHeapOccupancyPercent=35 -XX:+DisableExplicitGC -Djava.awt.headless=true"
   128  fi
   129  
   130  
   131  while [ $# -gt 0 ]; do
   132    COMMAND=$1
   133    case $COMMAND in
   134      -name)
   135        DAEMON_NAME=$2
   136        CONSOLE_OUTPUT_FILE=$LOG_DIR/$DAEMON_NAME.out
   137        shift 2
   138        ;;
   139      -loggc)
   140        if [ -z "$KAFKA_GC_LOG_OPTS" ]; then
   141          GC_LOG_ENABLED="true"
   142        fi
   143        shift
   144        ;;
   145      -daemon)
   146        DAEMON_MODE="true"
   147        shift
   148        ;;
   149      *)
   150        break
   151        ;;
   152    esac
   153  done
   154  
   155  # GC options
   156  GC_FILE_SUFFIX='-gc.log'
   157  GC_LOG_FILE_NAME=''
   158  if [ "x$GC_LOG_ENABLED" = "xtrue" ]; then
   159    GC_LOG_FILE_NAME=$DAEMON_NAME$GC_FILE_SUFFIX
   160    if $JAVA -XshowSettings:properties -version 2>&1 | grep --silent "^\s*java.vendor\s*=\s*IBM Corporation" ; then
   161      KAFKA_GC_LOG_OPTS="-Xverbosegclog:$LOG_DIR/$GC_LOG_FILE_NAME -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps "
   162    else
   163      KAFKA_GC_LOG_OPTS="-Xloggc:$LOG_DIR/$GC_LOG_FILE_NAME -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps "
   164    fi
   165  fi
   166  
   167  # Launch mode
   168  if [ "x$DAEMON_MODE" = "xtrue" ]; then
   169    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 &
   170  else
   171    exec $JAVA $KAFKA_HEAP_OPTS $KAFKA_JVM_PERFORMANCE_OPTS $KAFKA_GC_LOG_OPTS $KAFKA_JMX_OPTS $KAFKA_LOG4J_OPTS -cp $CLASSPATH $KAFKA_OPTS "$@"
   172  fi