Ubuntu | c57c5f9 | 2013-02-06 21:11:43 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | CASSANDRA_DIR=${HOME}/apache-cassandra-1.1.4 |
| 4 | LOGDIR=${HOME}/ONOS/onos-logs |
| 5 | CASSANDRA_LOG=$LOGDIR/cassandara.onos1vpc.log |
| 6 | |
| 7 | function lotate { |
| 8 | logfile=$1 |
| 9 | nr_max=$2 |
| 10 | if [ -f $logfile ]; then |
| 11 | for i in `seq $(expr 10 - 1) -1 1`; do |
| 12 | if [ -f ${logfile}.${i} ]; then |
| 13 | mv -f ${logfile}.${i} ${logfile}.`expr $i + 1` |
| 14 | fi |
| 15 | done |
| 16 | mv $logfile $logfile.1 |
| 17 | fi |
| 18 | } |
| 19 | |
| 20 | function start { |
| 21 | if [ ! -d ${LOGDIR} ]; then |
| 22 | mkdir -p ${LOGDIR} |
| 23 | fi |
| 24 | echo "rotate log: $log" |
| 25 | if [ -f $CASSANDRA_LOG ]; then |
| 26 | lotate $CASSANDRA_LOG |
| 27 | fi |
| 28 | |
| 29 | # Run cassandra |
| 30 | echo "Starting cassandra" |
| 31 | $CASSANDRA_DIR/bin/cassandra > $CASSANDRA_LOG 2>&1 |
| 32 | } |
| 33 | |
| 34 | function stop { |
| 35 | # Kill the existing processes |
| 36 | capid=`ps -edalf |grep java |grep apache-cassandra | awk '{print $4}'` |
| 37 | pids="$capid" |
| 38 | for p in ${pids}; do |
| 39 | if [ x$p != "x" ]; then |
| 40 | sudo kill -KILL $p |
| 41 | echo "Killed existing prosess (pid: $p)" |
| 42 | fi |
| 43 | done |
| 44 | } |
| 45 | |
| 46 | #function deldb { |
| 47 | # # Delete the berkeley db database |
| 48 | # if [ -d "/tmp/cassandra.titan" ]; then |
| 49 | # rm -rf /tmp/cassandra.titan |
| 50 | # mkdir /tmp/cassandra.titan |
| 51 | # fi |
| 52 | #} |
| 53 | |
| 54 | case "$1" in |
| 55 | start) |
| 56 | stop |
| 57 | start |
| 58 | ;; |
| 59 | stop) |
| 60 | stop |
| 61 | ;; |
| 62 | # deldb) |
| 63 | # deldb |
| 64 | # ;; |
| 65 | status) |
| 66 | n=`ps -edalf |grep java |grep apache-cassandra | wc -l` |
| 67 | echo "$n instance of cassandra running" |
| 68 | $CASSANDRA_DIR/bin/nodetool ring |
| 69 | ;; |
| 70 | *) |
| 71 | echo "Usage: $0 {start|stop|restart|status}" |
| 72 | exit 1 |
| 73 | esac |