Masayoshi Kobayashi | f358ff5 | 2013-03-22 00:31:59 +0000 | [diff] [blame] | 1 | USERNAME=ubuntu |
| 2 | CASSANDRA_DIR='/home/ubuntu/apache-cassandra-1.1.4' |
| 3 | ZK_DIR='/home/ubuntu/zookeeper-3.4.5' |
| 4 | ONOS_DIR='/home/ubuntu/ONOS' |
| 5 | ZK_LIB='/var/lib/zookeeper' |
| 6 | CASSANDRA_LIB='/var/lib/cassandra' |
| 7 | |
| 8 | if [ x$CLUSTER == "x" ]; then |
| 9 | echo "CLUSTER is not set. Exitting." |
| 10 | exit |
| 11 | fi |
| 12 | if [ x$ONOS_CLUSTER_BASENAME == "x" ]; then |
| 13 | echo "ONOS_CLUSTER_BASENAME is not set. Exitting" |
| 14 | exit |
| 15 | fi |
| 16 | if [ x$ONOS_CLUSTER_NR_NODES == "x" ]; then |
| 17 | echo "ONOS_CLUSTER_NR_NODES is not set. Exitting" |
| 18 | exit |
| 19 | fi |
| 20 | |
| 21 | export basename=$ONOS_CLUSTER_BASENAME |
| 22 | export nr_nodes=$ONOS_CLUSTER_NR_NODES |
| 23 | |
| 24 | checkcluster () { |
| 25 | dsh -g $basename 'uname -a' |
| 26 | } |
| 27 | |
| 28 | zk () { |
| 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 | |
| 55 | cassandra () { |
| 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 Kobayashi | f238c9e | 2013-06-10 01:41:13 +0000 | [diff] [blame] | 78 | 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 Kobayashi | f358ff5 | 2013-03-22 00:31:59 +0000 | [diff] [blame] | 104 | 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 Kobayashi | bd3d00e | 2013-04-03 22:59:57 +0000 | [diff] [blame] | 112 | checkdb) |
| 113 | echo "Check DB Status" |
| 114 | dsh -w ${basename}1 "cd $ONOS_DIR; ./scripts/check-db-status.sh" |
| 115 | ;; |
Masayoshi Kobayashi | f358ff5 | 2013-03-22 00:31:59 +0000 | [diff] [blame] | 116 | status) |
| 117 | echo "Checking Cassandra Status" |
| 118 | dsh -w ${basename}1 "cd $ONOS_DIR; ./start-cassandra.sh status" |
| 119 | ;; |
| 120 | esac |
| 121 | } |
| 122 | |
| 123 | onos () { |
| 124 | case "$1" in |
| 125 | start) |
Masayoshi Kobayashi | 0ab03da | 2013-03-26 00:43:02 +0000 | [diff] [blame] | 126 | 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 Kobayashi | 4a1542b | 2013-04-02 22:34:13 +0000 | [diff] [blame] | 129 | dsh -g ${basename} "cd $ONOS_DIR; ./start-rest.sh start" |
Masayoshi Kobayashi | 0ab03da | 2013-03-26 00:43:02 +0000 | [diff] [blame] | 130 | else |
| 131 | echo "Starting ONOS on ${basename}$2" |
| 132 | dsh -w ${basename}$2 "cd $ONOS_DIR; ./start-onos.sh start" |
| 133 | fi |
Masayoshi Kobayashi | f358ff5 | 2013-03-22 00:31:59 +0000 | [diff] [blame] | 134 | ;; |
| 135 | stop) |
Masayoshi Kobayashi | 0ab03da | 2013-03-26 00:43:02 +0000 | [diff] [blame] | 136 | 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 Kobayashi | f358ff5 | 2013-03-22 00:31:59 +0000 | [diff] [blame] | 143 | ;; |
| 144 | status) |
| 145 | echo "Checking ONOS Status" |
| 146 | dsh -g ${basename} "cd $ONOS_DIR; ./start-onos.sh status" |
| 147 | ;; |
| 148 | esac |
| 149 | } |
Masayoshi Kobayashi | 0ab03da | 2013-03-26 00:43:02 +0000 | [diff] [blame] | 150 | switch () { |
| 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 Kobayashi | 4a1542b | 2013-04-02 22:34:13 +0000 | [diff] [blame] | 163 | dsh -g ${basename} -x ${basename}1 "$ONOS_DIR/scripts/ctrl-add-ext.sh" |
Masayoshi Kobayashi | 0ab03da | 2013-03-26 00:43:02 +0000 | [diff] [blame] | 164 | else |
Masayoshi Kobayashi | 4a1542b | 2013-04-02 22:34:13 +0000 | [diff] [blame] | 165 | dsh -w ${basename}$2 "$ONOS_DIR/scripts/ctrl-add-ext.sh" |
Masayoshi Kobayashi | 0ab03da | 2013-03-26 00:43:02 +0000 | [diff] [blame] | 166 | 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 | } |