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