blob: 22071e2d70f9540139237e75e50ffca8661ad167 [file] [log] [blame]
Masayoshi Kobayashif0057de2013-06-20 16:55:22 -07001CASSANDRA_DIR='${HOME}/apache-cassandra-1.1.4'
2ZK_DIR='${HOME}/zookeeper-3.4.5'
3ONOS_DIR='${HOME}/ONOS'
Masayoshi Kobayashi972b8462013-06-21 15:46:38 -07004
Masayoshi Kobayashif358ff52013-03-22 00:31:59 +00005ZK_LIB='/var/lib/zookeeper'
6CASSANDRA_LIB='/var/lib/cassandra'
7
8if [ x$CLUSTER == "x" ]; then
9 echo "CLUSTER is not set. Exitting."
10 exit
11fi
12if [ x$ONOS_CLUSTER_BASENAME == "x" ]; then
13 echo "ONOS_CLUSTER_BASENAME is not set. Exitting"
14 exit
15fi
16if [ x$ONOS_CLUSTER_NR_NODES == "x" ]; then
17 echo "ONOS_CLUSTER_NR_NODES is not set. Exitting"
18 exit
19fi
20
21export basename=$ONOS_CLUSTER_BASENAME
22export nr_nodes=$ONOS_CLUSTER_NR_NODES
23
24checkcluster () {
25 dsh -g $basename 'uname -a'
26}
27
28zk () {
29 case "$1" in
30 start)
31 echo "Starting ZK.."
Masayoshi Kobayashi99730902013-06-27 23:23:20 -070032# dsh -g $basename "$ZK_DIR/bin/zkServer.sh start"
33 dsh -g $basename 'cd ONOS; ./start-zk.sh start'
Masayoshi Kobayashif358ff52013-03-22 00:31:59 +000034 while [ 1 ]; do
Masayoshi Kobayashi99730902013-06-27 23:23:20 -070035# nup=`dsh -g $basename "$ZK_DIR/bin/zkServer.sh status" | grep "Mode" | egrep "leader|follower" | wc -l`
36 nup=`dsh -g $basename "cd ONOS; ./start-zk.sh status" | grep "Mode" | egrep "leader|follower|standalone" | wc -l`
Masayoshi Kobayashi93522412013-08-01 17:28:34 -070037 echo "check status"
Masayoshi Kobayashif358ff52013-03-22 00:31:59 +000038 if [ $nup == $nr_nodes ]; then
39 echo "everybody's up: $nup up of of $nr_nodes"
40 echo "ZK started"
41 break;
42 fi
43 echo "waiting for everybody's up: $nup up of of $nr_nodes"
44 sleep 1
45 done
46 ;;
47 stop)
48 echo "Stopping ZK.."
49 dsh -g $basename "$ZK_DIR/bin/zkServer.sh stop"
50 ;;
51 status)
52 echo "Checking ZK Status"
53 dsh -g $basename "$ZK_DIR/bin/zkServer.sh status"
54 ;;
55 esac
56}
57
58cassandra () {
59 case "$1" in
60 start)
61 echo "Starting Cassandra.."
62 echo " start cassandra at the seed node"
63 dsh -w ${basename}1 "cd $ONOS_DIR; ./start-cassandra.sh start"
64 sleep 1
65 echo " start cassandra in rest nodes"
66 dsh -g ${basename} -x ${basename}1 "cd $ONOS_DIR; ./start-cassandra.sh start"
67 while [ 1 ]; do
68 echo $$
69 dsh -w ${basename}1 "cd $ONOS_DIR; ./start-cassandra.sh status" > .cassandra_check.$$
70 cat .cassandra_check.$$
71 nup=`cat .cassandra_check.$$ | grep Normal |grep Up| wc -l`
72 if [ $nup == $nr_nodes ]; then
73 echo "everybody's up: $nup up of of $nr_nodes"
74 echo "Cassandra started"
75 break;
76 fi
77 echo "waiting for everybody's up: $nup up of of $nr_nodes"
78 sleep 1
79 done
80 ;;
Masayoshi Kobayashif238c9e2013-06-10 01:41:13 +000081 bootup)
82 echo "Removing old Cassandra data and logs"
83 dsh -g ${basename} "rm -rf /var/lib/cassandra/*"
84 dsh -g ${basename} "rm -rf /var/log/cassandra/*"
85
86 echo "Starting Cassandra nodes one by one..."
87 for (( c=1; c<=$nr_nodes; c++ ))
88 do
89 echo "Starting node ${basename}${c}"
90 dsh -g ${basename} -w ${basename}${c} "cd $ONOS_DIR; ./start-cassandra.sh start"
91
92 #Wait until it's up
93 while [ 1 ]; do
94 echo $$
95 dsh -w ${basename}1 "cd $ONOS_DIR; ./start-cassandra.sh status" > .cassandra_check.$$
96 cat .cassandra_check.$$
97 nup=`cat .cassandra_check.$$ | grep Normal |grep Up| wc -l`
98 if [ $nup == $c ]; then
99 echo "New node up: $nup up of of $nr_nodes"
100 break;
101 fi
102 echo "Waiting for new node to come up: $nup up of of $nr_nodes"
103 sleep 5
104 done
105 done
106 ;;
Masayoshi Kobayashif358ff52013-03-22 00:31:59 +0000107 stop)
108 echo "Stopping Cassandra.."
109 dsh -g ${basename} "cd $ONOS_DIR; ./start-cassandra.sh stop"
110 ;;
111 cleandb)
112 echo "Removing all data in db"
113 dsh -w ${basename}1 "cd $ONOS_DIR; ./scripts/cleanup-cassandra.sh"
114 ;;
Masayoshi Kobayashibd3d00e2013-04-03 22:59:57 +0000115 checkdb)
116 echo "Check DB Status"
117 dsh -w ${basename}1 "cd $ONOS_DIR; ./scripts/check-db-status.sh"
118 ;;
Masayoshi Kobayashif358ff52013-03-22 00:31:59 +0000119 status)
120 echo "Checking Cassandra Status"
121 dsh -w ${basename}1 "cd $ONOS_DIR; ./start-cassandra.sh status"
122 ;;
123 esac
124}
125
126onos () {
127 case "$1" in
128 start)
Masayoshi Kobayashi0ab03da2013-03-26 00:43:02 +0000129 if [ x$2 == "x" -o x$2 == "xall" ]; then
130 echo "Starting ONOS on all nodes"
Masayoshi Kobayashi99730902013-06-27 23:23:20 -0700131 dsh -w ${basename}1 "cd $ONOS_DIR; ./start-onos.sh start"
132 sleep 3
133 dsh -g ${basename} -x ${basename}1 "cd $ONOS_DIR; ./start-onos.sh start"
Masayoshi Kobayashi4a1542b2013-04-02 22:34:13 +0000134 dsh -g ${basename} "cd $ONOS_DIR; ./start-rest.sh start"
Masayoshi Kobayashi0ab03da2013-03-26 00:43:02 +0000135 else
136 echo "Starting ONOS on ${basename}$2"
137 dsh -w ${basename}$2 "cd $ONOS_DIR; ./start-onos.sh start"
138 fi
Masayoshi Kobayashif358ff52013-03-22 00:31:59 +0000139 ;;
140 stop)
Masayoshi Kobayashi0ab03da2013-03-26 00:43:02 +0000141 if [ x$2 == "x" -o x$2 == "xall" ]; then
142 echo "Stop ONOS on all nodes"
143 dsh -g ${basename} "cd $ONOS_DIR; ./start-onos.sh stop"
144 else
145 echo "Stop ONOS on ${basename}$2"
146 dsh -w ${basename}$2 "cd $ONOS_DIR; ./start-onos.sh stop"
147 fi
Masayoshi Kobayashif358ff52013-03-22 00:31:59 +0000148 ;;
149 status)
150 echo "Checking ONOS Status"
151 dsh -g ${basename} "cd $ONOS_DIR; ./start-onos.sh status"
152 ;;
153 esac
154}
Masayoshi Kobayashi0ab03da2013-03-26 00:43:02 +0000155switch () {
156 case "$1" in
157 local)
158 if [ x$2 == "x" -o x$2 == "xall" ]; then
159 echo "set all switches point to local controller"
160 dsh -g ${basename} "$ONOS_DIR/scripts/ctrl-local.sh"
161 else
162 dsh -w ${basename}$2 "$ONOS_DIR/scripts/ctrl-local.sh"
163 fi
164 ;;
165 all)
166 if [ x$2 == "x" -o x$2 == "xall" ]; then
167 echo "set all non-core switches point to all non-core controllers"
Masayoshi Kobayashi4a1542b2013-04-02 22:34:13 +0000168 dsh -g ${basename} -x ${basename}1 "$ONOS_DIR/scripts/ctrl-add-ext.sh"
Masayoshi Kobayashi0ab03da2013-03-26 00:43:02 +0000169 else
Masayoshi Kobayashi4a1542b2013-04-02 22:34:13 +0000170 dsh -w ${basename}$2 "$ONOS_DIR/scripts/ctrl-add-ext.sh"
Masayoshi Kobayashi0ab03da2013-03-26 00:43:02 +0000171 fi
172 ;;
173 none)
174 if [ x$2 == "x" -o x$2 == "xall" ]; then
175 echo "all non-core switches loose controller"
176 dsh -g ${basename} -x ${basename}1 "$ONOS_DIR/scripts/ctrl-none.sh"
177 else
178 dsh -w ${basename}$2 "$ONOS_DIR/scripts/ctrl-none.sh"
179 fi
180 ;;
181 esac
182}