Skip to content

Instantly share code, notes, and snippets.

@unusedPhD
Created November 11, 2015 01:49
Show Gist options
  • Save unusedPhD/417640e9aa4844895b0f to your computer and use it in GitHub Desktop.
Save unusedPhD/417640e9aa4844895b0f to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment