#!/bin/bash

export JAVA_HOME=/var/vcap/packages/jre
export LOG_DIR=/var/vcap/sys/log/kafka-server
export KAFKA_HEAP_OPTS="-Xmx5G -Xms5G"

JOB_DIR=/var/vcap/jobs/kafka-server
CONFIG_FILE=${JOB_DIR}/config/server.properties
LOG_PIPE=${JOB_DIR}/kafka.pipe.log
PID_FILE=${JOB_DIR}/kafka.pid

case $1 in

start)

    if [ ! -e $LOG_PIPE ]; then
        mkfifo $LOG_PIPE
    fi

    if [ -d $LOG_DIR ]; then
        mkdir -p $LOG_DIR
        chown -R vcap:vcap $LOG_DIR
    fi

    ulimit -n 8192

    /var/vcap/packages/kafka/bin/kafka-server-start.sh $CONFIG_FILE > $LOG_PIPE 2>&1 &
    echo $! > $PID_FILE
    logger < $LOG_PIPE &

    ;;

stop)

    pid=`cat $PID_FILE`
    # attempt to kill -SIGTERM 3 times
    for i in {1..3}; do
        if [ ! -e /proc/$pid/limits ]; then
            break;
        fi
        kill -SIGTERM $pid
        sleep 1
    done
    # finally we use sigkill
    kill -SIGKILL $pid

;;

*)
    echo "Usage: ctl {start|stop}" ;;

esac

#!/bin/bash

export JAVA_HOME=/var/vcap/packages/jre
export LOG_DIR=/var/vcap/sys/log/kafka-server
export KAFKA_HEAP_OPTS="-Xmx5G -Xms5G"

JOB_DIR=/var/vcap/jobs/kafka-server
CONFIG_FILE=${JOB_DIR}/config/server.properties
LOG_PIPE=${JOB_DIR}/kafka.pipe.log
PID_FILE=${JOB_DIR}/kafka.pid

case $1 in

start)

    if [ ! -e $LOG_PIPE ]; then
        mkfifo $LOG_PIPE
    fi

    if [ -d $LOG_DIR ]; then
        mkdir -p $LOG_DIR
        chown -R vcap:vcap $LOG_DIR
    fi

    ulimit -n 8192

    # monit does not really execute the background task until this script finishes.
    # bosh does not deal with this script continuing to run indefinitely very well.
    nohup sleep 5 && echo $(ps ax | grep kafka | grep java | awk '{ print $1 }') > ${PID_FILE} &
    /var/vcap/packages/kafka/bin/kafka-server-start.sh $CONFIG_FILE > $LOG_PIPE  2>&1 &
    logger < $LOG_PIPE &

    ;;

stop)
    exec /var/vcap/packages/kafka/bin/kafka-server-stop.sh 2>&1 | logger

;;

*)
    echo "Usage: ctl {start|stop}" ;;

esac

Update control script start to get correct PID
Update control script start to get correct PID

[##99551354]

Signed-off-by: Sam Nelson <7f9518b0fc80ae8ec9b933cc7d9f449459d97036@pivotal.io>
