blob: 3bc62e4a473787af2ea209da2a9e295982be1581 [file] [log] [blame]
Ubuntuc57c5f92013-02-06 21:11:43 +00001#!/bin/bash
2
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +00003# Set paths
Masayoshi Kobayashi20224872013-06-20 17:00:17 -07004ONOS_HOME=`dirname $0`
HIGUCHI Yuta76b0ad32013-06-11 15:06:21 -07005CASSANDRA_DIR=${HOME}/apache-cassandra-1.2.4
Ubuntuc57c5f92013-02-06 21:11:43 +00006LOGDIR=${HOME}/ONOS/onos-logs
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +00007CASSANDRA_LOG=$LOGDIR/cassandara.`hostname`.log
Ubuntuc57c5f92013-02-06 21:11:43 +00008
9function lotate {
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000010 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
Ubuntuc57c5f92013-02-06 21:11:43 +000019 fi
Ubuntuc57c5f92013-02-06 21:11:43 +000020}
21
22function 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 Kobayashicf909f92013-06-21 13:28:22 -070033 cp ${ONOS_HOME}/conf/cassandra.yaml $CASSANDRA_DIR/conf
Ubuntuc57c5f92013-02-06 21:11:43 +000034 $CASSANDRA_DIR/bin/cassandra > $CASSANDRA_LOG 2>&1
35}
36
37function 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 Radoslavovb531d712013-03-29 15:13:43 -070043 kill -KILL $p
Ubuntuc57c5f92013-02-06 21:11:43 +000044 echo "Killed existing prosess (pid: $p)"
45 fi
46 done
47}
48
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +000049function deldb {
Ubuntuc57c5f92013-02-06 21:11:43 +000050# # Delete the berkeley db database
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +000051 if [ -d "/tmp/cassandra.titan" ]; then
52 echo "deleting berkeley db dir"
53 sudo rm -rf /tmp/cassandra.titan
54 fi
55}
Ubuntuc57c5f92013-02-06 21:11:43 +000056
57case "$1" in
58 start)
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +000059 deldb
Masayoshi Kobayashi20224872013-06-20 17:00:17 -070060 cp $ONOS_HOME/conf/cassandra.titan /tmp
Ubuntuc57c5f92013-02-06 21:11:43 +000061 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
78esac