Skip to content

Instantly share code, notes, and snippets.

@ShahBinoy
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShahBinoy/54ebc96839b65ce92322 to your computer and use it in GitHub Desktop.
Save ShahBinoy/54ebc96839b65ce92322 to your computer and use it in GitHub Desktop.
#!/bin/bash
# init script for Cassandra.
# chkconfig: 2345 90 10
# description: Cassandra
# script slightly modified from
# http://blog.milford.io/2010/06/installing-apache-cassandra-on-centos/
. /etc/rc.d/init.d/functions
CASS_HOME=/opt/cassandra
CASS_BIN=$CASS_HOME/bin/cassandra
CASS_LOG=/var/log/cassandra/system.log
CASS_USER="cassandra"
CASS_PID=/var/run/cassandra/cassandra.pid
if [ ! -f $CASS_BIN ]; then
echo "File not found: $CASS_BIN"
exit 1
fi
RETVAL=0
prog=`basename $0`
start() {
if [ -f $CASS_PID ] && checkpid `cat $CASS_PID`; then
echo "Cassandra is already running."
exit 0
fi
touch $CASS_LOG
chown $CASS_USER $CASS_LOG
echo -n $"Starting $prog: "
daemon --user $CASS_USER $CASS_BIN -p $CASS_PID >> $CASS_LOG 2>&1
usleep 500000
RETVAL=$?
if [ "$RETVAL" = "0" ]; then
echo_success
else
echo_failure
fi
echo
return $RETVAL
}
stop() {
# check if the process is already stopped by seeing if the pid file exists.
if [ ! -f $CASS_PID ]; then
RETVAL=1
echo_failure
else
echo -n $"Stopping $prog: "
pid=`cat $CASS_PID`
if kill $pid; then
while [ -e /proc/$pid ]; do
echo -n "."
sleep 1
done
RETVAL=0
echo_success
else
RETVAL=1
echo_failure
fi
echo
[ $RETVAL = 0 ]
fi
}
status_fn() {
if [ -f $CASS_PID ] && checkpid `cat $CASS_PID`; then
echo "Cassandra is running."
exit 0
else
echo "Cassandra is stopped."
exit 1
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status_fn
;;
restart)
stop
start
;;
*)
echo $"Usage: $prog {start|stop|restart|status}"
RETVAL=3
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment