blob: 9efc7252eda2ad33513ab036fd0a15ee31f06e76 [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
Thomas Vachuskae4abf5b22016-08-15 14:04:46 -070013ONOS_DIR=$(tar tf $ONOS_TAR | head -n 1 | cut -d/ -f1)
Thomas Vachuskaa3029cf2016-08-23 16:47:46 -070014ONOS_MD5=$ONOS_DIR/CHECKSUM
Thomas Vachuska5f54c6f2016-05-04 19:19:51 -070015
Thomas Vachuskaa3029cf2016-08-23 16:47:46 -070016# Extract MD5 of the ONOS tar file and of the previous installation, if one exists
17oldMD5=$(cat $ONOS_MD5 2>/dev/null)
18newMD5=$(md5 -q $ONOS_TAR)
19
20# Search for the "clean" argument anywhere on the command-line
21echo "$@" | egrep -q "\bclean\b" && clean=true || unset clean
22
23set -e # Do not tolerate any errors from this point onward
24
25# If the previous installation does not exist, or if the ONOS tar changed,
26# or if the user asked for clean run, start from scratch.
27if [ ! -d $ONOS_DIR -o $oldMD5 != $newMD5 -o -d $ONOS_DIR -a -n "$clean" ]; then
28 echo "Running clean installation..."
29
Thomas Vachuskae4abf5b22016-08-15 14:04:46 -070030 # Blitz previously unrolled onos- directory
31 rm -fr $ONOS_DIR
Thomas Vachuska5f54c6f2016-05-04 19:19:51 -070032
Thomas Vachuskae4abf5b22016-08-15 14:04:46 -070033 # Unroll new image from the specified tar file
34 [ -f $ONOS_TAR ] && tar zxf $ONOS_TAR
Thomas Vachuska5f54c6f2016-05-04 19:19:51 -070035
Thomas Vachuskaa3029cf2016-08-23 16:47:46 -070036 # Write out this installation's MD5 checksum
37 echo "$newMD5" > $ONOS_MD5
38
Thomas Vachuskae4abf5b22016-08-15 14:04:46 -070039 # Change into the ONOS home directory
40 cd $ONOS_DIR
41 export ONOS_HOME=$PWD
Thomas Vachuska5f54c6f2016-05-04 19:19:51 -070042
Thomas Vachuskae4abf5b22016-08-15 14:04:46 -070043 # FIXME: for now we're running using the karaf client; later use raw SSH
44 unset ONOS_USE_SSH
45
46 # Create config/cluster.json (cluster metadata)
47 IP=${ONOS_IP:-127.0.0.1}
48 echo "Creating local cluster configs for IP $IP..."
49 [ -d $ONOS_HOME/config ] || mkdir -p $ONOS_HOME/config
50 cat > $ONOS_HOME/config/cluster.json <<-EOF
51 {
52 "name": "default",
53 "nodes": [ {"id": "$IP", "ip": "$IP", "port": 9876 } ],
54 "partitions": [ { "id": 1, "members": [ "$IP" ] } ]
55 }
Madan Jampani590160a2016-06-14 16:49:44 -070056EOF
Thomas Vachuskaa3029cf2016-08-23 16:47:46 -070057
Thomas Vachuskae4abf5b22016-08-15 14:04:46 -070058else
Thomas Vachuskaa3029cf2016-08-23 16:47:46 -070059 # Otherwise, run using the previous installation
60 echo "Running previous installation..."
61
Thomas Vachuskae4abf5b22016-08-15 14:04:46 -070062 # Change into the ONOS home directory
63 cd $ONOS_DIR
64 export ONOS_HOME=$PWD
65fi
Madan Jampani590160a2016-06-14 16:49:44 -070066
Thomas Vachuska5f54c6f2016-05-04 19:19:51 -070067# Start ONOS as a server, but include any specified options
68./bin/onos-service server "$@" &>onos.log &
69echo "$!" > /tmp/onos.pid
70
71# Hang-on a bit and then start tailing the ONOS log output
Charles Chanf9335af2016-05-05 21:05:47 -070072RETRY_COUNT=5
73echo "Waiting for karaf.log"
74until [ $RETRY_COUNT -le 0 ]; do
75 KARAF_LOG=$(find $ONOS_HOME -type f -name karaf.log)
76 if [ $KARAF_LOG ]; then
77 tail -f $KARAF_LOG
78 return
79 fi
80 RETRY_COUNT=$[$RETRY_COUNT-1]
81 sleep 1
82done
Madan Jampani590160a2016-06-14 16:49:44 -070083echo "Fail to open karaf.log"
84