tom | 5c25570 | 2014-09-18 06:57:39 -0700 | [diff] [blame] | 1 | #!/bin/bash |
Pavlin Radoslavov | 9141379 | 2014-10-15 11:00:32 -0700 | [diff] [blame] | 2 | # ----------------------------------------------------------------------------- |
tom | 1a2908c | 2014-09-23 16:37:39 -0700 | [diff] [blame] | 3 | # Remotely pushes bits to a remote node and installs ONOS on it. |
Pavlin Radoslavov | 9141379 | 2014-10-15 11:00:32 -0700 | [diff] [blame] | 4 | # ----------------------------------------------------------------------------- |
tom | 5c25570 | 2014-09-18 06:57:39 -0700 | [diff] [blame] | 5 | |
Ayaka Koshibe | f17f34a | 2015-09-24 19:31:48 -0700 | [diff] [blame] | 6 | function _usage () { |
| 7 | cat << _EOF_ |
| 8 | usage: |
| 9 | $(basename $0) [-fn] [-m] <settings> [node] |
| 10 | |
| 11 | flags: |
| 12 | - -f : forces uninstall of currently installed ONOS |
Bob Lantz | 0b13c1b | 2016-02-25 05:18:54 -0800 | [diff] [blame] | 13 | - -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 Koshibe | f17f34a | 2015-09-24 19:31:48 -0700 | [diff] [blame] | 16 | - -m <settings> : pass <settings> XML file to remote maven installation |
| 17 | |
| 18 | options: |
| 19 | - [node] : remote node to install ONOS on. |
| 20 | |
| 21 | summary: |
| 22 | Remotely pushes bits to a remote node and installs ONOS on it. |
| 23 | |
Bob Lantz | 0b13c1b | 2016-02-25 05:18:54 -0800 | [diff] [blame] | 24 | The -u should be used on upstart-based systems. |
Ayaka Koshibe | f17f34a | 2015-09-24 19:31:48 -0700 | [diff] [blame] | 25 | |
| 26 | If [node] is not specified the default target is \$OCI. |
| 27 | |
| 28 | _EOF_ |
| 29 | } |
| 30 | |
| 31 | [ "$1" = "-h" ] && _usage && exit 0 |
| 32 | |
tom | 5c25570 | 2014-09-18 06:57:39 -0700 | [diff] [blame] | 33 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
| 34 | . $ONOS_ROOT/tools/build/envDefaults |
| 35 | |
Ray Milkey | bb7e57b | 2016-11-09 10:00:13 -0800 | [diff] [blame] | 36 | onos-check-bits |
| 37 | |
Kenji HIKICHI | 237787c | 2015-01-06 19:57:44 +0900 | [diff] [blame] | 38 | while getopts fnm: o; do |
Thomas Vachuska | e9fc596 | 2014-10-21 16:10:12 -0700 | [diff] [blame] | 39 | case "$o" in |
| 40 | f) uninstall=true;; |
Bob Lantz | 0b13c1b | 2016-02-25 05:18:54 -0800 | [diff] [blame] | 41 | u) noupstart=true; noinitd=true;; |
| 42 | i) noinitd=true;; |
Thomas Vachuska | e9fc596 | 2014-10-21 16:10:12 -0700 | [diff] [blame] | 43 | n) nostart=true;; |
Kenji HIKICHI | 237787c | 2015-01-06 19:57:44 +0900 | [diff] [blame] | 44 | m) mvn_settings=$OPTARG;; |
Thomas Vachuska | e9fc596 | 2014-10-21 16:10:12 -0700 | [diff] [blame] | 45 | esac |
| 46 | done |
| 47 | let OPC=$OPTIND-1 |
| 48 | shift $OPC |
| 49 | |
| 50 | # If the -f was given, attempt uninstall first. |
| 51 | [ -n "$uninstall" ] && onos-uninstall ${1:-$OCI} |
tom | 3014aef | 2014-09-18 08:44:39 -0700 | [diff] [blame] | 52 | |
tom | 0768a02 | 2014-09-24 16:16:16 -0700 | [diff] [blame] | 53 | node=${1:-$OCI} |
| 54 | remote=$ONOS_USER@$node |
tom | 5c25570 | 2014-09-18 06:57:39 -0700 | [diff] [blame] | 55 | |
Thomas Vachuska | 52e6580 | 2014-12-08 09:26:01 -0800 | [diff] [blame] | 56 | $(dirname $0)/onos-push-bits $node |
tom | 5c25570 | 2014-09-18 06:57:39 -0700 | [diff] [blame] | 57 | |
Kenji HIKICHI | 237787c | 2015-01-06 19:57:44 +0900 | [diff] [blame] | 58 | [ ! -z "$mvn_settings" ] && scp -q $mvn_settings $remote:/tmp/settings.xml |
| 59 | |
Bob Lantz | 7c751b5 | 2016-04-15 15:42:28 -0700 | [diff] [blame] | 60 | ssh -tt $remote " |
tom | 3014aef | 2014-09-18 08:44:39 -0700 | [diff] [blame] | 61 | [ -d $ONOS_INSTALL_DIR/bin ] && echo \"ONOS is already installed\" && exit 1 |
| 62 | |
tom | 1f3805d | 2014-09-18 19:58:47 -0700 | [diff] [blame] | 63 | # Prepare a landing zone and unroll the bits |
Charles M.C. Chan | dfbc6d8 | 2014-12-18 23:11:36 +0800 | [diff] [blame] | 64 | sudo mkdir -p $ONOS_INSTALL_DIR && sudo chown ${ONOS_USER}:${ONOS_GROUP} $ONOS_INSTALL_DIR |
tom | 5c25570 | 2014-09-18 06:57:39 -0700 | [diff] [blame] | 65 | tar zxmf /tmp/$ONOS_BITS.tar.gz -C $ONOS_INSTALL_DIR --strip-components=1 |
| 66 | |
tom | 0eaa97f | 2014-09-22 16:13:06 -0700 | [diff] [blame] | 67 | # Make a link to the log file directory and make a home for auxiliaries |
tom | ecd0fbd | 2014-09-19 08:47:05 -0700 | [diff] [blame] | 68 | ln -s $ONOS_INSTALL_DIR/$KARAF_DIST/data/log /opt/onos/log |
Jonathan Hart | f51950d | 2016-01-15 09:57:10 -0800 | [diff] [blame] | 69 | ln -s $ONOS_INSTALL_DIR/$KARAF_DIST /opt/onos/karaf |
tom | 0eaa97f | 2014-09-22 16:13:06 -0700 | [diff] [blame] | 70 | mkdir $ONOS_INSTALL_DIR/var |
tom | defed6f | 2014-09-29 11:37:02 -0700 | [diff] [blame] | 71 | mkdir $ONOS_INSTALL_DIR/config |
tom | 0eaa97f | 2014-09-22 16:13:06 -0700 | [diff] [blame] | 72 | |
Bob Lantz | 0b13c1b | 2016-02-25 05:18:54 -0800 | [diff] [blame] | 73 | # Install the configuration file(s) and set up options for debugging |
| 74 | [ -n $noupstart ] && sudo cp $ONOS_INSTALL_DIR/init/onos.conf /etc/init/onos.conf |
| 75 | [ -n $noinitd ] && sudo cp $ONOS_INSTALL_DIR/init/onos.initd /etc/init.d/onos |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 76 | echo 'export ONOS_OPTS=debug' > $ONOS_INSTALL_DIR/options |
tom | 0eaa97f | 2014-09-22 16:13:06 -0700 | [diff] [blame] | 77 | |
Bob Lantz | 0b13c1b | 2016-02-25 05:18:54 -0800 | [diff] [blame] | 78 | # Set up correct user to run onos-service |
| 79 | echo 'export ONOS_USER=$ONOS_USER' >> $ONOS_INSTALL_DIR/options |
Charles M.C. Chan | 0a4fa79 | 2014-12-11 18:50:08 +0800 | [diff] [blame] | 80 | |
Thomas Vachuska | 96a303c | 2015-04-28 16:04:50 -0700 | [diff] [blame] | 81 | # Remove any previous ON.Lab bits from ~/.m2 repo. |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 82 | rm -fr ~/.m2/repository/org/onosproject |
tom | 9ccb251 | 2014-10-07 12:54:53 -0700 | [diff] [blame] | 83 | |
Bob Lantz | 0b13c1b | 2016-02-25 05:18:54 -0800 | [diff] [blame] | 84 | [ ! -z $mvn_settings ] && cp /tmp/settings.xml ~/.m2/settings.xml |
Kenji HIKICHI | 237787c | 2015-01-06 19:57:44 +0900 | [diff] [blame] | 85 | |
tom | 9ccb251 | 2014-10-07 12:54:53 -0700 | [diff] [blame] | 86 | # Drop log level for the console |
Bob Lantz | 0b13c1b | 2016-02-25 05:18:54 -0800 | [diff] [blame] | 87 | echo 'log4j.logger.org.apache.sshd = WARN' \ |
Thomas Vachuska | e9fc596 | 2014-10-21 16:10:12 -0700 | [diff] [blame] | 88 | >> $ONOS_INSTALL_DIR/$KARAF_DIST/etc/org.ops4j.pax.logging.cfg |
tom | 9ccb251 | 2014-10-07 12:54:53 -0700 | [diff] [blame] | 89 | |
Jonathan Hart | 5de9105 | 2016-05-24 09:50:55 -0700 | [diff] [blame] | 90 | # Set up the ONOS service on systemd-based systems |
| 91 | sudo systemctl daemon-reload || true |
| 92 | |
tom | 5c25570 | 2014-09-18 06:57:39 -0700 | [diff] [blame] | 93 | " |
tom | 0768a02 | 2014-09-24 16:16:16 -0700 | [diff] [blame] | 94 | |
| 95 | # Configure the ONOS installation |
| 96 | onos-config $node |
| 97 | |
Thomas Vachuska | e9fc596 | 2014-10-21 16:10:12 -0700 | [diff] [blame] | 98 | # Unless -n option was given, attempt to ignite the ONOS service. |
| 99 | [ -z "$nostart" ] && onos-service $node start |