Skip to content

Instantly share code, notes, and snippets.

@yomon8
Forked from sgomezvillamor/etc-init.d-cassandra
Last active February 24, 2016 07:08
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save yomon8/cb6000659dbefe80149f to your computer and use it in GitHub Desktop.
/etc/init.d/cassandra for CentOS
#!/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=/usr/local/cassandra
CASS_BIN=$CASS_HOME/bin/cassandra
CASS_USER="cassandra"
CASS_LOG=/var/log/cassandra/system.log
CASS_PID=/var/run/cassandra/cassandra.pid
if [ ! -f $CASS_BIN ]; then
echo "File not found: $CASS_BIN"
exit 1
fi
RETVAL=0
start() {
if [ -f $CASS_PID ] && checkpid `cat $CASS_PID`; then
echo "Cassandra is already running."
exit 0
fi
echo -n $"Starting $prog: "
su $CASS_USER -c "$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
echo "Cassandra is already stopped."
exit 1
fi
echo -n $"Stopping $prog: "
if kill `cat $CASS_PID`; then
RETVAL=1
echo_success
else
RETVAL=1
echo_failure
fi
echo
[ $RETVAL = 0 ]
}
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
usleep 500000
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