<commit_before>#!/bin/sh
#
# Init file for Apache Kafka <%= @service_name.split(/-/)[1] and @service_name.split(/-/)[1].capitalize %>
#
<%- if @osfamily == 'Debian' -%>
### BEGIN INIT INFO
# Provides:          <%- @service_name -%>
# Required-Start:    zookeeper
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# X-Interactive:     true
# Short-Description: Apache Kafka is a distributed publish-subscribe messaging system
### END INIT INFO
<%- else -%>
# chkconfig: 35 85 15
# description: Apache Kafka is a distributed publish-subscribe messaging system
# pidfile: /var/run/<%= @service_name -%>.pid
<%- end -%>

NAME=<%= @service_name %>
PID_FILE="/var/run/$NAME.pid"
KAFKA_USER=kafka
<%- case @service_name
  when 'kafka' -%>
PGREP_PATTERN=kafka.Kafka

DAEMON="/opt/kafka/bin/kafka-server-start.sh"
DAEMON_OPTS="/opt/kafka/config/server.properties"

export KAFKA_JMX_OPTS="<%= @jmx_opts %>"
export KAFKA_LOG4J_OPTS="<%= @log4j_opts %>"
export KAFKA_HEAP_OPTS="<%= @heap_opts %>"

export KAFKA_OPTS="<%= @opts %>"
<%- when 'kafka-consumer' -%>
PGREP_PATTERN=kafka.tools.ConsoleConsumer

DAEMON="/opt/kafka/bin/kafka-console-consumer.sh"
DAEMON_OPTS="<% @consumer_service_config.sort.each do |k,v| -%><% unless v.to_s.strip.empty? -%>--<%= k -%>=<%= v.is_a?(Array) ? v.join(',') : v %> <% end -%><% end -%>"

export KAFKA_JMX_OPTS="<%= @consumer_jmx_opts %>"
export KAFKA_LOG4J_OPTS="<%= @consumer_log4j_opts %>"
<%- when 'kafka-mirror' -%>
PGREP_PATTERN=kafka.tools.MirrorMaker

DAEMON="/opt/kafka/bin/kafka-run-class.sh"
DAEMON_OPTS="kafka.tools.MirrorMaker --consumer.config <%= @consumer_config -%> --num.streams <%= @num_streams -%> --producer.config <%= @producer_config -%><%- if (scope.function_versioncmp([scope.lookupvar('kafka::version'), '0.9.0.0']) < 0) -%> --num.producers <%= @num_producers -%><%- end -%><%- if !@whitelist.eql?('') -%> --whitelist='<%= @whitelist -%>'<%- end %><%- if !@blacklist.eql?('') -%> --blacklist='<%= @blacklist -%>'<%- end -%>"

export KAFKA_HEAP_OPTS="-Xmx<%= @max_heap -%> -Xms<%= @max_heap -%>"
export KAFKA_JMX_OPTS="<%= @mirror_jmx_opts %>"
export KAFKA_LOG4J_OPTS="<%= @mirror_log4j_opts %>"
<%- when 'kafka-producer' -%>
PGREP_PATTERN=kafka.tools.ConsoleProducer

DAEMON="/opt/kafka/bin/kafka-console-producer.sh"
DAEMON_OPTS="<% @producer_service_config.sort.each do |k,v| -%><% unless v.to_s.strip.empty? -%>--<%= k -%>=<%= v.is_a?(Array) ? v.join(',') : v %> <% end -%><% end -%>"
PRODUCER_INPUT="<%= @input %>"

export KAFKA_JMX_OPTS="<%= @producer_jmx_opts %>"
export KAFKA_LOG4J_OPTS="<%= @producer_log4j_opts %>"
<%- end -%>

if [ -f /etc/default/kafka ]; then
    . /etc/default/kafka
fi

