clean.sh gets rid of all residue of running DevStack except installed
packages and pip modules.
And it eradicates rabbitmq-server and ts erlang dependencies as well as
the other RPC backends and databases.
Change-Id: I2b9a251a0a151c012bae85a5a2f9c2f72e7700be
| 1 | 1 |
new file mode 100755 |
| ... | ... |
@@ -0,0 +1,91 @@ |
| 0 |
+#!/usr/bin/env bash |
|
| 1 |
+ |
|
| 2 |
+# **clean.sh** |
|
| 3 |
+ |
|
| 4 |
+# ``clean.sh`` does its best to eradicate traces of a Grenade |
|
| 5 |
+# run except for the following: |
|
| 6 |
+# - both base and target code repos are left alone |
|
| 7 |
+# - packages (system and pip) are left alone |
|
| 8 |
+ |
|
| 9 |
+# This means that all data files are removed. More?? |
|
| 10 |
+ |
|
| 11 |
+# Keep track of the current devstack directory. |
|
| 12 |
+TOP_DIR=$(cd $(dirname "$0") && pwd) |
|
| 13 |
+ |
|
| 14 |
+# Import common functions |
|
| 15 |
+source $TOP_DIR/functions |
|
| 16 |
+ |
|
| 17 |
+# Load local configuration |
|
| 18 |
+source $TOP_DIR/stackrc |
|
| 19 |
+ |
|
| 20 |
+# Get the variables that are set in stack.sh |
|
| 21 |
+source $TOP_DIR/.stackenv |
|
| 22 |
+ |
|
| 23 |
+# Determine what system we are running on. This provides ``os_VENDOR``, |
|
| 24 |
+# ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME`` |
|
| 25 |
+# and ``DISTRO`` |
|
| 26 |
+GetDistro |
|
| 27 |
+ |
|
| 28 |
+ |
|
| 29 |
+# Import database library |
|
| 30 |
+source $TOP_DIR/lib/database |
|
| 31 |
+source $TOP_DIR/lib/rpc_backend |
|
| 32 |
+ |
|
| 33 |
+source $TOP_DIR/lib/tls |
|
| 34 |
+source $TOP_DIR/lib/horizon |
|
| 35 |
+source $TOP_DIR/lib/keystone |
|
| 36 |
+source $TOP_DIR/lib/glance |
|
| 37 |
+source $TOP_DIR/lib/nova |
|
| 38 |
+source $TOP_DIR/lib/cinder |
|
| 39 |
+source $TOP_DIR/lib/swift |
|
| 40 |
+source $TOP_DIR/lib/ceilometer |
|
| 41 |
+source $TOP_DIR/lib/heat |
|
| 42 |
+source $TOP_DIR/lib/quantum |
|
| 43 |
+source $TOP_DIR/lib/baremetal |
|
| 44 |
+source $TOP_DIR/lib/ldap |
|
| 45 |
+ |
|
| 46 |
+ |
|
| 47 |
+# See if there is anything running... |
|
| 48 |
+# need to adapt when run_service is merged |
|
| 49 |
+SESSION=$(screen -ls | awk '/[0-9].stack/ { print $1 }')
|
|
| 50 |
+if [[ -n "$SESSION" ]]; then |
|
| 51 |
+ # Let unstack.sh do its thing first |
|
| 52 |
+ $TOP_DIR/unstack.sh --all |
|
| 53 |
+fi |
|
| 54 |
+ |
|
| 55 |
+# Clean projects |
|
| 56 |
+cleanup_cinder |
|
| 57 |
+cleanup_glance |
|
| 58 |
+cleanup_keystone |
|
| 59 |
+cleanup_nova |
|
| 60 |
+cleanup_quantum |
|
| 61 |
+cleanup_swift |
|
| 62 |
+ |
|
| 63 |
+# cinder doesn't clean up the volume group as it might be used elsewhere... |
|
| 64 |
+# clean it up if it is a loop device |
|
| 65 |
+VG_DEV=$(sudo losetup -j $DATA_DIR/${VOLUME_GROUP}-backing-file | awk -F':' '/backing-file/ { print $1}')
|
|
| 66 |
+if [[ -n "$VG_DEV" ]]; then |
|
| 67 |
+ sudo losetup -d $VG_DEV |
|
| 68 |
+fi |
|
| 69 |
+ |
|
| 70 |
+#if mount | grep $DATA_DIR/swift/drives; then |
|
| 71 |
+# sudo umount $DATA_DIR/swift/drives/sdb1 |
|
| 72 |
+#fi |
|
| 73 |
+ |
|
| 74 |
+ |
|
| 75 |
+# Clean out /etc |
|
| 76 |
+sudo rm -rf /etc/keystone /etc/glance /etc/nova /etc/cinder /etc/swift |
|
| 77 |
+ |
|
| 78 |
+# Clean out tgt |
|
| 79 |
+sudo rm /etc/tgt/conf.d/* |
|
| 80 |
+ |
|
| 81 |
+# Clean up the message queue |
|
| 82 |
+cleanup_rpc_backend |
|
| 83 |
+cleanup_database |
|
| 84 |
+ |
|
| 85 |
+# Clean up networking... |
|
| 86 |
+# should this be in nova? |
|
| 87 |
+# FIXED_IP_ADDR in br100 |
|
| 88 |
+ |
|
| 89 |
+# Clean up files |
|
| 90 |
+#rm -f .stackenv |
| ... | ... |
@@ -775,6 +775,21 @@ function install_package() {
|
| 775 | 775 |
} |
| 776 | 776 |
|
| 777 | 777 |
|
| 778 |
+# Distro-agnostic package uninstaller |
|
| 779 |
+# uninstall_package package [package ...] |
|
| 780 |
+function uninstall_package() {
|
|
| 781 |
+ if is_ubuntu; then |
|
| 782 |
+ apt_get purge "$@" |
|
| 783 |
+ elif is_fedora; then |
|
| 784 |
+ yum remove -y "$@" |
|
| 785 |
+ elif is_suse; then |
|
| 786 |
+ rpm -e "$@" |
|
| 787 |
+ else |
|
| 788 |
+ exit_distro_not_supported "uninstalling packages" |
|
| 789 |
+ fi |
|
| 790 |
+} |
|
| 791 |
+ |
|
| 792 |
+ |
|
| 778 | 793 |
# Distro-agnostic function to tell if a package is installed |
| 779 | 794 |
# is_package_installed package [package ...] |
| 780 | 795 |
function is_package_installed() {
|
| ... | ... |
@@ -42,6 +42,11 @@ done |
| 42 | 42 |
# This is not an error as multi-node installs will do this on the compute nodes |
| 43 | 43 |
|
| 44 | 44 |
|
| 45 |
+# Get rid of everything enough to cleanly change database backends |
|
| 46 |
+function cleanup_database {
|
|
| 47 |
+ cleanup_database_$DATABASE_TYPE |
|
| 48 |
+} |
|
| 49 |
+ |
|
| 45 | 50 |
# Set the database type based on the configuration |
| 46 | 51 |
function initialize_database_backends {
|
| 47 | 52 |
for backend in $DATABASE_BACKENDS; do |
| ... | ... |
@@ -10,6 +10,24 @@ set +o xtrace |
| 10 | 10 |
|
| 11 | 11 |
register_database mysql |
| 12 | 12 |
|
| 13 |
+# Get rid of everything enough to cleanly change database backends |
|
| 14 |
+function cleanup_database_mysql {
|
|
| 15 |
+ if is_ubuntu; then |
|
| 16 |
+ # Get ruthless with mysql |
|
| 17 |
+ stop_service $MYSQL |
|
| 18 |
+ sudo aptitude purge -y ~nmysql-server |
|
| 19 |
+ sudo rm -rf /var/lib/mysql |
|
| 20 |
+ return |
|
| 21 |
+ elif is_fedora; then |
|
| 22 |
+ MYSQL=mysqld |
|
| 23 |
+ elif is_suse; then |
|
| 24 |
+ MYSQL=mysql |
|
| 25 |
+ else |
|
| 26 |
+ return |
|
| 27 |
+ fi |
|
| 28 |
+ stop_service $MYSQL |
|
| 29 |
+} |
|
| 30 |
+ |
|
| 13 | 31 |
function recreate_database_mysql {
|
| 14 | 32 |
local db=$1 |
| 15 | 33 |
local charset=$2 |
| ... | ... |
@@ -10,6 +10,20 @@ set +o xtrace |
| 10 | 10 |
|
| 11 | 11 |
register_database postgresql |
| 12 | 12 |
|
| 13 |
+# Get rid of everything enough to cleanly change database backends |
|
| 14 |
+function cleanup_database_postgresql {
|
|
| 15 |
+ stop_service postgresql |
|
| 16 |
+ if is_ubuntu; then |
|
| 17 |
+ # Get ruthless with mysql |
|
| 18 |
+ sudo aptitude purge -y ~npostgresql |
|
| 19 |
+ return |
|
| 20 |
+ elif is_fedora; then |
|
| 21 |
+ uninstall_package postgresql-server |
|
| 22 |
+ else |
|
| 23 |
+ return |
|
| 24 |
+ fi |
|
| 25 |
+} |
|
| 26 |
+ |
|
| 13 | 27 |
function recreate_database_postgresql {
|
| 14 | 28 |
local db=$1 |
| 15 | 29 |
local charset=$2 |
| ... | ... |
@@ -59,8 +59,7 @@ GLANCE_HOSTPORT=${GLANCE_HOSTPORT:-$SERVICE_HOST:9292}
|
| 59 | 59 |
function cleanup_glance() {
|
| 60 | 60 |
# kill instances (nova) |
| 61 | 61 |
# delete image files (glance) |
| 62 |
- # This function intentionally left blank |
|
| 63 |
- : |
|
| 62 |
+ sudo rm -rf $GLANCE_CACHE_DIR $GLANCE_IMAGE_DIR $GLANCE_AUTH_CACHE_DIR |
|
| 64 | 63 |
} |
| 65 | 64 |
|
| 66 | 65 |
# configure_glanceclient() - Set config files, create data dirs, etc |
| ... | ... |
@@ -106,6 +106,8 @@ function cleanup_nova() {
|
| 106 | 106 |
# Clean out the instances directory. |
| 107 | 107 |
sudo rm -rf $NOVA_INSTANCES_PATH/* |
| 108 | 108 |
fi |
| 109 |
+ |
|
| 110 |
+ sudo rm -rf $NOVA_STATE_PATH $NOVA_AUTH_CACHE_DIR |
|
| 109 | 111 |
} |
| 110 | 112 |
|
| 111 | 113 |
# configure_novaclient() - Set config files, create data dirs, etc |
| ... | ... |
@@ -308,9 +310,6 @@ EOF" |
| 308 | 308 |
sudo chown -R $STACK_USER $NOVA_INSTANCES_PATH |
| 309 | 309 |
fi |
| 310 | 310 |
fi |
| 311 |
- |
|
| 312 |
- # Clean up old instances |
|
| 313 |
- cleanup_nova |
|
| 314 | 311 |
fi |
| 315 | 312 |
} |
| 316 | 313 |
|
| ... | ... |
@@ -211,8 +211,6 @@ function configure_quantum() {
|
| 211 | 211 |
fi |
| 212 | 212 |
|
| 213 | 213 |
_configure_quantum_debug_command |
| 214 |
- |
|
| 215 |
- _cleanup_quantum |
|
| 216 | 214 |
} |
| 217 | 215 |
|
| 218 | 216 |
function create_nova_conf_quantum() {
|
| ... | ... |
@@ -385,9 +383,9 @@ function stop_quantum() {
|
| 385 | 385 |
fi |
| 386 | 386 |
} |
| 387 | 387 |
|
| 388 |
-# _cleanup_quantum() - Remove residual data files, anything left over from previous |
|
| 388 |
+# cleanup_quantum() - Remove residual data files, anything left over from previous |
|
| 389 | 389 |
# runs that a clean run would need to clean up |
| 390 |
-function _cleanup_quantum() {
|
|
| 390 |
+function cleanup_quantum() {
|
|
| 391 | 391 |
: |
| 392 | 392 |
} |
| 393 | 393 |
|
| ... | ... |
@@ -43,6 +43,38 @@ function check_rpc_backend() {
|
| 43 | 43 |
fi |
| 44 | 44 |
} |
| 45 | 45 |
|
| 46 |
+# clean up after rpc backend - eradicate all traces so changing backends |
|
| 47 |
+# produces a clean switch |
|
| 48 |
+function cleanup_rpc_backend {
|
|
| 49 |
+ if is_service_enabled rabbit; then |
|
| 50 |
+ # Obliterate rabbitmq-server |
|
| 51 |
+ uninstall_package rabbitmq-server |
|
| 52 |
+ sudo killall epmd |
|
| 53 |
+ if is_ubuntu; then |
|
| 54 |
+ # And the Erlang runtime too |
|
| 55 |
+ sudo aptitude purge -y ~nerlang |
|
| 56 |
+ fi |
|
| 57 |
+ elif is_service_enabled qpid; then |
|
| 58 |
+ if is_fedora; then |
|
| 59 |
+ uninstall_package qpid-cpp-server-daemon |
|
| 60 |
+ elif is_ubuntu; then |
|
| 61 |
+ uninstall_package qpidd |
|
| 62 |
+ else |
|
| 63 |
+ exit_distro_not_supported "qpid installation" |
|
| 64 |
+ fi |
|
| 65 |
+ elif is_service_enabled zeromq; then |
|
| 66 |
+ if is_fedora; then |
|
| 67 |
+ uninstall_package zeromq python-zmq |
|
| 68 |
+ elif is_ubuntu; then |
|
| 69 |
+ uninstall_package libzmq1 python-zmq |
|
| 70 |
+ elif is_suse; then |
|
| 71 |
+ uninstall_package libzmq1 python-pyzmq |
|
| 72 |
+ else |
|
| 73 |
+ exit_distro_not_supported "zeromq installation" |
|
| 74 |
+ fi |
|
| 75 |
+ fi |
|
| 76 |
+} |
|
| 77 |
+ |
|
| 46 | 78 |
# install rpc backend |
| 47 | 79 |
function install_rpc_backend() {
|
| 48 | 80 |
if is_service_enabled rabbit; then |
| ... | ... |
@@ -388,9 +388,11 @@ function start_swift() {
|
| 388 | 388 |
# stop_swift() - Stop running processes (non-screen) |
| 389 | 389 |
function stop_swift() {
|
| 390 | 390 |
# screen normally killed by unstack.sh |
| 391 |
- if type -p swift-init >/dev/null;then |
|
| 391 |
+ if type -p swift-init >/dev/null; then |
|
| 392 | 392 |
swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
|
| 393 | 393 |
fi |
| 394 |
+ # Dump the proxy server |
|
| 395 |
+ sudo pkill -f swift-proxy-server |
|
| 394 | 396 |
} |
| 395 | 397 |
|
| 396 | 398 |
# Restore xtrace |