blob: ff4fb443339ad46c1863b06b81201d6ac3377874 [file] [log] [blame]
tom5c255702014-09-18 06:57:39 -07001#!/bin/bash
Pavlin Radoslavov91413792014-10-15 11:00:32 -07002# -----------------------------------------------------------------------------
tom1a2908c2014-09-23 16:37:39 -07003# Remotely pushes bits to a remote node and installs ONOS on it.
Pavlin Radoslavov91413792014-10-15 11:00:32 -07004# -----------------------------------------------------------------------------
tom5c255702014-09-18 06:57:39 -07005
Ayaka Koshibef17f34a2015-09-24 19:31:48 -07006function _usage () {
7cat << _EOF_
8usage:
9 $(basename $0) [-fn] [-m] <settings> [node]
10
11flags:
12- -f : forces uninstall of currently installed ONOS
13- -n : do not copy over onos.conf upstart configuration file.
14- -m <settings> : pass <settings> XML file to remote maven installation
15
16options:
17- [node] : remote node to install ONOS on.
18
19summary:
20 Remotely pushes bits to a remote node and installs ONOS on it.
21
22 The [-n] flag assumes that Upstart is used. The [-f] flag depends on
23 and 'onos-config'.
24
25 If [node] is not specified the default target is \$OCI.
26
27_EOF_
28}
29
30[ "$1" = "-h" ] && _usage && exit 0
31
tom5c255702014-09-18 06:57:39 -070032[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
33. $ONOS_ROOT/tools/build/envDefaults
34
Kenji HIKICHI237787c2015-01-06 19:57:44 +090035while getopts fnm: o; do
Thomas Vachuskae9fc5962014-10-21 16:10:12 -070036 case "$o" in
37 f) uninstall=true;;
38 n) nostart=true;;
Kenji HIKICHI237787c2015-01-06 19:57:44 +090039 m) mvn_settings=$OPTARG;;
Thomas Vachuskae9fc5962014-10-21 16:10:12 -070040 esac
41done
42let OPC=$OPTIND-1
43shift $OPC
44
45# If the -f was given, attempt uninstall first.
46[ -n "$uninstall" ] && onos-uninstall ${1:-$OCI}
tom3014aef2014-09-18 08:44:39 -070047
tom0768a022014-09-24 16:16:16 -070048node=${1:-$OCI}
49remote=$ONOS_USER@$node
tom5c255702014-09-18 06:57:39 -070050
Thomas Vachuska52e65802014-12-08 09:26:01 -080051$(dirname $0)/onos-push-bits $node
tom5c255702014-09-18 06:57:39 -070052
Kenji HIKICHI237787c2015-01-06 19:57:44 +090053[ ! -z "$mvn_settings" ] && scp -q $mvn_settings $remote:/tmp/settings.xml
54
Pavlin Radoslavov20bc6ae2014-12-03 05:35:04 +000055ssh $remote "
tom3014aef2014-09-18 08:44:39 -070056 [ -d $ONOS_INSTALL_DIR/bin ] && echo \"ONOS is already installed\" && exit 1
57
tom1f3805d2014-09-18 19:58:47 -070058 # Prepare a landing zone and unroll the bits
Charles M.C. Chandfbc6d82014-12-18 23:11:36 +080059 sudo mkdir -p $ONOS_INSTALL_DIR && sudo chown ${ONOS_USER}:${ONOS_GROUP} $ONOS_INSTALL_DIR
tom5c255702014-09-18 06:57:39 -070060 tar zxmf /tmp/$ONOS_BITS.tar.gz -C $ONOS_INSTALL_DIR --strip-components=1
61
tom0eaa97f2014-09-22 16:13:06 -070062 # Make a link to the log file directory and make a home for auxiliaries
tomecd0fbd2014-09-19 08:47:05 -070063 ln -s $ONOS_INSTALL_DIR/$KARAF_DIST/data/log /opt/onos/log
Jonathan Hartf51950d2016-01-15 09:57:10 -080064 ln -s $ONOS_INSTALL_DIR/$KARAF_DIST /opt/onos/karaf
tom0eaa97f2014-09-22 16:13:06 -070065 mkdir $ONOS_INSTALL_DIR/var
tomdefed6f2014-09-29 11:37:02 -070066 mkdir $ONOS_INSTALL_DIR/config
tom0eaa97f2014-09-22 16:13:06 -070067
Yuta HIGUCHI43e3a7e2014-11-30 23:22:11 -080068 # create dir for Raft log
69 # TODO: use $KARAF_DATA
70 mkdir -p -- $ONOS_INSTALL_DIR/$KARAF_DIST/data/raft
71
tomb41d1ac2014-09-24 01:51:24 -070072 # Install the upstart configuration file and setup options for debugging
Brian O'Connor0eed29e2015-09-16 11:38:33 -070073 [ -z "$nostart" ] && sudo cp $ONOS_INSTALL_DIR/init/onos.conf /etc/init/onos.conf
Jonathan Hartf51950d2016-01-15 09:57:10 -080074 [ -z "$nostart" ] && sudo cp $ONOS_INSTALL_DIR/init/onos.initd /etc/init.d/onos
tomb41d1ac2014-09-24 01:51:24 -070075 echo 'export ONOS_OPTS=debug' > $ONOS_INSTALL_DIR/options
tom0eaa97f2014-09-22 16:13:06 -070076
Charles M.C. Chan0a4fa792014-12-11 18:50:08 +080077 # Setup correct user to run onos-service
78 echo 'export ONOS_USER="${ONOS_USER:-sdn}"' >> $ONOS_INSTALL_DIR/options
79
Thomas Vachuska96a303c2015-04-28 16:04:50 -070080 # Remove any previous ON.Lab bits from ~/.m2 repo.
Brian O'Connorabafb502014-12-02 22:26:20 -080081 rm -fr ~/.m2/repository/org/onosproject
tom9ccb2512014-10-07 12:54:53 -070082
Kenji HIKICHI237787c2015-01-06 19:57:44 +090083 [ ! -z "$mvn_settings" ] && cp /tmp/settings.xml ~/.m2/settings.xml
84
tom9ccb2512014-10-07 12:54:53 -070085 # Drop log level for the console
Thomas Vachuskae9fc5962014-10-21 16:10:12 -070086 echo "log4j.logger.org.apache.sshd = WARN" \
87 >> $ONOS_INSTALL_DIR/$KARAF_DIST/etc/org.ops4j.pax.logging.cfg
tom9ccb2512014-10-07 12:54:53 -070088
tom5c255702014-09-18 06:57:39 -070089"
tom0768a022014-09-24 16:16:16 -070090
91# Configure the ONOS installation
92onos-config $node
93
Thomas Vachuskae9fc5962014-10-21 16:10:12 -070094# Unless -n option was given, attempt to ignite the ONOS service.
95[ -z "$nostart" ] && onos-service $node start