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 | |
Kenji HIKICHI | 237787c | 2015-01-06 19:57:44 +0900 | [diff] [blame] | 39 | while getopts fnm: 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;; |
Thomas Vachuska | e9fc596 | 2014-10-21 16:10:12 -0700 | [diff] [blame] | 47 | esac |
| 48 | done |
| 49 | let OPC=$OPTIND-1 |
| 50 | shift $OPC |
| 51 | |
| 52 | # If the -f was given, attempt uninstall first. |
| 53 | [ -n "$uninstall" ] && onos-uninstall ${1:-$OCI} |
tom | 3014aef | 2014-09-18 08:44:39 -0700 | [diff] [blame] | 54 | |
tom | 0768a02 | 2014-09-24 16:16:16 -0700 | [diff] [blame] | 55 | node=${1:-$OCI} |
| 56 | remote=$ONOS_USER@$node |
tom | 5c25570 | 2014-09-18 06:57:39 -0700 | [diff] [blame] | 57 | |
Thomas Vachuska | 52e6580 | 2014-12-08 09:26:01 -0800 | [diff] [blame] | 58 | $(dirname $0)/onos-push-bits $node |
tom | 5c25570 | 2014-09-18 06:57:39 -0700 | [diff] [blame] | 59 | |
Kenji HIKICHI | 237787c | 2015-01-06 19:57:44 +0900 | [diff] [blame] | 60 | [ ! -z "$mvn_settings" ] && scp -q $mvn_settings $remote:/tmp/settings.xml |
| 61 | |
Bob Lantz | 7c751b5 | 2016-04-15 15:42:28 -0700 | [diff] [blame] | 62 | ssh -tt $remote " |
tom | 3014aef | 2014-09-18 08:44:39 -0700 | [diff] [blame] | 63 | [ -d $ONOS_INSTALL_DIR/bin ] && echo \"ONOS is already installed\" && exit 1 |
| 64 | |
tom | 1f3805d | 2014-09-18 19:58:47 -0700 | [diff] [blame] | 65 | # Prepare a landing zone and unroll the bits |
Charles M.C. Chan | dfbc6d8 | 2014-12-18 23:11:36 +0800 | [diff] [blame] | 66 | 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] | 67 | tar zxmf /tmp/$ONOS_BITS.tar.gz -C $ONOS_INSTALL_DIR --strip-components=1 |
| 68 | |
tom | 0eaa97f | 2014-09-22 16:13:06 -0700 | [diff] [blame] | 69 | # 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] | 70 | ln -s $ONOS_INSTALL_DIR/$KARAF_DIST/data/log /opt/onos/log |
Jonathan Hart | f51950d | 2016-01-15 09:57:10 -0800 | [diff] [blame] | 71 | ln -s $ONOS_INSTALL_DIR/$KARAF_DIST /opt/onos/karaf |
tom | 0eaa97f | 2014-09-22 16:13:06 -0700 | [diff] [blame] | 72 | mkdir $ONOS_INSTALL_DIR/var |
tom | defed6f | 2014-09-29 11:37:02 -0700 | [diff] [blame] | 73 | mkdir $ONOS_INSTALL_DIR/config |
tom | 0eaa97f | 2014-09-22 16:13:06 -0700 | [diff] [blame] | 74 | |
Bob Lantz | 0b13c1b | 2016-02-25 05:18:54 -0800 | [diff] [blame] | 75 | # 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 |
Bob Lantz | d22c991 | 2016-12-15 14:26:18 -0800 | [diff] [blame] | 78 | [ -n $nosysd ] && sudo cp $ONOS_INSTALL_DIR/init/onos.service /etc/systemd/system/onos.service |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 79 | echo 'export ONOS_OPTS=debug' > $ONOS_INSTALL_DIR/options |
tom | 0eaa97f | 2014-09-22 16:13:06 -0700 | [diff] [blame] | 80 | |
Bob Lantz | 0b13c1b | 2016-02-25 05:18:54 -0800 | [diff] [blame] | 81 | # Set up correct user to run onos-service |
| 82 | echo 'export ONOS_USER=$ONOS_USER' >> $ONOS_INSTALL_DIR/options |
Charles M.C. Chan | 0a4fa79 | 2014-12-11 18:50:08 +0800 | [diff] [blame] | 83 | |
Thomas Vachuska | 96a303c | 2015-04-28 16:04:50 -0700 | [diff] [blame] | 84 | # Remove any previous ON.Lab bits from ~/.m2 repo. |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 85 | rm -fr ~/.m2/repository/org/onosproject |
tom | 9ccb251 | 2014-10-07 12:54:53 -0700 | [diff] [blame] | 86 | |
Bob Lantz | 0b13c1b | 2016-02-25 05:18:54 -0800 | [diff] [blame] | 87 | [ ! -z $mvn_settings ] && cp /tmp/settings.xml ~/.m2/settings.xml |
Kenji HIKICHI | 237787c | 2015-01-06 19:57:44 +0900 | [diff] [blame] | 88 | |
tom | 9ccb251 | 2014-10-07 12:54:53 -0700 | [diff] [blame] | 89 | # Drop log level for the console |
Bob Lantz | 0b13c1b | 2016-02-25 05:18:54 -0800 | [diff] [blame] | 90 | echo 'log4j.logger.org.apache.sshd = WARN' \ |
Thomas Vachuska | e9fc596 | 2014-10-21 16:10:12 -0700 | [diff] [blame] | 91 | >> $ONOS_INSTALL_DIR/$KARAF_DIST/etc/org.ops4j.pax.logging.cfg |
tom | 9ccb251 | 2014-10-07 12:54:53 -0700 | [diff] [blame] | 92 | |
Yuta HIGUCHI | 6ee6b8c | 2017-05-09 14:44:30 -0700 | [diff] [blame] | 93 | # remove verbose bundle detail from log layout |
| 94 | echo 'log4j.appender.out.layout.ConversionPattern=%d{ISO8601} | %-5.5p | %-16.16t | %-32.32c{1} | %X{bundle.id} | %m%n' \ |
| 95 | >> $ONOS_INSTALL_DIR/$KARAF_DIST/etc/org.ops4j.pax.logging.cfg |
| 96 | |
Jonathan Hart | 5de9105 | 2016-05-24 09:50:55 -0700 | [diff] [blame] | 97 | # Set up the ONOS service on systemd-based systems |
| 98 | sudo systemctl daemon-reload || true |
| 99 | |
tom | 5c25570 | 2014-09-18 06:57:39 -0700 | [diff] [blame] | 100 | " |
tom | 0768a02 | 2014-09-24 16:16:16 -0700 | [diff] [blame] | 101 | |
| 102 | # Configure the ONOS installation |
| 103 | onos-config $node |
| 104 | |
Thomas Vachuska | e9fc596 | 2014-10-21 16:10:12 -0700 | [diff] [blame] | 105 | # Unless -n option was given, attempt to ignite the ONOS service. |
Brian O'Connor | 13081ca | 2017-06-29 22:35:39 -0700 | [diff] [blame^] | 106 | [ -z "$nostart" ] && onos-service $node start || true |