nova-solver-scheduler/installation/uninstall.sh

120 lines
3.8 KiB
Bash
Executable File

#!/bin/bash
# Copyright (c) 2014 Cisco Systems Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
_NOVA_CONF_DIR="/etc/nova"
_NOVA_CONF_FILE="nova.conf"
_NOVA_DIR="/usr/lib/python2.7/dist-packages/nova"
# if you did not make changes to the installation files,
# please do not edit the following directories.
_CODE_DIR="../nova"
_BACKUP_DIR="${_NOVA_DIR}/.solver-scheduler-installation-backup"
#_SCRIPT_NAME="${0##*/}"
#_SCRIPT_LOGFILE="/var/log/nova-solver-scheduler/installation/${_SCRIPT_NAME}.log"
if [[ ${EUID} -ne 0 ]]; then
echo "Please run as root."
exit 1
fi
##Redirecting output to logfile as well as stdout
#exec > >(tee -a ${_SCRIPT_LOGFILE})
#exec 2> >(tee -a ${_SCRIPT_LOGFILE} >&2)
cd `dirname $0`
echo "checking installation directories..."
if [ ! -d "${_NOVA_DIR}" ] ; then
echo "Could not find the nova installation. Please check the variables in the beginning of the script."
echo "aborted."
exit 1
fi
if [ ! -f "${_NOVA_CONF_DIR}/${_NOVA_CONF_FILE}" ] ; then
echo "Could not find nova config file. Please check the variables in the beginning of the script."
echo "aborted."
exit 1
fi
echo "checking backup..."
if [ ! -d "${_BACKUP_DIR}/nova" ] ; then
echo "Could not find backup files. It is possible that the solver-scheduler has been uninstalled."
echo "If this is not the case, then please uninstall manually."
exit 1
fi
echo "backing up current files that might be overwritten..."
if [ -d "${_BACKUP_DIR}/uninstall" ] ; then
rm -r "${_BACKUP_DIR}/uninstall"
fi
mkdir -p "${_BACKUP_DIR}/uninstall/nova"
mkdir -p "${_BACKUP_DIR}/uninstall/etc/nova"
cp -r "${_NOVA_DIR}/scheduler" "${_BACKUP_DIR}/uninstall/nova/" && cp -r "${_NOVA_DIR}/volume" "${_BACKUP_DIR}/uninstall/nova/"
if [ $? -ne 0 ] ; then
rm -r "${_BACKUP_DIR}/uninstall/nova"
echo "Error in code backup, aborted."
exit 1
fi
cp "${_NOVA_CONF_DIR}/${_NOVA_CONF_FILE}" "${_BACKUP_DIR}/uninstall/etc/nova/"
if [ $? -ne 0 ] ; then
rm -r "${_BACKUP_DIR}/uninstall/nova"
rm -r "${_BACKUP_DIR}/uninstall/etc"
echo "Error in config backup, aborted."
exit 1
fi
echo "restoring code to the status before installing solver-scheduler..."
cp -r "${_BACKUP_DIR}/nova" `dirname ${_NOVA_DIR}`
if [ $? -ne 0 ] ; then
echo "Error in copying, aborted."
echo "Recovering current files..."
cp -r "${_BACKUP_DIR}/uninstall/nova" `dirname ${_NOVA_DIR}`
if [ $? -ne 0 ] ; then
echo "Recovering failed! Please uninstall manually."
fi
exit 1
fi
echo "updating config file..."
sed -i.uninstall.backup -e "/scheduler_driver *=/d" "${_NOVA_CONF_DIR}/${_NOVA_CONF_FILE}"
if [ $? -ne 0 ] ; then
echo "Error in updating, aborted."
echo "Recovering current files..."
cp "${_BACKUP_DIR}/uninstall/etc/nova/${_NOVA_CONF_FILE}" "${_NOVA_CONF_DIR}"
if [ $? -ne 0 ] ; then
echo "Recovering failed! Please uninstall manually."
fi
exit 1
fi
echo "cleaning up backup files..."
rm -r "${_BACKUP_DIR}/nova" && rm -r "${_BACKUP_DIR}/etc"
if [ $? -ne 0 ] ; then
echo "There was an error when cleaning up the backup files."
fi
echo "restarting nova scheduler..."
service nova-scheduler restart
if [ $? -ne 0 ] ; then
echo "There was an error in restarting the service, please restart nova scheduler manually."
exit 1
fi
echo "Completed."
exit 0