Thomas Vachuska | 5f54c6f | 2016-05-04 19:19:51 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # Runs ONOS from distributable onos.tar.gz |
| 4 | # ----------------------------------------------------------------------------- |
| 5 | |
| 6 | ONOS_TAR= |
| 7 | |
| 8 | cd /tmp |
| 9 | |
| 10 | # Kill any running instances |
| 11 | [ -f /tmp/onos.pid ] && kill -9 $(cat /tmp/onos.pid) &>/dev/null |
| 12 | |
| 13 | set -e |
| 14 | |
| 15 | # Blitz previously unrolled onos- directory |
Thomas Vachuska | fc3f314 | 2016-05-04 20:10:10 -0700 | [diff] [blame] | 16 | rm -fr onos-*/ |
Thomas Vachuska | 5f54c6f | 2016-05-04 19:19:51 -0700 | [diff] [blame] | 17 | |
| 18 | # Unroll new image from the specified tar file |
| 19 | [ -f $ONOS_TAR ] && tar zxf $ONOS_TAR |
| 20 | |
| 21 | # Change into the ONOS home directory |
Thomas Vachuska | dcdf24d | 2016-06-13 12:10:25 -0700 | [diff] [blame] | 22 | cd onos-*/ |
Thomas Vachuska | 5f54c6f | 2016-05-04 19:19:51 -0700 | [diff] [blame] | 23 | export ONOS_HOME=$PWD |
| 24 | |
| 25 | # FIXME: for now we're running using the karaf client; later use raw SSH |
| 26 | unset ONOS_USE_SSH |
| 27 | |
Madan Jampani | 590160a | 2016-06-14 16:49:44 -0700 | [diff] [blame] | 28 | # Create config/cluster.json (cluster metadata) |
Brian O'Connor | 3c24769 | 2016-06-15 13:26:54 -0700 | [diff] [blame] | 29 | IP=${ONOS_IP:-127.0.0.1} |
Madan Jampani | 590160a | 2016-06-14 16:49:44 -0700 | [diff] [blame] | 30 | echo "Creating local cluster configs for IP $IP..." |
| 31 | [ -d $ONOS_HOME/config ] || mkdir -p $ONOS_HOME/config |
| 32 | cat > $ONOS_HOME/config/cluster.json <<EOF |
| 33 | { |
| 34 | "name": "default", |
| 35 | "nodes": [ {"id": "$IP", "ip": "$IP", "port": 9876 } ], |
| 36 | "partitions": [ { "id": 1, "members": [ "$IP" ] } ] |
| 37 | } |
| 38 | EOF |
| 39 | |
Thomas Vachuska | 5f54c6f | 2016-05-04 19:19:51 -0700 | [diff] [blame] | 40 | # Start ONOS as a server, but include any specified options |
| 41 | ./bin/onos-service server "$@" &>onos.log & |
| 42 | echo "$!" > /tmp/onos.pid |
| 43 | |
| 44 | # Hang-on a bit and then start tailing the ONOS log output |
Charles Chan | f9335af | 2016-05-05 21:05:47 -0700 | [diff] [blame] | 45 | RETRY_COUNT=5 |
| 46 | echo "Waiting for karaf.log" |
| 47 | until [ $RETRY_COUNT -le 0 ]; do |
| 48 | KARAF_LOG=$(find $ONOS_HOME -type f -name karaf.log) |
| 49 | if [ $KARAF_LOG ]; then |
| 50 | tail -f $KARAF_LOG |
| 51 | return |
| 52 | fi |
| 53 | RETRY_COUNT=$[$RETRY_COUNT-1] |
| 54 | sleep 1 |
| 55 | done |
Madan Jampani | 590160a | 2016-06-14 16:49:44 -0700 | [diff] [blame] | 56 | echo "Fail to open karaf.log" |
| 57 | |