<commit_before>#! /bin/sh
#
# This file is managed by Chef.
# Do NOT modify this file directly.
#
### BEGIN INIT INFO
# Provides:          cassandra
# Required-Start:    $remote_fs $network $named $time
# Required-Stop:     $remote_fs $network $named $time
# Should-Start:      ntp mdadm
# Should-Stop:       ntp mdadm
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: distributed storage system for structured data
# Description:       Cassandra is a distributed (peer-to-peer) system for
#                    the management and storage of structured data.
### END INIT INFO

DESC="Cassandra"
NAME=cassandra
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
export CASSANDRA_HOME=<%= node.cassandra.installation_dir %>
export CASSANDRA_CONF=<%= node.cassandra.conf_dir %>
USER=<%= node.cassandra.user %>
GROUP=<%= node.cassandra.user %>
WAIT_FOR_START=10
FD_LIMIT=100000
NODETOOL=$CASSANDRA_HOME/bin/nodetool

[ -e $CASSANDRA_HOME/lib/apache-cassandra-<%= node.cassandra.version %>.jar ] || exit 0
[ -e $CASSANDRA_CONF/cassandra.yaml ] || exit 0
[ -e $CASSANDRA_CONF/cassandra-env.sh ] || exit 0
[ -e $CASSANDRA_HOME/bin/cassandra ] || exit 0
[ -e $NODETOOL ] || exit 0


# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

# Return
#   0 if daemon is running
#   1 if daemon is not running
is_running()
{
    [ -f $PIDFILE -a -d /proc/$(cat $PIDFILE) ] && return 0
    return 1
}

# Return
#   0 if daemon has been started
#   1 if daemon was already running
#   2 if daemon could not be started
do_start()
{
    is_running && return 1

    ulimit -l unlimited
    ulimit -n "$FD_LIMIT"

    touch $PIDFILE
    chown $USER:$GROUP $PIDFILE

    start-stop-daemon --start \
        --quiet \
        --background \
        --chdir / \
        --oknodo \
        --chuid $USER:$GROUP \
        --exec /bin/bash \
        --pidfile $PIDFILE \
        -- -c "$CASSANDRA_HOME/bin/cassandra -p $PIDFILE > <%= node.cassandra.log_dir %>/boot.log 2>&1"

    is_running && return 0

    for tries in `seq $WAIT_FOR_START`; do
        sleep 1
        is_running && return 0
    done

    return 2
}

# Returns
#   0 if daemon has been stopped
#   1 if daemon was already stopped
#   2 if daemon could not be stopped
#   other if a failure occurred
do_stop()
{
    is_running || return 1

  # Disable Thrift, Mark node down for client 
  echo "executing nodetool -h 0 disablethrift .."
  $NODETOOL -h 0 disablethrift
  [ $? -eq 0 ] || {
    echo "failed to execute disablethrift .."
  }
  sleep 2

  # Disabling Gossip, Mark node down for cluster
  echo "executing nodetool -h 0 disablegossip .."
  $NODETOOL -h 0 disablegossip
  [ $? -eq 0 ] || {
    echo "failed to execute disablegossip .."
  }
  sleep 2

  # Drain node for existing connections, Always safe even takes long time
  echo "executing nodetool -h 0 drain .."
  $NODETOOL -h 0 drain
  [ $? -eq 0 ] || {
    echo "failed to execute drain .."
  }
  sleep 2
  
    start-stop-daemon --stop \
        --pidfile $PIDFILE \
        --user $USER \
        --retry TERM/30/KILL/5

    is_running && return 2

    return 0
}

case "$1" in
    start)
        echo "Starting $DESC"
        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
        do_start
        case "$?" in
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
    stop)
        echo "Stopping $DESC"
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
        do_stop
        case "$?" in
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
    restart|force-reload)
        echo "Restarting $DESC"
        log_daemon_msg "Restarting $DESC" "$NAME"
        do_stop
        case "$?" in
          0|1)
                do_start
                case "$?" in
                        0) log_end_msg 0 ;;
                        1) log_end_msg 1 ;; # Old process is still running
                        *) log_end_msg 1 ;; # Failed to start
                esac
                ;;
          *)
                # Failed to stop
                log_end_msg 1
                ;;
        esac
        ;;
    status)
        is_running
        stat=$?
        case "$stat" in
            0) log_success_msg "$DESC is running" ;;
            *) log_success_msg "$DESC is not running" ;;
        esac
        exit "$stat"
        ;;
    *)
        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
        exit 3
        ;;
esac

:

