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 |
Masayoshi Kobayashi | 2022487 | 2013-06-20 17:00:17 -0700 | [diff] [blame] | 4 | ONOS_HOME=`dirname $0` |
HIGUCHI Yuta | 76b0ad3 | 2013-06-11 15:06:21 -0700 | [diff] [blame] | 5 | CASSANDRA_DIR=${HOME}/apache-cassandra-1.2.4 |
Yuta HIGUCHI | f2583fb | 2014-01-15 20:20:12 -0800 | [diff] [blame] | 6 | LOGDIR=${ONOS_HOME}/onos-logs |
Masayoshi Kobayashi | 9973090 | 2013-06-27 23:23:20 -0700 | [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" |
Masayoshi Kobayashi | 9973090 | 2013-06-27 23:23:20 -0700 | [diff] [blame] | 33 | # echo "[31;48m[WARNING] This script copies conf/cassandra.yaml to $CASSANDRA_DIR/conf/cassandra.yaml (overwrites)[0m" |
| 34 | # echo "[31;48moriginal cassandra.yaml was backed up as cassandra.yaml.backup[0m" |
| 35 | # id=`hostid` |
| 36 | # cp ${CASSANDRA_DIR}/conf/cassandra.yaml $CASSANDRA_DIR/conf/cassandra.yaml.backup |
| 37 | # cp ${ONOS_HOME}/conf/cassandra.yaml.${id} $CASSANDRA_DIR/conf |
Ubuntu | c57c5f9 | 2013-02-06 21:11:43 +0000 | [diff] [blame] | 38 | $CASSANDRA_DIR/bin/cassandra > $CASSANDRA_LOG 2>&1 |
| 39 | } |
| 40 | |
| 41 | function stop { |
| 42 | # Kill the existing processes |
| 43 | capid=`ps -edalf |grep java |grep apache-cassandra | awk '{print $4}'` |
| 44 | pids="$capid" |
| 45 | for p in ${pids}; do |
| 46 | if [ x$p != "x" ]; then |
Pavlin Radoslavov | b531d71 | 2013-03-29 15:13:43 -0700 | [diff] [blame] | 47 | kill -KILL $p |
Ubuntu | c57c5f9 | 2013-02-06 21:11:43 +0000 | [diff] [blame] | 48 | echo "Killed existing prosess (pid: $p)" |
| 49 | fi |
| 50 | done |
| 51 | } |
| 52 | |
Masayoshi Kobayashi | cbd5e0a | 2013-02-25 19:00:19 +0000 | [diff] [blame] | 53 | function deldb { |
Ubuntu | c57c5f9 | 2013-02-06 21:11:43 +0000 | [diff] [blame] | 54 | # # Delete the berkeley db database |
Masayoshi Kobayashi | cbd5e0a | 2013-02-25 19:00:19 +0000 | [diff] [blame] | 55 | if [ -d "/tmp/cassandra.titan" ]; then |
| 56 | echo "deleting berkeley db dir" |
| 57 | sudo rm -rf /tmp/cassandra.titan |
| 58 | fi |
| 59 | } |
Ubuntu | c57c5f9 | 2013-02-06 21:11:43 +0000 | [diff] [blame] | 60 | |
| 61 | case "$1" in |
| 62 | start) |
Masayoshi Kobayashi | cbd5e0a | 2013-02-25 19:00:19 +0000 | [diff] [blame] | 63 | deldb |
Masayoshi Kobayashi | 2022487 | 2013-06-20 17:00:17 -0700 | [diff] [blame] | 64 | cp $ONOS_HOME/conf/cassandra.titan /tmp |
Ubuntu | c57c5f9 | 2013-02-06 21:11:43 +0000 | [diff] [blame] | 65 | stop |
| 66 | start |
| 67 | ;; |
| 68 | stop) |
| 69 | stop |
| 70 | ;; |
| 71 | # deldb) |
| 72 | # deldb |
| 73 | # ;; |
| 74 | status) |
| 75 | n=`ps -edalf |grep java |grep apache-cassandra | wc -l` |
| 76 | echo "$n instance of cassandra running" |
| 77 | $CASSANDRA_DIR/bin/nodetool ring |
| 78 | ;; |
| 79 | *) |
| 80 | echo "Usage: $0 {start|stop|restart|status}" |
| 81 | exit 1 |
| 82 | esac |