github.com/kchristidis/fabric@v1.0.4-0.20171028114726-837acd08cde1/images/kafka/kafka-run-class.sh (about)

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