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 | |
Thomas Vachuska | e4abf5b2 | 2016-08-15 14:04:46 -0700 | [diff] [blame] | 13 | ONOS_DIR=$(tar tf $ONOS_TAR | head -n 1 | cut -d/ -f1) |
Thomas Vachuska | a3029cf | 2016-08-23 16:47:46 -0700 | [diff] [blame] | 14 | ONOS_MD5=$ONOS_DIR/CHECKSUM |
Thomas Vachuska | 5f54c6f | 2016-05-04 19:19:51 -0700 | [diff] [blame] | 15 | |
Thomas Vachuska | a3029cf | 2016-08-23 16:47:46 -0700 | [diff] [blame] | 16 | # Extract MD5 of the ONOS tar file and of the previous installation, if one exists |
| 17 | oldMD5=$(cat $ONOS_MD5 2>/dev/null) |
| 18 | newMD5=$(md5 -q $ONOS_TAR) |
| 19 | |
| 20 | # Search for the "clean" argument anywhere on the command-line |
| 21 | echo "$@" | egrep -q "\bclean\b" && clean=true || unset clean |
| 22 | |
| 23 | set -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. |
Thomas Vachuska | 9152b15 | 2016-08-24 14:05:09 -0700 | [diff] [blame^] | 27 | if [ ! -d $ONOS_DIR -o "$oldMD5" != "$newMD5" -o -d $ONOS_DIR -a -n "$clean" ]; then |
Thomas Vachuska | a3029cf | 2016-08-23 16:47:46 -0700 | [diff] [blame] | 28 | echo "Running clean installation..." |
| 29 | |
Thomas Vachuska | e4abf5b2 | 2016-08-15 14:04:46 -0700 | [diff] [blame] | 30 | # Blitz previously unrolled onos- directory |
| 31 | rm -fr $ONOS_DIR |
Thomas Vachuska | 5f54c6f | 2016-05-04 19:19:51 -0700 | [diff] [blame] | 32 | |
Thomas Vachuska | e4abf5b2 | 2016-08-15 14:04:46 -0700 | [diff] [blame] | 33 | # Unroll new image from the specified tar file |
| 34 | [ -f $ONOS_TAR ] && tar zxf $ONOS_TAR |
Thomas Vachuska | 5f54c6f | 2016-05-04 19:19:51 -0700 | [diff] [blame] | 35 | |
Thomas Vachuska | a3029cf | 2016-08-23 16:47:46 -0700 | [diff] [blame] | 36 | # Write out this installation's MD5 checksum |
| 37 | echo "$newMD5" > $ONOS_MD5 |
| 38 | |
Thomas Vachuska | e4abf5b2 | 2016-08-15 14:04:46 -0700 | [diff] [blame] | 39 | # Change into the ONOS home directory |
| 40 | cd $ONOS_DIR |
| 41 | export ONOS_HOME=$PWD |
Thomas Vachuska | 5f54c6f | 2016-05-04 19:19:51 -0700 | [diff] [blame] | 42 | |
Thomas Vachuska | e4abf5b2 | 2016-08-15 14:04:46 -0700 | [diff] [blame] | 43 | # 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 Jampani | 590160a | 2016-06-14 16:49:44 -0700 | [diff] [blame] | 56 | EOF |
Thomas Vachuska | a3029cf | 2016-08-23 16:47:46 -0700 | [diff] [blame] | 57 | |
Thomas Vachuska | e4abf5b2 | 2016-08-15 14:04:46 -0700 | [diff] [blame] | 58 | else |
Thomas Vachuska | a3029cf | 2016-08-23 16:47:46 -0700 | [diff] [blame] | 59 | # Otherwise, run using the previous installation |
| 60 | echo "Running previous installation..." |
| 61 | |
Thomas Vachuska | e4abf5b2 | 2016-08-15 14:04:46 -0700 | [diff] [blame] | 62 | # Change into the ONOS home directory |
| 63 | cd $ONOS_DIR |
| 64 | export ONOS_HOME=$PWD |
| 65 | fi |
Madan Jampani | 590160a | 2016-06-14 16:49:44 -0700 | [diff] [blame] | 66 | |
Thomas Vachuska | 5f54c6f | 2016-05-04 19:19:51 -0700 | [diff] [blame] | 67 | # Start ONOS as a server, but include any specified options |
| 68 | ./bin/onos-service server "$@" &>onos.log & |
| 69 | echo "$!" > /tmp/onos.pid |
| 70 | |
| 71 | # Hang-on a bit and then start tailing the ONOS log output |
Charles Chan | f9335af | 2016-05-05 21:05:47 -0700 | [diff] [blame] | 72 | RETRY_COUNT=5 |
| 73 | echo "Waiting for karaf.log" |
| 74 | until [ $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 |
| 82 | done |
Madan Jampani | 590160a | 2016-06-14 16:49:44 -0700 | [diff] [blame] | 83 | echo "Fail to open karaf.log" |
| 84 | |