3
#Copyright (c) 2009 Eucalyptus Systems, Inc.
5
#This program is free software: you can redistribute it and/or modify
6
#it under the terms of the GNU General Public License as published by
7
#the Free Software Foundation, only version 3 of the License.
9
#This file is distributed in the hope that it will be useful, but WITHOUT
10
#ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
#FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
#You should have received a copy of the GNU General Public License along
15
#with this program. If not, see <http://www.gnu.org/licenses/>.
17
#Please contact Eucalyptus Systems, Inc., 130 Castilian
18
#Dr., Goleta, CA 93101 USA or visit <http://www.eucalyptus.com/licenses/>
19
#if you need additional information or have any questions.
21
#This file may incorporate work covered under the following copyright and
24
# Software License Agreement (BSD License)
26
# Copyright (c) 2008, Regents of the University of California
29
# Redistribution and use of this software in source and binary forms, with
30
# or without modification, are permitted provided that the following
33
# Redistributions of source code must retain the above copyright notice,
34
# this list of conditions and the following disclaimer.
36
# Redistributions in binary form must reproduce the above copyright
37
# notice, this list of conditions and the following disclaimer in the
38
# documentation and/or other materials provided with the distribution.
40
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
41
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
42
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
43
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
44
# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
46
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
47
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
48
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
49
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
50
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. USERS OF
51
# THIS SOFTWARE ACKNOWLEDGE THE POSSIBLE PRESENCE OF OTHER OPEN SOURCE
52
# LICENSED MATERIAL, COPYRIGHTED MATERIAL OR PATENTED MATERIAL IN THIS
53
# SOFTWARE, AND IF ANY SUCH MATERIAL IS DISCOVERED THE PARTY DISCOVERING
54
# IT MAY INFORM DR. RICH WOLSKI AT THE UNIVERSITY OF CALIFORNIA, SANTA
55
# BARBARA WHO WILL THEN ASCERTAIN THE MOST APPROPRIATE REMEDY, WHICH IN
56
# THE REGENTS’ DISCRETION MAY INCLUDE, WITHOUT LIMITATION, REPLACEMENT
57
# OF THE CODE SO IDENTIFIED, LICENSING OF THE CODE SO IDENTIFIED, OR
58
# WITHDRAWAL OF THE CODE CAPABILITY TO THE EXTENT NEEDED TO COMPLY WITH
59
# ANY SUCH LICENSES OR RIGHTS.
65
OPENSSL="`which openssl 2> /dev/null`"
73
echo "This script attempts to upgrade an old installation of eucalyptus"
75
echo " --help this page"
76
echo " --new <euca_dir> where the new eucalyptus is installed"
77
echo " --old <euca_dir> where the old eucalyptus is installed"
78
echo " --backup <euca_dir> create a backup of an existing eucalyptus installation"
79
echo " --force attempt the upgrade even if a database is detected"
80
echo " --conf upgrade the conf file"
81
echo " --db upgrade the database"
82
echo " --keys upgrade the keys"
86
while [ $# -gt 0 ]; do
87
if [ "$1" = "-h" -o "$1" = "-help" -o "$1" = "?" -o "$1" = "--help" ]; then
91
if [ "$1" = "--db" ]; then
96
if [ "$1" = "--conf" ]; then
101
if [ "$1" = "--keys" ]; then
106
if [ "$1" = "--backup" ]; then
108
echo "--backup requires eucalyptus directory"
115
if [ "$1" = "--new" ]; then
117
echo "--new requires eucalyptus directory"
124
if [ "$1" = "--old" ]; then
126
echo "--old requires eucalyptus directory"
133
if [ "$1" == "--force" ]; then
142
if [ -d "$BACKUP" ]; then
143
# backup useful bits of existing eucalyptus installation
144
echo "Backing up $BACKUP..."
147
mkdir -p /root/eucalyptus.backup.$DATESTR
148
cd /root/eucalyptus.backup.$DATESTR
149
echo "Backing up to /root/eucalyptus.backup.$DATESTR"
151
for i in $EUCADIR/var/lib/eucalyptus/keys/ $EUCADIR/var/lib/eucalyptus/db/ $EUCADIR/etc/eucalyptus/eucalyptus.conf $EUCADIR/etc/eucalyptus/eucalyptus-version
155
EUCABACKUPS="$EUCABACKUPS $i"
158
tar cf - $EUCABACKUPS 2>/dev/null | tar xf - 2>/dev/null
164
# default NEW install and some checks
165
if [ -z "$NEW_EUCA" ]; then
166
echo "Use --new to specify the location of the new installation"
169
if [ -z "$OLD_EUCA" ]; then
170
echo "Use --old to specify the old installation from which we upgrade"
173
if [ ! -e $NEW_EUCA/etc/eucalyptus/eucalyptus-version ]; then
174
echo "cannot locate $NEW_EUCA/etc/eucalyptus/eucalyptus-version, --new must point to a valid eucalyptus installation"
177
new_euca_version="`cat $NEW_EUCA/etc/eucalyptus/eucalyptus-version 2> /dev/null`"
179
if [ ! -e $OLD_EUCA/etc/eucalyptus/eucalyptus-version ]; then
180
echo "Cannot locate $OLD_EUCA/etc/eucalyptus/eucalyptus-version, --old must point to a valid eucalyptus installation/backup. If this is a valid installation and the version file is missing, please create one with the version of eucalyptus you are upgrading from (i.e. '1.6.1')"
183
old_euca_version="`cat $OLD_EUCA/etc/eucalyptus/eucalyptus-version 2> /dev/null`"
186
NEW_EUCA_VER_NUM=`echo $new_euca_version | sed "s/\.//g"`
187
OLD_EUCA_VER_NUM=`echo $old_euca_version | sed "s/\.//g"`
189
# valid version upgrade check
190
if [ $new_euca_version = $old_euca_version ]; then
196
if [ $new_euca_version = "1.6.2" ]; then
197
if [ $old_euca_version != "1.6.1" ]; then
198
echo "Cannot upgrade from $old_euca_version to $new_euca_version, skipping automatic upgrade"
203
echo "Upgrading from version $old_euca_version ($OLD_EUCA_VER_NUM) to $new_euca_version ($NEW_EUCA_VER_NUM)"
204
#if [ `expr $euca_version "<" 1.6` -eq 1 ]; then
205
# echo "$NEW_EUCA is not a 1.6.x Eucalyptus installation"
210
if [ "$CONF" = "Y" ]; then
211
echo "Upgrading configuration file..."
212
if [ "$SAMEVER" = "Y" ]; then
213
cp --preserve -a $OLD_EUCA/etc/eucalyptus/eucalyptus.conf $NEW_EUCA/etc/eucalyptus/eucalyptus.conf
217
# we need euca_conf later (the new version)
218
if [ ! -x $NEW_EUCA/usr/sbin/euca_conf ];
220
echo "Cannot find new $NEW_EUCA/usr/sbin/euca_conf! Skipping automatic upgrade."
224
# upgrade the conf file
225
export EUCALYPTUS="$NEW_EUCA"
226
$EUCALYPTUS/usr/sbin/euca_conf -d $EUCALYPTUS --upgrade-conf $OLD_EUCA/etc/eucalyptus/eucalyptus.conf $EUCALYPTUS/etc/eucalyptus/eucalyptus.conf
231
if [ "$KEYS" = "Y" ]; then
232
echo "Upgrading keys..."
233
for x in `\ls -ad $OLD_EUCA/var/lib/eucalyptus/keys/* 2>&1 | grep -v policy\.xml` ; do
234
cp -a --preserve $x $NEW_EUCA/var/lib/eucalyptus/keys/
239
# upgrade the database (and backup)
240
if [ "$DB" = "Y" ]; then
241
echo "Upgrading database..."
242
if [ $SAMEVER = "Y" ]; then
243
cp --preserve -a $OLD_EUCA/var/lib/eucalyptus/db/* $NEW_EUCA/var/lib/eucalyptus/db/
245
# check we have the right binaries
246
if [ -z "$OPENSSL" ]; then
247
echo "Missing openssl, skipping automatic upgrade."
250
# make sure there are files to upgrade from
251
if ( ls $OLD_EUCA/var/lib/eucalyptus/db/* >/dev/null 2>&1 ); then
253
# upgrade the database
254
export EUCALYPTUS="$NEW_EUCA"
255
FILES=`\ls -1 ${EUCALYPTUS}/usr/share/eucalyptus/*.jar | egrep -v ".*eucalyptus-.*1\.6\.1.*"`
256
for FILE in $FILES; do
257
export CLASSPATH=${FILE}:${CLASSPATH}
259
$OPENSSL pkcs12 -in ${EUCALYPTUS}/var/lib/eucalyptus/keys/euca.p12 -name eucalyptus -name "eucalyptus" -password pass:eucalyptus -passin pass:eucalyptus -passout pass:eucalyptus -nodes 2>/dev/null | grep -A30 "friendlyName: eucalyptus" | grep -A26 "BEGIN RSA" > ${EUCALYPTUS}/var/lib/eucalyptus/keys/cloud-pk.pem
261
export EUCALYPTUS_DB="`echo -n eucalyptus | $OPENSSL dgst -sha256 -sign ${EUCALYPTUS}/var/lib/eucalyptus/keys/cloud-pk.pem -hex 2>/dev/null`"
262
export EUCALYPTUS_CLUSTER_CERT="`openssl pkcs12 -in ${EUCALYPTUS}/var/lib/eucalyptus/keys/clusters.p12 -name eucalyptus -name "eucalyptus" -password pass:eucalyptus -passin pass:eucalyptus -passout pass:eucalyptus -nodes -nokeys 2>/dev/null | sed '1,/friendlyName: cc-/ d ; /friendlyName/,$ d ; /-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/p' -n | openssl base64 | sed '{:q;N;s/\n//g;s/=/./g;s/+/-/g;s/\//_/g;t q}'`"
263
export EUCALYPTUS_NODE_CERT="`openssl pkcs12 -in ${EUCALYPTUS}/var/lib/eucalyptus/keys/clusters.p12 -name eucalyptus -name "eucalyptus" -password pass:eucalyptus -passin pass:eucalyptus -passout pass:eucalyptus -nodes -nokeys 2>/dev/null | sed '1,/friendlyName: nc-/ d ; /friendlyName/,$ d ; /-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/p' -n | openssl base64 | sed '{:q;N;s/\n//g;s/=/./g;s/+/-/g;s/\//_/g;t q}'`"
265
echo "Upgrading your database..."
266
if [ -f ${EUCALYPTUS}/etc/eucalyptus/cloud.d/scripts/Import_${OLD_EUCA_VER_NUM}.groovy ]; then
267
rm -f $NEW_EUCA/var/lib/eucalyptus/db/*.log $NEW_EUCA/var/lib/eucalyptus/db/*.script $NEW_EUCA/var/lib/eucalyptus/db/*.properties
268
if ( ! java org.codehaus.groovy.tools.GroovyStarter --main groovy.ui.GroovyMain --classpath ${EUCALYPTUS}/etc/eucalyptus/cloud.d/scripts:$CLASSPATH \
269
-Deuca.old=${OLD_EUCA} -Deuca.new=${NEW_EUCA} -Deuca.home=${NEW_EUCA} \
270
-Deuca.var.dir=${NEW_EUCA}/var/lib/eucalyptus -Deuca.conf.dir=${NEW_EUCA} -Deuca.log.dir=${NEW_EUCA}/var/log/eucalyptus \
271
${EUCALYPTUS}/etc/eucalyptus/cloud.d/scripts/Import_${OLD_EUCA_VER_NUM}.groovy 2>&1 | egrep -v "(log4j)|(ehcache)" > $EUCALYPTUS/var/log/eucalyptus/upgrade.log ); then
272
echo "Database upgrade failed! Please check your database before using Eucalyptus."
276
echo "Cannot find DB upgrade script from $old_euca_version to $new_euca_version! Skipping DB upgrade."