upload.in 3.05 KB
Newer Older
1
#!/bin/bash
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

# Copyright (C) 2006, 2007 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.

# This is a test script to ease development and testing on test clusters.
# It should not be used to update production environments.

# Usage: upload.sh node-{1,2,3}
# it will upload the python libraries to
# $prefix/lib/python2.4/site-packages/ganeti and the command line utils to
26
# $prefix/sbin. It needs passwordless root login to the nodes.
27
28

set -e
29

Iustin Pop's avatar
Iustin Pop committed
30
31
32
33
PREFIX='@PREFIX@'
SYSCONFDIR='@SYSCONFDIR@'
PKGLIBDIR='@PKGLIBDIR@'

34
NO_RESTART=
Iustin Pop's avatar
Iustin Pop committed
35
NO_CRON=
36
NO_DEBUG=
37
38
39
40
41
42
hosts=
while [ "$#" -gt 0 ]; do
  opt="$1"
  case "$opt" in
    --no-restart)
      NO_RESTART=1
Iustin Pop's avatar
Iustin Pop committed
43
44
45
46
      ;;
    --no-cron)
      NO_CRON=1
      ;;
47
48
49
    --no-debug)
      NO_DEBUG=1
      ;;
50
51
52
53
    -h|--help)
      echo "Usage: $0 [--no-restart] hosts..."
      exit 0
      ;;
54
55
56
    -*)
      echo "Unknown option: $opt" >&2
      exit 1
Iustin Pop's avatar
Iustin Pop committed
57
      ;;
58
59
    *)
      hosts="$hosts $opt"
Iustin Pop's avatar
Iustin Pop committed
60
      ;;
61
62
63
64
65
66
  esac
  shift
done

set ${hosts}

67
68
69
TXD=`mktemp -d`
trap 'rm -rf $TXD' EXIT

70
if [[ -f /proc/cpuinfo ]]; then
71
  cpu_count=$(grep -E -c '^processor[[:space:]]*:' /proc/cpuinfo)
72
73
74
75
76
  make_args=-j$(( cpu_count + 1 ))
else
  make_args=
fi

77
# install ganeti as a real tree
78
make $make_args install DESTDIR="$TXD"
79

Iustin Pop's avatar
Iustin Pop committed
80
# copy additional needed files
81
[ -f doc/examples/ganeti.initd ] && \
Iustin Pop's avatar
Iustin Pop committed
82
83
84
install -D --mode=0755 doc/examples/ganeti.initd \
  "$TXD/$SYSCONFDIR/init.d/ganeti"

85
[ -f doc/examples/ganeti.default-debug -a -z "$NO_DEBUG" ] && \
86
87
88
install -D --mode=0644 doc/examples/ganeti.default-debug \
  "$TXD/$SYSCONFDIR/default/ganeti"

89
[ -f doc/examples/bash_completion ] && \
Iustin Pop's avatar
Iustin Pop committed
90
91
92
install -D --mode=0644 doc/examples/bash_completion \
  "$TXD/$SYSCONFDIR/bash_completion.d/ganeti"

93
if [ -f doc/examples/ganeti.cron -a -z "$NO_CRON" ]; then
Iustin Pop's avatar
Iustin Pop committed
94
95
96
97
  install -D --mode=0644 doc/examples/ganeti.cron \
    "$TXD/$SYSCONFDIR/cron.d/ganeti"
fi

98
[ -f doc/examples/dumb-allocator ] && \
Iustin Pop's avatar
Iustin Pop committed
99
100
101
install -D --mode=0755 doc/examples/dumb-allocator \
  "$TXD/$PKGLIBDIR/iallocators/dumb"

102
103
104
105
106
107
108
109
110
echo ---

( cd "$TXD" && find; )

echo ---

# and now put it under $prefix on the target node(s)
for host; do
  echo Uploading code to ${host}...
111
112
113
  rsync -v -rlDc \
    -e "ssh -oBatchMode=yes" \
    --exclude="*.py[oc]" --exclude="*.pdf" --exclude="*.html" \
Iustin Pop's avatar
Iustin Pop committed
114
115
    "$TXD/" \
    root@${host}:/ &
116
117
118
done
wait

119
120
121
if test -z "${NO_RESTART}"; then
  for host; do
    echo Restarting ganeti-noded on ${host}...
122
    ssh -oBatchMode=yes root@${host} /etc/init.d/ganeti restart &
123
124
125
  done
  wait
fi