start() {
  ulimit -n 65536
  ulimit -s 10240
  ulimit -c unlimited
  if [ -f "$PID_FILE" ]; then
    PID=`cat "$PID_FILE"`
    if [ `ps -p "$PID" -o pid= || echo 1` -eq `pgrep -f "$PGREP_PATTERN" || echo 2` ] ; then
      echo "$PID_FILE exists, process is already running"
      exit 0
    fi
    echo "$PID_FILE exists but the process is not running. Deleting $PID_FILE and re-trying"
    rm -f -- "$PID_FILE"
    start
    return $?
  fi

  /bin/su "$KAFKA_USER" -c "KAFKA_JMX_OPTS=\"$KAFKA_JMX_OPTS\" $DAEMON $DAEMON_OPTS<%- if @service_name == 'kafka-producer' -%> $PRODUCER_INPUT<%- end -%> >/dev/null 2>&1 &"
  sleep 2
  PID=`pgrep -f "$PGREP_PATTERN"`
  if [ -z "$PID" ]; then
    echo "$NAME could not be started"
    exit 1
  fi

  echo "$PID" > "$PID_FILE";
  echo "$NAME started"
  return 0
}

stop() {
  if [ ! -f "$PID_FILE" ]; then
    echo "$PID_FILE does not exist, process is not running"
    return 1
  fi

  kill `cat "$PID_FILE"`;
  rm -f -- "$PID_FILE";
  echo "$NAME stopped"
  return 0
}

status() {
  if ! [ -f "$PID_FILE" ]; then
    echo "$NAME stopped"
    exit 1
  fi

  PID=`cat "$PID_FILE"`
  if ! [ `ps -p "$PID" -o pid= || echo 1` -eq `pgrep -f "$PGREP_PATTERN" || echo 2` ] ; then
    echo "$NAME stopped but pid file exists"
    exit 1
  fi

  echo "$NAME running with pid $PID"
  exit 0
}

case "$1" in<commit_msg>system-v init: extend stop() to be more robust<commit_after>#!/bin/sh
#
# Init file for Apache Kafka <%= @service_name.split(/-/)[1] and @service_name.split(/-/)[1].capitalize %>
#
<%- if @osfamily == 'Debian' -%>
### BEGIN INIT INFO
# Provides:          <%- @service_name -%>
# Required-Start:    zookeeper
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# X-Interactive:     true
# Short-Description: Apache Kafka is a distributed publish-subscribe messaging system
### END INIT INFO
<%- else -%>
# chkconfig: 35 85 15
# description: Apache Kafka is a distributed publish-subscribe messaging system
# pidfile: /var/run/<%= @service_name -%>.pid
<%- end -%>

NAME=<%= @service_name %>
PID_FILE="/var/run/$NAME.pid"
KAFKA_USER=kafka
<%- case @service_name
  when 'kafka' -%>
PGREP_PATTERN=kafka.Kafka

DAEMON="/opt/kafka/bin/kafka-server-start.sh"
DAEMON_OPTS="/opt/kafka/config/server.properties"

export KAFKA_JMX_OPTS="<%= @jmx_opts %>"
export KAFKA_LOG4J_OPTS="<%= @log4j_opts %>"
export KAFKA_HEAP_OPTS="<%= @heap_opts %>"

export KAFKA_OPTS="<%= @opts %>"
<%- when 'kafka-consumer' -%>
PGREP_PATTERN=kafka.tools.ConsoleConsumer

DAEMON="/opt/kafka/bin/kafka-console-consumer.sh"
DAEMON_OPTS="<% @consumer_service_config.sort.each do |k,v| -%><% unless v.to_s.strip.empty? -%>--<%= k -%>=<%= v.is_a?(Array) ? v.join(',') : v %> <% end -%><% end -%>"

export KAFKA_JMX_OPTS="<%= @consumer_jmx_opts %>"
export KAFKA_LOG4J_OPTS="<%= @consumer_log4j_opts %>"
<%- when 'kafka-mirror' -%>
PGREP_PATTERN=kafka.tools.MirrorMaker

