blob: b6f4c1e0041707f1952f862a1fbe322ba31d574b [file] [log] [blame]
Masayoshi Kobayashif358ff52013-03-22 00:31:59 +00001USERNAME=ubuntu
2CASSANDRA_DIR='/home/ubuntu/apache-cassandra-1.1.4'
3ZK_DIR='/home/ubuntu/zookeeper-3.4.5'
4ONOS_DIR='/home/ubuntu/ONOS'
5ZK_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.."
32 dsh -g $basename "$ZK_DIR/bin/zkServer.sh start"
33 while [ 1 ]; do
34 nup=`dsh -g $basename "$ZK_DIR/bin/zkServer.sh status" | grep "Mode" | egrep "leader|follower" | wc -l`
35 if [ $nup == $nr_nodes ]; then
36 echo "everybody's up: $nup up of of $nr_nodes"
37 echo "ZK started"
38 break;
39 fi
40 echo "waiting for everybody's up: $nup up of of $nr_nodes"
41 sleep 1
42 done
43 ;;
44 stop)
45 echo "Stopping ZK.."
46 dsh -g $basename "$ZK_DIR/bin/zkServer.sh stop"
47 ;;
48 status)
49 echo "Checking ZK Status"
50 dsh -g $basename "$ZK_DIR/bin/zkServer.sh status"
51 ;;
52 esac
53}
54
55cassandra () {
56 case "$1" in
57 start)
58 echo "Starting Cassandra.."
59 echo " start cassandra at the seed node"
60 dsh -w ${basename}1 "cd $ONOS_DIR; ./start-cassandra.sh start"
61 sleep 1
62 echo " start cassandra in rest nodes"
63 dsh -g ${basename} -x ${basename}1 "cd $ONOS_DIR; ./start-cassandra.sh start"
64 while [ 1 ]; do
65 echo $$
66 dsh -w ${basename}1 "cd $ONOS_DIR; ./start-cassandra.sh status" > .cassandra_check.$$
67 cat .cassandra_check.$$
68 nup=`cat .cassandra_check.$$ | grep Normal |grep Up| wc -l`
69 if [ $nup == $nr_nodes ]; then
70 echo "everybody's up: $nup up of of $nr_nodes"
71 echo "Cassandra started"
72 break;
73 fi
74 echo "waiting for everybody's up: $nup up of of $nr_nodes"
75 sleep 1
76 done
77 ;;
Masayoshi Kobayashif238c9e2013-06-10 01:41:13 +000078 bootup)
79 echo "Removing old Cassandra data and logs"
80 dsh -g ${basename} "rm -rf /var/lib/cassandra/*"
81 dsh -g ${basename} "rm -rf /var/log/cassandra/*"
82
83 echo "Starting Cassandra nodes one by one..."
84 for (( c=1; c<=$nr_nodes; c++ ))
85 do
86 echo "Starting node ${basename}${c}"
87 dsh -g ${basename} -w ${basename}${c} "cd $ONOS_DIR; ./start-cassandra.sh start"
88
89 #Wait until it's up
90 while [ 1 ]; do
91 echo $$
92 dsh -w ${basename}1 "cd $ONOS_DIR; ./start-cassandra.sh status" > .cassandra_check.$$
93 cat .cassandra_check.$$
94 nup=`cat .cassandra_check.$$ | grep Normal |grep Up| wc -l`
95 if [ $nup == $c ]; then
96 echo "New node up: $nup up of of $nr_nodes"
97 break;
98 fi
99 echo "Waiting for new node to come up: $nup up of of $nr_nodes"
100 sleep 5
101 done
102 done
103 ;;
Masayoshi Kobayashif358ff52013-03-22 00:31:59 +0000104 stop)
105 echo "Stopping Cassandra.."
106 dsh -g ${basename} "cd $ONOS_DIR; ./start-cassandra.sh stop"
107 ;;
108 cleandb)
109 echo "Removing all data in db"
110 dsh -w ${basename}1 "cd $ONOS_DIR; ./scripts/cleanup-cassandra.sh"
111 ;;
Masayoshi Kobayashibd3d00e2013-04-03 22:59:57 +0000112 checkdb)
113 echo "Check DB Status"
114 dsh -w ${basename}1 "cd $ONOS_DIR; ./scripts/check-db-status.sh"
115 ;;
Masayoshi Kobayashif358ff52013-03-22 00:31:59 +0000116 status)
117 echo "Checking Cassandra Status"
118 dsh -w ${basename}1 "cd $ONOS_DIR; ./start-cassandra.sh status"
119 ;;
120 esac
121}
122
123onos () {
124 case "$1" in
125 start)
Masayoshi Kobayashi0ab03da2013-03-26 00:43:02 +0000126 if [ x$2 == "x" -o x$2 == "xall" ]; then
127 echo "Starting ONOS on all nodes"
128 dsh -g ${basename} "cd $ONOS_DIR; ./start-onos.sh start"
Masayoshi Kobayashi4a1542b2013-04-02 22:34:13 +0000129 dsh -g ${basename} "cd $ONOS_DIR; ./start-rest.sh start"
Masayoshi Kobayashi0ab03da2013-03-26 00:43:02 +0000130 else
131 echo "Starting ONOS on ${basename}$2"
132 dsh -w ${basename}$2 "cd $ONOS_DIR; ./start-onos.sh start"
133 fi
Masayoshi Kobayashif358ff52013-03-22 00:31:59 +0000134 ;;
135 stop)
Masayoshi Kobayashi0ab03da2013-03-26 00:43:02 +0000136 if [ x$2 == "x" -o x$2 == "xall" ]; then
137 echo "Stop ONOS on all nodes"
138 dsh -g ${basename} "cd $ONOS_DIR; ./start-onos.sh stop"
139 else
140 echo "Stop ONOS on ${basename}$2"
141 dsh -w ${basename}$2 "cd $ONOS_DIR; ./start-onos.sh stop"
142 fi
Masayoshi Kobayashif358ff52013-03-22 00:31:59 +0000143 ;;
144 status)
145 echo "Checking ONOS Status"
146 dsh -g ${basename} "cd $ONOS_DIR; ./start-onos.sh status"
147 ;;
148 esac
149}
Masayoshi Kobayashi0ab03da2013-03-26 00:43:02 +0000150switch () {
151 case "$1" in
152 local)
153 if [ x$2 == "x" -o x$2 == "xall" ]; then
154 echo "set all switches point to local controller"
155 dsh -g ${basename} "$ONOS_DIR/scripts/ctrl-local.sh"
156 else
157 dsh -w ${basename}$2 "$ONOS_DIR/scripts/ctrl-local.sh"
158 fi
159 ;;
160 all)
161 if [ x$2 == "x" -o x$2 == "xall" ]; then
162 echo "set all non-core switches point to all non-core controllers"
Masayoshi Kobayashi4a1542b2013-04-02 22:34:13 +0000163 dsh -g ${basename} -x ${basename}1 "$ONOS_DIR/scripts/ctrl-add-ext.sh"
Masayoshi Kobayashi0ab03da2013-03-26 00:43:02 +0000164 else
Masayoshi Kobayashi4a1542b2013-04-02 22:34:13 +0000165 dsh -w ${basename}$2 "$ONOS_DIR/scripts/ctrl-add-ext.sh"
Masayoshi Kobayashi0ab03da2013-03-26 00:43:02 +0000166 fi
167 ;;
168 none)
169 if [ x$2 == "x" -o x$2 == "xall" ]; then
170 echo "all non-core switches loose controller"
171 dsh -g ${basename} -x ${basename}1 "$ONOS_DIR/scripts/ctrl-none.sh"
172 else
173 dsh -w ${basename}$2 "$ONOS_DIR/scripts/ctrl-none.sh"
174 fi
175 ;;
176 esac
177}