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) |
Bob Lantz | d22c991 | 2016-12-15 14:26:18 -0800 | [diff] [blame] | 15 | - -s : don't install onos.service systemd configuration file |
Bob Lantz | 0b13c1b | 2016-02-25 05:18:54 -0800 | [diff] [blame] | 16 | - -n : don't try to start ONOS |
Ayaka Koshibe | f17f34a | 2015-09-24 19:31:48 -0700 | [diff] [blame] | 17 | - -m <settings> : pass <settings> XML file to remote maven installation |
| 18 | |
| 19 | options: |
| 20 | - [node] : remote node to install ONOS on. |
| 21 | |
| 22 | summary: |
| 23 | Remotely pushes bits to a remote node and installs ONOS on it. |
| 24 | |
Bob Lantz | 0b13c1b | 2016-02-25 05:18:54 -0800 | [diff] [blame] | 25 | The -u should be used on upstart-based systems. |
Ayaka Koshibe | f17f34a | 2015-09-24 19:31:48 -0700 | [diff] [blame] | 26 | |
| 27 | If [node] is not specified the default target is \$OCI. |
| 28 | |
| 29 | _EOF_ |
| 30 | } |
| 31 | |
| 32 | [ "$1" = "-h" ] && _usage && exit 0 |
| 33 | |
tom | 5c25570 | 2014-09-18 06:57:39 -0700 | [diff] [blame] | 34 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
| 35 | . $ONOS_ROOT/tools/build/envDefaults |
| 36 | |
Ray Milkey | bb7e57b | 2016-11-09 10:00:13 -0800 | [diff] [blame] | 37 | onos-check-bits |
| 38 | |
Jordan Halterman | 980a8c1 | 2017-09-22 18:01:19 -0700 | [diff] [blame] | 39 | while getopts fnvm: o; do |
Thomas Vachuska | e9fc596 | 2014-10-21 16:10:12 -0700 | [diff] [blame] | 40 | case "$o" in |
| 41 | f) uninstall=true;; |
Bob Lantz | d22c991 | 2016-12-15 14:26:18 -0800 | [diff] [blame] | 42 | u) noupstart=true; noinitd=true; nosysd=true;; |
| 43 | i) noinitd=true; nosysd=true;; |
| 44 | s) nosysd=true;; |
Thomas Vachuska | e9fc596 | 2014-10-21 16:10:12 -0700 | [diff] [blame] | 45 | n) nostart=true;; |
Kenji HIKICHI | 237787c | 2015-01-06 19:57:44 +0900 | [diff] [blame] | 46 | m) mvn_settings=$OPTARG;; |
Jordan Halterman | 980a8c1 | 2017-09-22 18:01:19 -0700 | [diff] [blame] | 47 | v) upgrade=true;; |
Thomas Vachuska | e9fc596 | 2014-10-21 16:10:12 -0700 | [diff] [blame] | 48 | esac |
| 49 | done |
| 50 | let OPC=$OPTIND-1 |
| 51 | shift $OPC |
| 52 | |
| 53 | # If the -f was given, attempt uninstall first. |
| 54 | [ -n "$uninstall" ] && onos-uninstall ${1:-$OCI} |
tom | 3014aef | 2014-09-18 08:44:39 -0700 | [diff] [blame] | 55 | |
tom | 0768a02 | 2014-09-24 16:16:16 -0700 | [diff] [blame] | 56 | node=${1:-$OCI} |
| 57 | remote=$ONOS_USER@$node |
tom | 5c25570 | 2014-09-18 06:57:39 -0700 | [diff] [blame] | 58 | |
Thomas Vachuska | 52e6580 | 2014-12-08 09:26:01 -0800 | [diff] [blame] | 59 | $(dirname $0)/onos-push-bits $node |
tom | 5c25570 | 2014-09-18 06:57:39 -0700 | [diff] [blame] | 60 | |
Kenji HIKICHI | 237787c | 2015-01-06 19:57:44 +0900 | [diff] [blame] | 61 | [ ! -z "$mvn_settings" ] && scp -q $mvn_settings $remote:/tmp/settings.xml |
| 62 | |
Bob Lantz | 7c751b5 | 2016-04-15 15:42:28 -0700 | [diff] [blame] | 63 | ssh -tt $remote " |
Jordan Halterman | 980a8c1 | 2017-09-22 18:01:19 -0700 | [diff] [blame] | 64 | [ -z "$upgrade" ] && [ -d $ONOS_INSTALL_DIR/bin ] && echo \"ONOS is already installed\" && exit 1 |
tom | 3014aef | 2014-09-18 08:44:39 -0700 | [diff] [blame] | 65 | |
tom | 1f3805d | 2014-09-18 19:58:47 -0700 | [diff] [blame] | 66 | # Prepare a landing zone and unroll the bits |
Charles M.C. Chan | dfbc6d8 | 2014-12-18 23:11:36 +0800 | [diff] [blame] | 67 | 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] | 68 | tar zxmf /tmp/$ONOS_BITS.tar.gz -C $ONOS_INSTALL_DIR --strip-components=1 |
| 69 | |
tom | 0eaa97f | 2014-09-22 16:13:06 -0700 | [diff] [blame] | 70 | # 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] | 71 | ln -s $ONOS_INSTALL_DIR/$KARAF_DIST/data/log /opt/onos/log |
Jonathan Hart | f51950d | 2016-01-15 09:57:10 -0800 | [diff] [blame] | 72 | ln -s $ONOS_INSTALL_DIR/$KARAF_DIST /opt/onos/karaf |
tom | 0eaa97f | 2014-09-22 16:13:06 -0700 | [diff] [blame] | 73 | mkdir $ONOS_INSTALL_DIR/var |
tom | defed6f | 2014-09-29 11:37:02 -0700 | [diff] [blame] | 74 | mkdir $ONOS_INSTALL_DIR/config |
tom | 0eaa97f | 2014-09-22 16:13:06 -0700 | [diff] [blame] | 75 | |
Bob Lantz | 0b13c1b | 2016-02-25 05:18:54 -0800 | [diff] [blame] | 76 | # Install the configuration file(s) and set up options for debugging |
| 77 | [ -n $noupstart ] && sudo cp $ONOS_INSTALL_DIR/init/onos.conf /etc/init/onos.conf |
| 78 | [ -n $noinitd ] && sudo cp $ONOS_INSTALL_DIR/init/onos.initd /etc/init.d/onos |
Bob Lantz | d22c991 | 2016-12-15 14:26:18 -0800 | [diff] [blame] | 79 | [ -n $nosysd ] && sudo cp $ONOS_INSTALL_DIR/init/onos.service /etc/systemd/system/onos.service |
Jordan Halterman | 85147d0 | 2018-02-07 11:58:59 -0800 | [diff] [blame] | 80 | |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 81 | echo 'export ONOS_OPTS=debug' > $ONOS_INSTALL_DIR/options |
tom | 0eaa97f | 2014-09-22 16:13:06 -0700 | [diff] [blame] | 82 | |
Jordan Halterman | 85147d0 | 2018-02-07 11:58:59 -0800 | [diff] [blame] | 83 | if [ ! -z "$ONOS_YOURKIT" ]; then |
| 84 | sudo apt-get install unzip |
| 85 | cd /tmp |
| 86 | wget -N https://www.yourkit.com/download/YourKit-JavaProfiler-${ONOS_YOURKIT}.zip |
| 87 | unzip -o YourKit-JavaProfiler-${ONOS_YOURKIT}.zip |
| 88 | rm YourKit-JavaProfiler-${ONOS_YOURKIT}.zip |
| 89 | mv /tmp/YourKit-JavaProfiler-$(echo $ONOS_YOURKIT | sed 's/\(.*\)-.*/\1/')/bin/linux-x86-64/libyjpagent.so $ONOS_INSTALL_DIR/libyjpagent.so |
Jordan Halterman | 4ed92ec | 2018-05-10 23:28:58 -0700 | [diff] [blame] | 90 | echo -e 'export JAVA_OPTS="${JAVA_OPTS:--agentpath:$ONOS_INSTALL_DIR/libyjpagent.so}=listen=all"' >> $ONOS_INSTALL_DIR/options |
Jordan Halterman | 85147d0 | 2018-02-07 11:58:59 -0800 | [diff] [blame] | 91 | fi |
| 92 | |
Bob Lantz | 0b13c1b | 2016-02-25 05:18:54 -0800 | [diff] [blame] | 93 | # Set up correct user to run onos-service |
| 94 | echo 'export ONOS_USER=$ONOS_USER' >> $ONOS_INSTALL_DIR/options |
Charles M.C. Chan | 0a4fa79 | 2014-12-11 18:50:08 +0800 | [diff] [blame] | 95 | |
Jordan Halterman | 980a8c1 | 2017-09-22 18:01:19 -0700 | [diff] [blame] | 96 | # If the upgrade flag is set, append ".upgrade" to the version string. |
| 97 | if [ ! -z "$upgrade" ] |
| 98 | then |
| 99 | echo '.upgrade' >> $ONOS_INSTALL_DIR/VERSION |
| 100 | fi |
| 101 | |
Thomas Vachuska | a10137c | 2018-04-03 16:45:59 -0700 | [diff] [blame] | 102 | # Remove any previous Open Networking Foundation bits from ~/.m2 repo. |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 103 | rm -fr ~/.m2/repository/org/onosproject |
tom | 9ccb251 | 2014-10-07 12:54:53 -0700 | [diff] [blame] | 104 | |
Bob Lantz | 0b13c1b | 2016-02-25 05:18:54 -0800 | [diff] [blame] | 105 | [ ! -z $mvn_settings ] && cp /tmp/settings.xml ~/.m2/settings.xml |
Kenji HIKICHI | 237787c | 2015-01-06 19:57:44 +0900 | [diff] [blame] | 106 | |
tom | 9ccb251 | 2014-10-07 12:54:53 -0700 | [diff] [blame] | 107 | # Drop log level for the console |
Bob Lantz | 0b13c1b | 2016-02-25 05:18:54 -0800 | [diff] [blame] | 108 | echo 'log4j.logger.org.apache.sshd = WARN' \ |
Thomas Vachuska | e9fc596 | 2014-10-21 16:10:12 -0700 | [diff] [blame] | 109 | >> $ONOS_INSTALL_DIR/$KARAF_DIST/etc/org.ops4j.pax.logging.cfg |
tom | 9ccb251 | 2014-10-07 12:54:53 -0700 | [diff] [blame] | 110 | |
Yuta HIGUCHI | 6ee6b8c | 2017-05-09 14:44:30 -0700 | [diff] [blame] | 111 | # remove verbose bundle detail from log layout |
| 112 | echo 'log4j.appender.out.layout.ConversionPattern=%d{ISO8601} | %-5.5p | %-16.16t | %-32.32c{1} | %X{bundle.id} | %m%n' \ |
| 113 | >> $ONOS_INSTALL_DIR/$KARAF_DIST/etc/org.ops4j.pax.logging.cfg |
| 114 | |
Thomas Vachuska | 5ca0f7a | 2017-11-28 16:27:22 -0800 | [diff] [blame] | 115 | # Set up and enable the ONOS service on systemd-based systems |
| 116 | sudo systemctl daemon-reload && sudo systemctl enable onos.service || true |
Jonathan Hart | 5de9105 | 2016-05-24 09:50:55 -0700 | [diff] [blame] | 117 | |
tom | 5c25570 | 2014-09-18 06:57:39 -0700 | [diff] [blame] | 118 | " |
tom | 0768a02 | 2014-09-24 16:16:16 -0700 | [diff] [blame] | 119 | |
| 120 | # Configure the ONOS installation |
| 121 | onos-config $node |
| 122 | |
Brian O'Connor | 740e98c | 2017-06-29 17:07:17 -0700 | [diff] [blame] | 123 | # Upload the shared cluster key if present |
| 124 | [ -f "$ONOS_CLUSTER_KEY_FILE" ] && onos-push-cluster-key $1 |
| 125 | |
Thomas Vachuska | e9fc596 | 2014-10-21 16:10:12 -0700 | [diff] [blame] | 126 | # Unless -n option was given, attempt to ignite the ONOS service. |
Brian O'Connor | 13081ca | 2017-06-29 22:35:39 -0700 | [diff] [blame] | 127 | [ -z "$nostart" ] && onos-service $node start || true |