summaryrefslogtreecommitdiff
path: root/system/apache-cassandra/rc.cassandra
diff options
context:
space:
mode:
Diffstat (limited to 'system/apache-cassandra/rc.cassandra')
-rw-r--r--system/apache-cassandra/rc.cassandra95
1 files changed, 65 insertions, 30 deletions
diff --git a/system/apache-cassandra/rc.cassandra b/system/apache-cassandra/rc.cassandra
index 97a8e8f172..8fa5d9a7ce 100644
--- a/system/apache-cassandra/rc.cassandra
+++ b/system/apache-cassandra/rc.cassandra
@@ -1,41 +1,76 @@
#!/bin/bash
-set -e
+export JAVA="/usr/lib64/java/bin/java"
+export CASSANDRA_HOME="/opt/apache-cassandra"
+export CASSANDRA_CONF="$CASSANDRA_HOME/conf"
+export CASSANDRA_INCLUDE="$CASSANDRA_HOME/tools/bin/cassandra.in.sh"
-CASSANDRA_BIN_PATH="/opt/apache-cassandra/bin"
-PID_FILE="/var/run/cassandra.pid"
+PRG="cassandra"
+DIR="/opt/apache-cassandra/bin/"
+PID_DIRECTORY="/var/run"
+PID_FILE="$PID_DIRECTORY/$PRG.pid"
-stop_cassandra(){
- kill `cat $PID_FILE`
- rm -f $PID_FILE
+function isRunning() {
+[[ ! -f "$PID_FILE" ]] && return 1
+PID="$(<"$PID_FILE")"
+[[ -z "$PID" ]] && return 1
+[[ ! $(ps -p $PID | grep $PID) == "" ]] && RV=0 || RV=1
+return $RV
}
-if [ ! -d $CASSANDRA_BIN_PATH ]; then
- echo
- echo "Cassandra is not installed on this machine!"
- echo "Please check cassandra installation or set var CASSANDRA_BIN_PATH properly"
- echo
- exit 1
+function status() {
+isRunning
+STATUS=$?
+if [[ $STATUS -eq 0 ]]; then
+ echo -e "Service $PRG is running"
+else
+ echo -e "Service $PRG is not running."
fi
+}
+
+function start() {
+isRunning
+STATUS=$?
+if [[ $STATUS -eq 0 ]]; then
+ echo -e "Service $PRG is already running."
+else
+ echo -e "Start service $PRG"
+ $DIR$PRG -p $PID_FILE > /dev/null 2>&1 &
+fi
+}
+
+function stop() {
+isRunning
+STATUS=$?
+if [[ $STATUS -eq 0 ]]; then
+ echo -e "Stop service $PRG"
+ PID="$(<"$PID_FILE")"
+ kill $PID
+ rm "$PID_FILE"
+else
+ echo -e "Service $PRG not running."
+fi
+}
case $1 in
- start)
- echo " * Starting Cassandra..."
- $CASSANDRA_BIN_PATH/cassandra -p $PID_FILE > /dev/null 2>&1
- ;;
- stop)
- echo " * Stopping Cassandra..."
- stop_cassandra
- ;;
- restart)
- echo " * Rerstarting Cassandra..."
- stop_cassandra
- sleep 3
- $CASSANDRA_BIN_PATH/cassandra -p $PID_FILE > /dev/null 2>&1
- ;;
- *)
- echo " * Please provide correct option between start|stop|restart"
- ;;
+ start)
+ start
+ ;;
+ stop)
+ stop
+ ;;
+ restart)
+ start
+ sleep 1
+ stop
+ ;;
+ status)
+ status
+ ;;
+ *)
+ echo "Usage: $0 {start|stop|restart|status}"
+ exit 1
+ ;;
esac
-
+exit 0