| #!/bin/bash |
| |
| # Copyright (C) 2006, 2007, 2008, 2009, 2010, 2012, 2013 Google Inc. |
| # All rights reserved. |
| # |
| # Redistribution and use in source and binary forms, with or without |
| # modification, are permitted provided that the following conditions are |
| # met: |
| # |
| # 1. Redistributions of source code must retain the above copyright notice, |
| # this list of conditions and the following disclaimer. |
| # |
| # 2. Redistributions in binary form must reproduce the above copyright |
| # notice, this list of conditions and the following disclaimer in the |
| # documentation and/or other materials provided with the distribution. |
| # |
| # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
| # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| |
| # This is a test script to ease development and testing on test clusters. |
| # It should not be used to update production environments. |
| |
| # Usage: upload node-{1,2,3} |
| # it will upload the python libraries to |
| # $prefix/lib/python2.X/dist-packages/ganeti and the command line utils to |
| # $prefix/sbin. It needs passwordless root login to the nodes. |
| |
| set -e -u |
| |
| usage() { |
| echo "Usage: $0 [--no-restart] [--no-cron] [--no-debug] hosts..." >&2 |
| exit $1 |
| } |
| |
| declare -r SED="sed -f autotools/replace_vars.sed" |
| |
| NO_RESTART= |
| NO_CRON= |
| NO_DEBUG= |
| hosts= |
| while [ "$#" -gt 0 ]; do |
| opt="$1" |
| case "$opt" in |
| --no-restart) |
| NO_RESTART=1 |
| ;; |
| --no-cron) |
| NO_CRON=1 |
| ;; |
| --no-debug) |
| NO_DEBUG=1 |
| ;; |
| -h|--help) |
| usage 0 |
| ;; |
| -*) |
| echo "Unknown option: $opt" >&2 |
| usage 1 |
| ;; |
| *) |
| hosts="$hosts $opt" |
| ;; |
| esac |
| shift |
| done |
| |
| if [ -z "$hosts" ]; then |
| usage 1 |
| fi |
| |
| set ${hosts} |
| |
| make regen-vcs-version |
| |
| TXD=`mktemp -d` |
| trap 'rm -rf $TXD' EXIT |
| |
| if [[ -f /proc/cpuinfo ]]; then |
| cpu_count=$(grep -E -c '^processor[[:space:]]*:' /proc/cpuinfo) |
| make_args=-j$(( cpu_count + 1 )) |
| else |
| make_args= |
| fi |
| |
| # Make sure that directories will get correct permissions |
| umask 0022 |
| |
| # install ganeti as a real tree |
| make $make_args install DESTDIR="$TXD" |
| |
| # at this point, make has been finished, so the configuration is |
| # fixed; we can read the prefix vars/etc. |
| PREFIX="$(echo @PREFIX@ | $SED)" |
| SYSCONFDIR="$(echo @SYSCONFDIR@ | $SED)" |
| LIBDIR="$(echo @LIBDIR@ | $SED)" |
| PKGLIBDIR="$(echo @PKGLIBDIR@ | $SED)" |
| |
| # copy additional needed files |
| [ -f doc/examples/ganeti.initd ] && \ |
| install -D --mode=0755 doc/examples/ganeti.initd \ |
| "$TXD/$SYSCONFDIR/init.d/ganeti" |
| |
| [ -f doc/examples/ganeti.logrotate ] && \ |
| install -D --mode=0755 doc/examples/ganeti.logrotate \ |
| "$TXD/$SYSCONFDIR/logrotate.d/ganeti" |
| |
| [ -f doc/examples/ganeti-master-role.ocf ] && \ |
| install -D --mode=0755 doc/examples/ganeti-master-role.ocf \ |
| "$TXD/$LIBDIR/ocf/resource.d/ganeti/ganeti-master-role" |
| |
| [ -f doc/examples/ganeti-node-role.ocf ] && \ |
| install -D --mode=0755 doc/examples/ganeti-node-role.ocf \ |
| "$TXD/$LIBDIR/ocf/resource.d/ganeti/ganeti-node-role" |
| |
| [ -f doc/examples/ganeti.default-debug -a -z "$NO_DEBUG" ] && \ |
| install -D --mode=0644 doc/examples/ganeti.default-debug \ |
| "$TXD/$SYSCONFDIR/default/ganeti" |
| |
| [ -f doc/examples/bash_completion-debug ] && \ |
| install -D --mode=0644 doc/examples/bash_completion-debug \ |
| "$TXD/$SYSCONFDIR/bash_completion.d/ganeti" |
| |
| if [ -f doc/examples/ganeti.cron -a -z "$NO_CRON" ]; then |
| install -D --mode=0644 doc/examples/ganeti.cron \ |
| "$TXD/$SYSCONFDIR/cron.d/ganeti" |
| fi |
| |
| echo --- |
| |
| ( cd "$TXD" && find; ) |
| |
| echo --- |
| |
| # and now put it under $prefix on the target node(s) |
| for host; do |
| echo Uploading code to ${host}... |
| rsync -v -rlKDc \ |
| -e "ssh -oBatchMode=yes" \ |
| --exclude="*.py[oc]" --exclude="*.pdf" --exclude="*.html" \ |
| "$TXD/" \ |
| root@${host}:/ & |
| done |
| wait |
| |
| if test -z "${NO_RESTART}"; then |
| for host; do |
| echo Restarting ganeti-noded on ${host}... |
| ssh -oBatchMode=yes root@${host} $SYSCONFDIR/init.d/ganeti restart & |
| done |
| wait |
| fi |