blob: e223a61a13ec109131ab8cd7c016d76c6cc2190e [file] [log] [blame]
Thomas Vachuska5f54c6f2016-05-04 19:19:51 -07001#!/bin/bash
2# -----------------------------------------------------------------------------
3# Runs ONOS from distributable onos.tar.gz
4# -----------------------------------------------------------------------------
5
6ONOS_TAR=
7
8cd /tmp
9
10# Kill any running instances
11[ -f /tmp/onos.pid ] && kill -9 $(cat /tmp/onos.pid) &>/dev/null
12
13set -e
14
Thomas Vachuskae4abf5b22016-08-15 14:04:46 -070015ONOS_DIR=$(tar tf $ONOS_TAR | head -n 1 | cut -d/ -f1)
Thomas Vachuska5f54c6f2016-05-04 19:19:51 -070016
Charles Chan28267ea2016-08-22 16:35:39 -070017if [ -d $ONOS_DIR -a "$1" = "clean" -o ! -d $ONOS_DIR ]; then
Thomas Vachuskae4abf5b22016-08-15 14:04:46 -070018 # Blitz previously unrolled onos- directory
19 rm -fr $ONOS_DIR
Thomas Vachuska5f54c6f2016-05-04 19:19:51 -070020
Thomas Vachuskae4abf5b22016-08-15 14:04:46 -070021 # Unroll new image from the specified tar file
22 [ -f $ONOS_TAR ] && tar zxf $ONOS_TAR
Thomas Vachuska5f54c6f2016-05-04 19:19:51 -070023
Thomas Vachuskae4abf5b22016-08-15 14:04:46 -070024 # Change into the ONOS home directory
25 cd $ONOS_DIR
26 export ONOS_HOME=$PWD
Thomas Vachuska5f54c6f2016-05-04 19:19:51 -070027
Thomas Vachuskae4abf5b22016-08-15 14:04:46 -070028 # 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 Jampani590160a2016-06-14 16:49:44 -070041EOF
Thomas Vachuskae4abf5b22016-08-15 14:04:46 -070042else
43 # Change into the ONOS home directory
44 cd $ONOS_DIR
45 export ONOS_HOME=$PWD
46fi
Madan Jampani590160a2016-06-14 16:49:44 -070047
Thomas Vachuska5f54c6f2016-05-04 19:19:51 -070048# Start ONOS as a server, but include any specified options
49./bin/onos-service server "$@" &>onos.log &
50echo "$!" > /tmp/onos.pid
51
52# Hang-on a bit and then start tailing the ONOS log output
Charles Chanf9335af2016-05-05 21:05:47 -070053RETRY_COUNT=5
54echo "Waiting for karaf.log"
55until [ $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
63done
Madan Jampani590160a2016-06-14 16:49:44 -070064echo "Fail to open karaf.log"
65