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 | |
Thomas Vachuska | e4abf5b2 | 2016-08-15 14:04:46 -0700 | [diff] [blame] | 15 | ONOS_DIR=$(tar tf $ONOS_TAR | head -n 1 | cut -d/ -f1) |
Thomas Vachuska | 5f54c6f | 2016-05-04 19:19:51 -0700 | [diff] [blame] | 16 | |
Charles Chan | 28267ea | 2016-08-22 16:35:39 -0700 | [diff] [blame] | 17 | if [ -d $ONOS_DIR -a "$1" = "clean" -o ! -d $ONOS_DIR ]; then |
Thomas Vachuska | e4abf5b2 | 2016-08-15 14:04:46 -0700 | [diff] [blame] | 18 | # Blitz previously unrolled onos- directory |
| 19 | rm -fr $ONOS_DIR |
Thomas Vachuska | 5f54c6f | 2016-05-04 19:19:51 -0700 | [diff] [blame] | 20 | |
Thomas Vachuska | e4abf5b2 | 2016-08-15 14:04:46 -0700 | [diff] [blame] | 21 | # Unroll new image from the specified tar file |
| 22 | [ -f $ONOS_TAR ] && tar zxf $ONOS_TAR |
Thomas Vachuska | 5f54c6f | 2016-05-04 19:19:51 -0700 | [diff] [blame] | 23 | |
Thomas Vachuska | e4abf5b2 | 2016-08-15 14:04:46 -0700 | [diff] [blame] | 24 | # Change into the ONOS home directory |
| 25 | cd $ONOS_DIR |
| 26 | export ONOS_HOME=$PWD |
Thomas Vachuska | 5f54c6f | 2016-05-04 19:19:51 -0700 | [diff] [blame] | 27 | |
Thomas Vachuska | e4abf5b2 | 2016-08-15 14:04:46 -0700 | [diff] [blame] | 28 | # FIXME: for now we're running using the karaf client; later use raw SSH |
| 29 | unset ONOS_USE_SSH |
| 30 | |
| 31 | # Create config/cluster.json (cluster metadata) |
| 32 | IP=${ONOS_IP:-127.0.0.1} |
| 33 | echo "Creating local cluster configs for IP $IP..." |
| 34 | [ -d $ONOS_HOME/config ] || mkdir -p $ONOS_HOME/config |
| 35 | cat > $ONOS_HOME/config/cluster.json <<-EOF |
| 36 | { |
| 37 | "name": "default", |
| 38 | "nodes": [ {"id": "$IP", "ip": "$IP", "port": 9876 } ], |
| 39 | "partitions": [ { "id": 1, "members": [ "$IP" ] } ] |
| 40 | } |
Madan Jampani | 590160a | 2016-06-14 16:49:44 -0700 | [diff] [blame] | 41 | EOF |
Thomas Vachuska | e4abf5b2 | 2016-08-15 14:04:46 -0700 | [diff] [blame] | 42 | else |
| 43 | # Change into the ONOS home directory |
| 44 | cd $ONOS_DIR |
| 45 | export ONOS_HOME=$PWD |
| 46 | fi |
Madan Jampani | 590160a | 2016-06-14 16:49:44 -0700 | [diff] [blame] | 47 | |
Thomas Vachuska | 5f54c6f | 2016-05-04 19:19:51 -0700 | [diff] [blame] | 48 | # Start ONOS as a server, but include any specified options |
| 49 | ./bin/onos-service server "$@" &>onos.log & |
| 50 | echo "$!" > /tmp/onos.pid |
| 51 | |
| 52 | # Hang-on a bit and then start tailing the ONOS log output |
Charles Chan | f9335af | 2016-05-05 21:05:47 -0700 | [diff] [blame] | 53 | RETRY_COUNT=5 |
| 54 | echo "Waiting for karaf.log" |
| 55 | until [ $RETRY_COUNT -le 0 ]; do |
| 56 | KARAF_LOG=$(find $ONOS_HOME -type f -name karaf.log) |
| 57 | if [ $KARAF_LOG ]; then |
| 58 | tail -f $KARAF_LOG |
| 59 | return |
| 60 | fi |
| 61 | RETRY_COUNT=$[$RETRY_COUNT-1] |
| 62 | sleep 1 |
| 63 | done |
Madan Jampani | 590160a | 2016-06-14 16:49:44 -0700 | [diff] [blame] | 64 | echo "Fail to open karaf.log" |
| 65 | |