blob: 3406b550a2d201c0ff64c95883e96a3297cf9610 [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
Ray Milkey2fa4f182016-11-07 10:14:10 -080017md5cmd=''
18case "$OSTYPE" in
19 darwin*) md5cmd='md5' ;;
20 *) md5cmd='md5sum' ;;
21esac
22
Thomas Vachuskaa3029cf2016-08-23 16:47:46 -070023oldMD5=$(cat $ONOS_MD5 2>/dev/null)
Ray Milkey2fa4f182016-11-07 10:14:10 -080024newMD5=$(${md5cmd} -q $ONOS_TAR)
Thomas Vachuskaa3029cf2016-08-23 16:47:46 -070025
26# Search for the "clean" argument anywhere on the command-line
27echo "$@" | egrep -q "\bclean\b" && clean=true || unset clean
28
29set -e # Do not tolerate any errors from this point onward
30
31# If the previous installation does not exist, or if the ONOS tar changed,
32# or if the user asked for clean run, start from scratch.
Thomas Vachuska9152b152016-08-24 14:05:09 -070033if [ ! -d $ONOS_DIR -o "$oldMD5" != "$newMD5" -o -d $ONOS_DIR -a -n "$clean" ]; then
Thomas Vachuskaa3029cf2016-08-23 16:47:46 -070034 echo "Running clean installation..."
35
Thomas Vachuskae4abf5b22016-08-15 14:04:46 -070036 # Blitz previously unrolled onos- directory
37 rm -fr $ONOS_DIR
Thomas Vachuska5f54c6f2016-05-04 19:19:51 -070038
Thomas Vachuskae4abf5b22016-08-15 14:04:46 -070039 # Unroll new image from the specified tar file
40 [ -f $ONOS_TAR ] && tar zxf $ONOS_TAR
Thomas Vachuska5f54c6f2016-05-04 19:19:51 -070041
Thomas Vachuskaa3029cf2016-08-23 16:47:46 -070042 # Write out this installation's MD5 checksum
43 echo "$newMD5" > $ONOS_MD5
44
Thomas Vachuskae4abf5b22016-08-15 14:04:46 -070045 # Change into the ONOS home directory
46 cd $ONOS_DIR
47 export ONOS_HOME=$PWD
Thomas Vachuska5f54c6f2016-05-04 19:19:51 -070048
Thomas Vachuskae4abf5b22016-08-15 14:04:46 -070049 # FIXME: for now we're running using the karaf client; later use raw SSH
50 unset ONOS_USE_SSH
51
52 # Create config/cluster.json (cluster metadata)
53 IP=${ONOS_IP:-127.0.0.1}
54 echo "Creating local cluster configs for IP $IP..."
55 [ -d $ONOS_HOME/config ] || mkdir -p $ONOS_HOME/config
56 cat > $ONOS_HOME/config/cluster.json <<-EOF
57 {
58 "name": "default",
59 "nodes": [ {"id": "$IP", "ip": "$IP", "port": 9876 } ],
60 "partitions": [ { "id": 1, "members": [ "$IP" ] } ]
61 }
Madan Jampani590160a2016-06-14 16:49:44 -070062EOF
Thomas Vachuskaa3029cf2016-08-23 16:47:46 -070063
Thomas Vachuskae4abf5b22016-08-15 14:04:46 -070064else
Thomas Vachuskaa3029cf2016-08-23 16:47:46 -070065 # Otherwise, run using the previous installation
66 echo "Running previous installation..."
67
Thomas Vachuskae4abf5b22016-08-15 14:04:46 -070068 # Change into the ONOS home directory
69 cd $ONOS_DIR
70 export ONOS_HOME=$PWD
71fi
Madan Jampani590160a2016-06-14 16:49:44 -070072
Thomas Vachuska5f54c6f2016-05-04 19:19:51 -070073# Start ONOS as a server, but include any specified options
74./bin/onos-service server "$@" &>onos.log &
75echo "$!" > /tmp/onos.pid
76
77# Hang-on a bit and then start tailing the ONOS log output
Charles Chanf9335af2016-05-05 21:05:47 -070078RETRY_COUNT=5
79echo "Waiting for karaf.log"
80until [ $RETRY_COUNT -le 0 ]; do
81 KARAF_LOG=$(find $ONOS_HOME -type f -name karaf.log)
82 if [ $KARAF_LOG ]; then
83 tail -f $KARAF_LOG
84 return
85 fi
86 RETRY_COUNT=$[$RETRY_COUNT-1]
87 sleep 1
88done
Madan Jampani590160a2016-06-14 16:49:44 -070089echo "Fail to open karaf.log"
90