DAEMON="/opt/kafka/bin/kafka-run-class.sh"
DAEMON_OPTS="kafka.tools.MirrorMaker --consumer.config <%= @consumer_config -%> --num.streams <%= @num_streams -%> --producer.config <%= @producer_config -%><%- if (scope.function_versioncmp([scope.lookupvar('kafka::version'), '0.9.0.0']) < 0) -%> --num.producers <%= @num_producers -%><%- end -%><%- if !@whitelist.eql?('') -%> --whitelist='<%= @whitelist -%>'<%- end %><%- if !@blacklist.eql?('') -%> --blacklist='<%= @blacklist -%>'<%- end -%>"

export KAFKA_HEAP_OPTS="-Xmx<%= @max_heap -%> -Xms<%= @max_heap -%>"
export KAFKA_JMX_OPTS="<%= @mirror_jmx_opts %>"
export KAFKA_LOG4J_OPTS="<%= @mirror_log4j_opts %>"
<%- when 'kafka-producer' -%>
PGREP_PATTERN=kafka.tools.ConsoleProducer

DAEMON="/opt/kafka/bin/kafka-console-producer.sh"
DAEMON_OPTS="<% @producer_service_config.sort.each do |k,v| -%><% unless v.to_s.strip.empty? -%>--<%= k -%>=<%= v.is_a?(Array) ? v.join(',') : v %> <% end -%><% end -%>"
PRODUCER_INPUT="<%= @input %>"

export KAFKA_JMX_OPTS="<%= @producer_jmx_opts %>"
export KAFKA_LOG4J_OPTS="<%= @producer_log4j_opts %>"
<%- end -%>

if [ -f /etc/default/kafka ]; then
    . /etc/default/kafka
fi

start() {
  ulimit -n 65536
  ulimit -s 10240
  ulimit -c unlimited
  if [ -f "$PID_FILE" ]; then
    PID=`cat "$PID_FILE"`
    if [ `ps -p "$PID" -o pid= || echo 1` -eq `pgrep -f "$PGREP_PATTERN" || echo 2` ] ; then
      echo "$PID_FILE exists, process is already running"
      exit 0
    fi
    echo "$PID_FILE exists but the process is not running. Deleting $PID_FILE and re-trying"
    rm -f -- "$PID_FILE"
    start
    return $?
  fi

  /bin/su "$KAFKA_USER" -c "KAFKA_JMX_OPTS=\"$KAFKA_JMX_OPTS\" $DAEMON $DAEMON_OPTS<%- if @service_name == 'kafka-producer' -%> $PRODUCER_INPUT<%- end -%> >/dev/null 2>&1 &"
  sleep 2
  PID=`pgrep -f "$PGREP_PATTERN"`
  if [ -z "$PID" ]; then
    echo "$NAME could not be started"
    exit 1
  fi

  echo "$PID" > "$PID_FILE";
  echo "$NAME started"
  return 0
}

stop() {
  if ! [ -f "$PID_FILE" ]; then
    echo -n "$PID_FILE does not exist"
    if PID=`pgrep -f "$PGREP_PATTERN"` ; then
      echo -n ", but process is running"
      echo "$PID" > "$PID_FILE"
    else
      echo -n ", and process is not running"
      return 1
    fi
  fi

  kill `cat "$PID_FILE"`;
  rm -f -- "$PID_FILE";
  echo "$NAME stopped"
  return 0
}

status() {
  if ! [ -f "$PID_FILE" ]; then
    echo "$NAME stopped"
    exit 1
  fi

  PID=`cat "$PID_FILE"`
  if ! [ `ps -p "$PID" -o pid= || echo 1` -eq `pgrep -f "$PGREP_PATTERN" || echo 2` ] ; then
    echo "$NAME stopped but pid file exists"
    exit 1
  fi

  echo "$NAME running with pid $PID"
  exit 0
}

case "$1" in
{'fraction_non_alphanumeric': 0.20439107229500242, 'fraction_numerical': 0.013100436681222707, 'mean_word_length': 3.6242288278182837, 'pattern_counts': {'":': 0, '<': 107, '<?xml version=': 0, '>': 112, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4695744', 'n_tokens_mistral': 3714, 'n_tokens_neox': 3395, 'n_words': 732}