blob: 391640c63ab90f73ef6a6840f521c3361b3d03be [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)
Bob Lantzd22c9912016-12-15 14:26:18 -080015- -s : don't install onos.service systemd configuration file
Bob Lantz0b13c1b2016-02-25 05:18:54 -080016- -n : don't try to start ONOS
Ayaka Koshibef17f34a2015-09-24 19:31:48 -070017- -m <settings> : pass <settings> XML file to remote maven installation
18
19options:
20- [node] : remote node to install ONOS on.
21
22summary:
23 Remotely pushes bits to a remote node and installs ONOS on it.
24
Bob Lantz0b13c1b2016-02-25 05:18:54 -080025 The -u should be used on upstart-based systems.
Ayaka Koshibef17f34a2015-09-24 19:31:48 -070026
27 If [node] is not specified the default target is \$OCI.
28
29_EOF_
30}
31
32[ "$1" = "-h" ] && _usage && exit 0
33
tom5c255702014-09-18 06:57:39 -070034[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
35. $ONOS_ROOT/tools/build/envDefaults
36
Ray Milkeybb7e57b2016-11-09 10:00:13 -080037onos-check-bits
38
Jordan Halterman980a8c12017-09-22 18:01:19 -070039while getopts fnvm: o; do
Thomas Vachuskae9fc5962014-10-21 16:10:12 -070040 case "$o" in
41 f) uninstall=true;;
Bob Lantzd22c9912016-12-15 14:26:18 -080042 u) noupstart=true; noinitd=true; nosysd=true;;
43 i) noinitd=true; nosysd=true;;
44 s) nosysd=true;;
Thomas Vachuskae9fc5962014-10-21 16:10:12 -070045 n) nostart=true;;
Kenji HIKICHI237787c2015-01-06 19:57:44 +090046 m) mvn_settings=$OPTARG;;
Jordan Halterman980a8c12017-09-22 18:01:19 -070047 v) upgrade=true;;
Thomas Vachuskae9fc5962014-10-21 16:10:12 -070048 esac
49done
50let OPC=$OPTIND-1
51shift $OPC
52
53# If the -f was given, attempt uninstall first.
54[ -n "$uninstall" ] && onos-uninstall ${1:-$OCI}
tom3014aef2014-09-18 08:44:39 -070055
tom0768a022014-09-24 16:16:16 -070056node=${1:-$OCI}
57remote=$ONOS_USER@$node
DongRyeol Cha5c0a9f02018-05-17 14:32:55 +090058remote_scp=$ONOS_USER@[$node]
tom5c255702014-09-18 06:57:39 -070059
Thomas Vachuska52e65802014-12-08 09:26:01 -080060$(dirname $0)/onos-push-bits $node
tom5c255702014-09-18 06:57:39 -070061
DongRyeol Cha5c0a9f02018-05-17 14:32:55 +090062[ ! -z "$mvn_settings" ] && scp -q $mvn_settings $remote_scp:/tmp/settings.xml
Kenji HIKICHI237787c2015-01-06 19:57:44 +090063
Bob Lantz7c751b52016-04-15 15:42:28 -070064ssh -tt $remote "
Jordan Halterman980a8c12017-09-22 18:01:19 -070065 [ -z "$upgrade" ] && [ -d $ONOS_INSTALL_DIR/bin ] && echo \"ONOS is already installed\" && exit 1
tom3014aef2014-09-18 08:44:39 -070066
tom1f3805d2014-09-18 19:58:47 -070067 # Prepare a landing zone and unroll the bits
Charles M.C. Chandfbc6d82014-12-18 23:11:36 +080068 sudo mkdir -p $ONOS_INSTALL_DIR && sudo chown ${ONOS_USER}:${ONOS_GROUP} $ONOS_INSTALL_DIR
tom5c255702014-09-18 06:57:39 -070069 tar zxmf /tmp/$ONOS_BITS.tar.gz -C $ONOS_INSTALL_DIR --strip-components=1
70
tom0eaa97f2014-09-22 16:13:06 -070071 # Make a link to the log file directory and make a home for auxiliaries
tomecd0fbd2014-09-19 08:47:05 -070072 ln -s $ONOS_INSTALL_DIR/$KARAF_DIST/data/log /opt/onos/log
Jonathan Hartf51950d2016-01-15 09:57:10 -080073 ln -s $ONOS_INSTALL_DIR/$KARAF_DIST /opt/onos/karaf
tom0eaa97f2014-09-22 16:13:06 -070074 mkdir $ONOS_INSTALL_DIR/var
tomdefed6f2014-09-29 11:37:02 -070075 mkdir $ONOS_INSTALL_DIR/config
tom0eaa97f2014-09-22 16:13:06 -070076
Bob Lantz0b13c1b2016-02-25 05:18:54 -080077 # Install the configuration file(s) and set up options for debugging
78 [ -n $noupstart ] && sudo cp $ONOS_INSTALL_DIR/init/onos.conf /etc/init/onos.conf
79 [ -n $noinitd ] && sudo cp $ONOS_INSTALL_DIR/init/onos.initd /etc/init.d/onos
Bob Lantzd22c9912016-12-15 14:26:18 -080080 [ -n $nosysd ] && sudo cp $ONOS_INSTALL_DIR/init/onos.service /etc/systemd/system/onos.service
Jordan Haltermance47fe52018-02-07 11:58:59 -080081
tomb41d1ac2014-09-24 01:51:24 -070082 echo 'export ONOS_OPTS=debug' > $ONOS_INSTALL_DIR/options
tom0eaa97f2014-09-22 16:13:06 -070083
Jordan Haltermance47fe52018-02-07 11:58:59 -080084 if [ ! -z "$ONOS_YOURKIT" ]; then
85 sudo apt-get install unzip
86 cd /tmp
87 wget -N https://www.yourkit.com/download/YourKit-JavaProfiler-${ONOS_YOURKIT}.zip
88 unzip -o YourKit-JavaProfiler-${ONOS_YOURKIT}.zip
89 rm YourKit-JavaProfiler-${ONOS_YOURKIT}.zip
90 mv /tmp/YourKit-JavaProfiler-$(echo $ONOS_YOURKIT | sed 's/\(.*\)-.*/\1/')/bin/linux-x86-64/libyjpagent.so $ONOS_INSTALL_DIR/libyjpagent.so
Jordan Halterman054a5cb2018-05-10 23:28:58 -070091 echo -e 'export JAVA_OPTS="${JAVA_OPTS:--agentpath:$ONOS_INSTALL_DIR/libyjpagent.so}=listen=all"' >> $ONOS_INSTALL_DIR/options
Jordan Haltermance47fe52018-02-07 11:58:59 -080092 fi
93
Bob Lantz0b13c1b2016-02-25 05:18:54 -080094 # Set up correct user to run onos-service
95 echo 'export ONOS_USER=$ONOS_USER' >> $ONOS_INSTALL_DIR/options
Charles M.C. Chan0a4fa792014-12-11 18:50:08 +080096
Jordan Halterman980a8c12017-09-22 18:01:19 -070097 # If the upgrade flag is set, append ".upgrade" to the version string.
98 if [ ! -z "$upgrade" ]
99 then
100 echo '.upgrade' >> $ONOS_INSTALL_DIR/VERSION
101 fi
102
Thomas Vachuskaa10137c2018-04-03 16:45:59 -0700103 # Remove any previous Open Networking Foundation bits from ~/.m2 repo.
Brian O'Connorabafb502014-12-02 22:26:20 -0800104 rm -fr ~/.m2/repository/org/onosproject
tom9ccb2512014-10-07 12:54:53 -0700105
Bob Lantz0b13c1b2016-02-25 05:18:54 -0800106 [ ! -z $mvn_settings ] && cp /tmp/settings.xml ~/.m2/settings.xml
Kenji HIKICHI237787c2015-01-06 19:57:44 +0900107
tom9ccb2512014-10-07 12:54:53 -0700108 # Drop log level for the console
Bob Lantz0b13c1b2016-02-25 05:18:54 -0800109 echo 'log4j.logger.org.apache.sshd = WARN' \
Thomas Vachuskae9fc5962014-10-21 16:10:12 -0700110 >> $ONOS_INSTALL_DIR/$KARAF_DIST/etc/org.ops4j.pax.logging.cfg
tom9ccb2512014-10-07 12:54:53 -0700111
Yuta HIGUCHI6ee6b8c2017-05-09 14:44:30 -0700112 # remove verbose bundle detail from log layout
113 echo 'log4j.appender.out.layout.ConversionPattern=%d{ISO8601} | %-5.5p | %-16.16t | %-32.32c{1} | %X{bundle.id} | %m%n' \
114 >> $ONOS_INSTALL_DIR/$KARAF_DIST/etc/org.ops4j.pax.logging.cfg
115
Thomas Vachuska5ca0f7a2017-11-28 16:27:22 -0800116 # Set up and enable the ONOS service on systemd-based systems
117 sudo systemctl daemon-reload && sudo systemctl enable onos.service || true
Jonathan Hart5de91052016-05-24 09:50:55 -0700118
tom5c255702014-09-18 06:57:39 -0700119"
tom0768a022014-09-24 16:16:16 -0700120
121# Configure the ONOS installation
122onos-config $node
123
Brian O'Connor740e98c2017-06-29 17:07:17 -0700124# Upload the shared cluster key if present
125[ -f "$ONOS_CLUSTER_KEY_FILE" ] && onos-push-cluster-key $1
126
Thomas Vachuskae9fc5962014-10-21 16:10:12 -0700127# Unless -n option was given, attempt to ignite the ONOS service.
DongRyeol Cha5c0a9f02018-05-17 14:32:55 +0900128[ -z "$nostart" ] && onos-service $node start || true