# vi:ai sw=4 ts=4 tw=0 et
<commit_msg>Set FD_LIMIT by appropriate node attribute<commit_after>#! /bin/sh
#
# This file is managed by Chef.
# Do NOT modify this file directly.
#
### BEGIN INIT INFO
# Provides:          cassandra
# Required-Start:    $remote_fs $network $named $time
# Required-Stop:     $remote_fs $network $named $time
# Should-Start:      ntp mdadm
# Should-Stop:       ntp mdadm
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: distributed storage system for structured data
# Description:       Cassandra is a distributed (peer-to-peer) system for
#                    the management and storage of structured data.
### END INIT INFO

DESC="Cassandra"
NAME=cassandra
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
export CASSANDRA_HOME=<%= node.cassandra.installation_dir %>
export CASSANDRA_CONF=<%= node.cassandra.conf_dir %>
USER=<%= node.cassandra.user %>
GROUP=<%= node.cassandra.user %>
WAIT_FOR_START=10
FD_LIMIT=<%= node.cassandra.limits.nofile %>
NODETOOL=$CASSANDRA_HOME/bin/nodetool

[ -e $CASSANDRA_HOME/lib/apache-cassandra-<%= node.cassandra.version %>.jar ] || exit 0
[ -e $CASSANDRA_CONF/cassandra.yaml ] || exit 0
[ -e $CASSANDRA_CONF/cassandra-env.sh ] || exit 0
[ -e $CASSANDRA_HOME/bin/cassandra ] || exit 0
[ -e $NODETOOL ] || exit 0


# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

# Return
#   0 if daemon is running
#   1 if daemon is not running
is_running()
{
    [ -f $PIDFILE -a -d /proc/$(cat $PIDFILE) ] && return 0
    return 1
}

# Return
#   0 if daemon has been started
#   1 if daemon was already running
#   2 if daemon could not be started
do_start()
{
    is_running && return 1

    ulimit -l unlimited
    ulimit -n "$FD_LIMIT"

    touch $PIDFILE
    chown $USER:$GROUP $PIDFILE

    start-stop-daemon --start \
        --quiet \
        --background \
        --chdir / \
        --oknodo \
        --chuid $USER:$GROUP \
        --exec /bin/bash \
        --pidfile $PIDFILE \
        -- -c "$CASSANDRA_HOME/bin/cassandra -p $PIDFILE > <%= node.cassandra.log_dir %>/boot.log 2>&1"

    is_running && return 0

    for tries in `seq $WAIT_FOR_START`; do
        sleep 1
        is_running && return 0
    done

    return 2
}

# Returns
#   0 if daemon has been stopped
#   1 if daemon was already stopped
#   2 if daemon could not be stopped
#   other if a failure occurred
do_stop()
{
    is_running || return 1

  # Disable Thrift, Mark node down for client 
  echo "executing nodetool -h 0 disablethrift .."
  $NODETOOL -h 0 disablethrift
  [ $? -eq 0 ] || {
    echo "failed to execute disablethrift .."
  }
  sleep 2

  # Disabling Gossip, Mark node down for cluster
  echo "executing nodetool -h 0 disablegossip .."
  $NODETOOL -h 0 disablegossip
  [ $? -eq 0 ] || {
    echo "failed to execute disablegossip .."
  }
  sleep 2

  # Drain node for existing connections, Always safe even takes long time
  echo "executing nodetool -h 0 drain .."
  $NODETOOL -h 0 drain
  [ $? -eq 0 ] || {
    echo "failed to execute drain .."
  }
  sleep 2
  
    start-stop-daemon --stop \
        --pidfile $PIDFILE \
        --user $USER \
        --retry TERM/30/KILL/5

    is_running && return 2

    return 0
}

case "$1" in
    start)
        echo "Starting $DESC"
        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
        do_start
        case "$?" in
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
    stop)
        echo "Stopping $DESC"
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
        do_stop
        case "$?" in
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
    restart|force-reload)
        echo "Restarting $DESC"
        log_daemon_msg "Restarting $DESC" "$NAME"
        do_stop
        case "$?" in
          0|1)
                do_start
                case "$?" in
                        0) log_end_msg 0 ;;
                        1) log_end_msg 1 ;; # Old process is still running
                        *) log_end_msg 1 ;; # Failed to start
                esac
                ;;
          *)
                # Failed to stop
                log_end_msg 1
                ;;
        esac
        ;;
    status)
        is_running
        stat=$?
        case "$stat" in
            0) log_success_msg "$DESC is running" ;;
            *) log_success_msg "$DESC is not running" ;;
        esac
        exit "$stat"
        ;;
    *)
        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
        exit 3
        ;;
esac

:

# vi:ai sw=4 ts=4 tw=0 et

{'fraction_non_alphanumeric': 0.12139667072675599, 'fraction_numerical': 0.016240357287860333, 'mean_word_length': 1.9597476719735656, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '6071463', 'n_tokens_mistral': 3531, 'n_tokens_neox': 3309, 'n_words': 972}