tom | 5c25570 | 2014-09-18 06:57:39 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | #------------------------------------------------------------------------------- |
tom | 3014aef | 2014-09-18 08:44:39 -0700 | [diff] [blame] | 3 | # Remotely pushes bits to a remote machine and install & starts ONOS. |
tom | 5c25570 | 2014-09-18 06:57:39 -0700 | [diff] [blame] | 4 | #------------------------------------------------------------------------------- |
| 5 | |
| 6 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
| 7 | . $ONOS_ROOT/tools/build/envDefaults |
| 8 | |
tom | 3014aef | 2014-09-18 08:44:39 -0700 | [diff] [blame] | 9 | # If the first option is -f attempt uninstall first. |
tom | ecd0fbd | 2014-09-19 08:47:05 -0700 | [diff] [blame] | 10 | [ "$1" = "-f" ] && shift && echo 'Uninstalling...' && onos-uninstall ${1:-$OCI} |
tom | 3014aef | 2014-09-18 08:44:39 -0700 | [diff] [blame] | 11 | |
tom | 5c25570 | 2014-09-18 06:57:39 -0700 | [diff] [blame] | 12 | remote=$ONOS_USER@${1:-$OCI} |
| 13 | |
tom | 3014aef | 2014-09-18 08:44:39 -0700 | [diff] [blame] | 14 | scp -q $ONOS_TAR $remote:/tmp |
tom | 5c25570 | 2014-09-18 06:57:39 -0700 | [diff] [blame] | 15 | |
tom | ecd0fbd | 2014-09-19 08:47:05 -0700 | [diff] [blame] | 16 | LOG=$ONOS_INSTALL_DIR/install.log |
| 17 | onos=$ONOS_INSTALL_DIR/bin/onos |
| 18 | |
tom | 3014aef | 2014-09-18 08:44:39 -0700 | [diff] [blame] | 19 | ssh $remote " |
| 20 | [ -d $ONOS_INSTALL_DIR/bin ] && echo \"ONOS is already installed\" && exit 1 |
| 21 | |
tom | 1f3805d | 2014-09-18 19:58:47 -0700 | [diff] [blame] | 22 | # Prepare a landing zone and unroll the bits |
tom | ecd0fbd | 2014-09-19 08:47:05 -0700 | [diff] [blame] | 23 | echo 'Unpacking...' |
tom | 3014aef | 2014-09-18 08:44:39 -0700 | [diff] [blame] | 24 | sudo mkdir -p $ONOS_INSTALL_DIR && sudo chown sdn:sdn $ONOS_INSTALL_DIR |
tom | 5c25570 | 2014-09-18 06:57:39 -0700 | [diff] [blame] | 25 | tar zxmf /tmp/$ONOS_BITS.tar.gz -C $ONOS_INSTALL_DIR --strip-components=1 |
| 26 | |
tom | 1f3805d | 2014-09-18 19:58:47 -0700 | [diff] [blame] | 27 | # Make a link to the log file directory. |
tom | ecd0fbd | 2014-09-19 08:47:05 -0700 | [diff] [blame] | 28 | ln -s $ONOS_INSTALL_DIR/$KARAF_DIST/data/log /opt/onos/log |
tom | 1f3805d | 2014-09-18 19:58:47 -0700 | [diff] [blame] | 29 | |
| 30 | # TODO: Setup ONOS to run as a daemon; for now we at least startup |
tom | ecd0fbd | 2014-09-19 08:47:05 -0700 | [diff] [blame] | 31 | echo 'Starting...' |
| 32 | nohup $ONOS_INSTALL_DIR/bin/onos-ctl server </dev/null | 1>/opt/onos/svc.log 2>&1 & |
| 33 | |
| 34 | # Wait until we reach the run-level 100 |
| 35 | echo 'Waiting for cluster bootstrap...' |
| 36 | running="" |
| 37 | while [ -z \$running ]; do |
| 38 | $onos bundle:list 2>>$LOG | grep -q 'START LEVEL 100' && running=1 || sleep 2 |
| 39 | done |
| 40 | |
| 41 | # Now create group onos and join it, while quitting the default one |
| 42 | if ! $onos cluster:group-list 2>>$LOG | cut -d \\ -f3 | grep -q onos; then |
| 43 | echo 'Creating ONOS group...' |
| 44 | installRole=primary |
| 45 | $onos cluster:group-create onos 1>>$LOG 2>&1 |
| 46 | fi |
| 47 | |
| 48 | echo 'Configuring group membership...' |
| 49 | node=\$($onos cluster:node-list 2>>$LOG | grep '^x' | cut -d \\ -f3) |
| 50 | $onos cluster:group-join onos \$node 1>>$LOG 2>&1 |
| 51 | $onos cluster:group-quit default \$node 1>>$LOG 2>&1 |
| 52 | |
| 53 | if [ X\$installRole = Xprimary ]; then |
| 54 | echo 'Installing ONOS bundles...' |
| 55 | $onos cluster:feature-install onos onos-api 1>>$LOG 2>&1 |
| 56 | $onos cluster:feature-install onos onos-core 1>>$LOG 2>&1 |
| 57 | $onos cluster:feature-install onos onos-openflow 1>>$LOG 2>&1 |
| 58 | $onos cluster:feature-install onoe onos-cli 1>>$LOG 2>&1 |
| 59 | # $onos cluster:feature-install onos onos-gui 1>>$LOG 2>&1 |
| 60 | # $onos cluster:feature-install onos onos-rest 1>>$LOG 2>&1 |
| 61 | $onos cluster:feature-install onos onos-app-tvue 1>>$LOG 2>&1 |
| 62 | $onos cluster:feature-install onos onos-app-fwd 1>>$LOG 2>&1 |
| 63 | fi |
| 64 | |
| 65 | echo 'Started...' |
tom | 5c25570 | 2014-09-18 06:57:39 -0700 | [diff] [blame] | 66 | " |