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