2010-08-28 14:11:09 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2014-04-26 14:17:33 +02:00
|
|
|
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"
|
2010-08-28 14:11:09 +02:00
|
|
|
|
2014-04-26 14:17:33 +02:00
|
|
|
PRG="cassandra"
|
|
|
|
DIR="/opt/apache-cassandra/bin/"
|
|
|
|
PID_DIRECTORY="/var/run"
|
|
|
|
PID_FILE="$PID_DIRECTORY/$PRG.pid"
|
2010-08-28 14:11:09 +02:00
|
|
|
|
2014-04-26 14:17:33 +02:00
|
|
|
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
|
2010-08-28 14:11:09 +02:00
|
|
|
}
|
|
|
|
|
2014-04-26 14:17:33 +02:00
|
|
|
function status() {
|
|
|
|
isRunning
|
|
|
|
STATUS=$?
|
|
|
|
if [[ $STATUS -eq 0 ]]; then
|
|
|
|
echo -e "Service $PRG is running"
|
|
|
|
else
|
|
|
|
echo -e "Service $PRG is not running."
|
2010-08-28 14:11:09 +02:00
|
|
|
fi
|
2014-04-26 14:17:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2010-08-28 14:11:09 +02:00
|
|
|
|
|
|
|
case $1 in
|
2014-04-26 14:17:33 +02:00
|
|
|
start)
|
|
|
|
start
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
stop
|
|
|
|
;;
|
|
|
|
restart)
|
|
|
|
start
|
|
|
|
sleep 1
|
|
|
|
stop
|
|
|
|
;;
|
|
|
|
status)
|
|
|
|
status
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Usage: $0 {start|stop|restart|status}"
|
|
|
|
exit 1
|
|
|
|
;;
|
2010-08-28 14:11:09 +02:00
|
|
|
esac
|
|
|
|
|
2014-04-26 14:17:33 +02:00
|
|
|
exit 0
|