blob: ff52c726b852c0ba738f5be7c7163f250eef52e7 [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
Bob Lantz0b13c1b2016-02-25 05:18:54 -080013- -u : don't install onos.conf upstart configuration file
14- -i : don't install /etc/init.d/onos script (also used by onos.conf)
15- -n : don't try to start ONOS
Ayaka Koshibef17f34a2015-09-24 19:31:48 -070016- -m <settings> : pass <settings> XML file to remote maven installation
17
18options:
19- [node] : remote node to install ONOS on.
20
21summary:
22 Remotely pushes bits to a remote node and installs ONOS on it.
23
Bob Lantz0b13c1b2016-02-25 05:18:54 -080024 The -u should be used on upstart-based systems.
Ayaka Koshibef17f34a2015-09-24 19:31:48 -070025
26 If [node] is not specified the default target is \$OCI.
27
28_EOF_
29}
30
31[ "$1" = "-h" ] && _usage && exit 0
32
tom5c255702014-09-18 06:57:39 -070033[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
34. $ONOS_ROOT/tools/build/envDefaults
35
Kenji HIKICHI237787c2015-01-06 19:57:44 +090036while getopts fnm: o; do
Thomas Vachuskae9fc5962014-10-21 16:10:12 -070037 case "$o" in
38 f) uninstall=true;;
Bob Lantz0b13c1b2016-02-25 05:18:54 -080039 u) noupstart=true; noinitd=true;;
40 i) noinitd=true;;
Thomas Vachuskae9fc5962014-10-21 16:10:12 -070041 n) nostart=true;;
Kenji HIKICHI237787c2015-01-06 19:57:44 +090042 m) mvn_settings=$OPTARG;;
Thomas Vachuskae9fc5962014-10-21 16:10:12 -070043 esac
44done
45let OPC=$OPTIND-1
46shift $OPC
47
48# If the -f was given, attempt uninstall first.
49[ -n "$uninstall" ] && onos-uninstall ${1:-$OCI}
tom3014aef2014-09-18 08:44:39 -070050
tom0768a022014-09-24 16:16:16 -070051node=${1:-$OCI}
52remote=$ONOS_USER@$node
tom5c255702014-09-18 06:57:39 -070053
Thomas Vachuska52e65802014-12-08 09:26:01 -080054$(dirname $0)/onos-push-bits $node
tom5c255702014-09-18 06:57:39 -070055
Kenji HIKICHI237787c2015-01-06 19:57:44 +090056[ ! -z "$mvn_settings" ] && scp -q $mvn_settings $remote:/tmp/settings.xml
57
Pavlin Radoslavov20bc6ae2014-12-03 05:35:04 +000058ssh $remote "
tom3014aef2014-09-18 08:44:39 -070059 [ -d $ONOS_INSTALL_DIR/bin ] && echo \"ONOS is already installed\" && exit 1
60
tom1f3805d2014-09-18 19:58:47 -070061 # Prepare a landing zone and unroll the bits
Charles M.C. Chandfbc6d82014-12-18 23:11:36 +080062 sudo mkdir -p $ONOS_INSTALL_DIR && sudo chown ${ONOS_USER}:${ONOS_GROUP} $ONOS_INSTALL_DIR
tom5c255702014-09-18 06:57:39 -070063 tar zxmf /tmp/$ONOS_BITS.tar.gz -C $ONOS_INSTALL_DIR --strip-components=1
64
tom0eaa97f2014-09-22 16:13:06 -070065 # Make a link to the log file directory and make a home for auxiliaries
tomecd0fbd2014-09-19 08:47:05 -070066 ln -s $ONOS_INSTALL_DIR/$KARAF_DIST/data/log /opt/onos/log
Jonathan Hartf51950d2016-01-15 09:57:10 -080067 ln -s $ONOS_INSTALL_DIR/$KARAF_DIST /opt/onos/karaf
tom0eaa97f2014-09-22 16:13:06 -070068 mkdir $ONOS_INSTALL_DIR/var
tomdefed6f2014-09-29 11:37:02 -070069 mkdir $ONOS_INSTALL_DIR/config
tom0eaa97f2014-09-22 16:13:06 -070070
Yuta HIGUCHI43e3a7e2014-11-30 23:22:11 -080071 # create dir for Raft log
72 # TODO: use $KARAF_DATA
73 mkdir -p -- $ONOS_INSTALL_DIR/$KARAF_DIST/data/raft
74
Bob Lantz0b13c1b2016-02-25 05:18:54 -080075 # Install the configuration file(s) and set up options for debugging
76 [ -n $noupstart ] && sudo cp $ONOS_INSTALL_DIR/init/onos.conf /etc/init/onos.conf
77 [ -n $noinitd ] && sudo cp $ONOS_INSTALL_DIR/init/onos.initd /etc/init.d/onos
tomb41d1ac2014-09-24 01:51:24 -070078 echo 'export ONOS_OPTS=debug' > $ONOS_INSTALL_DIR/options
tom0eaa97f2014-09-22 16:13:06 -070079
Bob Lantz0b13c1b2016-02-25 05:18:54 -080080 # Set up correct user to run onos-service
81 echo 'export ONOS_USER=$ONOS_USER' >> $ONOS_INSTALL_DIR/options
Charles M.C. Chan0a4fa792014-12-11 18:50:08 +080082
Thomas Vachuska96a303c2015-04-28 16:04:50 -070083 # Remove any previous ON.Lab bits from ~/.m2 repo.
Brian O'Connorabafb502014-12-02 22:26:20 -080084 rm -fr ~/.m2/repository/org/onosproject
tom9ccb2512014-10-07 12:54:53 -070085
Bob Lantz0b13c1b2016-02-25 05:18:54 -080086 [ ! -z $mvn_settings ] && cp /tmp/settings.xml ~/.m2/settings.xml
Kenji HIKICHI237787c2015-01-06 19:57:44 +090087
tom9ccb2512014-10-07 12:54:53 -070088 # Drop log level for the console
Bob Lantz0b13c1b2016-02-25 05:18:54 -080089 echo 'log4j.logger.org.apache.sshd = WARN' \
Thomas Vachuskae9fc5962014-10-21 16:10:12 -070090 >> $ONOS_INSTALL_DIR/$KARAF_DIST/etc/org.ops4j.pax.logging.cfg
tom9ccb2512014-10-07 12:54:53 -070091
tom5c255702014-09-18 06:57:39 -070092"
tom0768a022014-09-24 16:16:16 -070093
94# Configure the ONOS installation
95onos-config $node
96
Thomas Vachuskae9fc5962014-10-21 16:10:12 -070097# Unless -n option was given, attempt to ignite the ONOS service.
98[ -z "$nostart" ] && onos-service $node start