unusedPhD
11/11/2015 - 1:49 AM

init.d file for cassandra with ulimit -n call to increase limit

init.d file for cassandra with ulimit -n call to increase limit

#!/bin/bash

CASSANDRA=/opt/cassandra/bin/cassandra
PIDFILE=/var/run/cassandra.pid
LOGFILE=/var/log/cassandra/init.log
PARAMS="-p ${PIDFILE}"

writelog() {
  echo "`date` : $1" >> "$LOG"
}

log_clear(){
    echo "`date` - cleared" > $LOG
}

start(){
  if [ ! -f ${PIDFILE} ];
    then
      echo "Starting Cassandra..."
      ulimit -n 100000
      start-stop-daemon --start --pidfile ${PIDFILE} --exec ${CASSANDRA}/cassandra -- ${PARAMS} \ >> ${LOGFILE}
      sleep 3
      echo "Cassandra started"
    else
      echo "Cassandra already running"
  fi
}

stop(){
  if [ ! -f ${PIDFILE} ] ; then
    echo "Cassandra is not running"
  else
    echo "Stopping Cassandra..."
    pid_no=`cat ${PIDFILE}`
    kill $pid_no
    rm ${PIDFILE}
    sleep 2
  fi
}

stop(){
  if [ ! -f ${PIDFILE} ] ; then
    echo "Cassandra is not running"
  else
    echo "Stopping Cassandra..."
    pid_no=`cat ${PIDFILE}`
    kill $pid_no
    rm ${PIDFILE}
    sleep 2
  fi
}

status(){
  if [ ! -f $PIDFILE ] ; then
    echo "Cassandra is not running"
  else
    echo "Cassandra running; pid: " `cat $PID`
  fi
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    stop
    start
    ;;
  status)
    status
    ;;
  logclear)
    log_clear
    ;;
  *)
    echo "Usage: sudo service cassandra (start|stop|restart|status|logclear)"
    ;;
esac

exit 1