Skip to content

Commit 995eb92

Browse files
author
Dean Troyer
committed
Add clean.sh
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 parent 08fd641 commit 995eb92

File tree

11 files changed

+185
-10
lines changed

11 files changed

+185
-10
lines changed

clean.sh

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env bash
2+
3+
# **clean.sh**
4+
5+
# ``clean.sh`` does its best to eradicate traces of a Grenade
6+
# run except for the following:
7+
# - both base and target code repos are left alone
8+
# - packages (system and pip) are left alone
9+
10+
# This means that all data files are removed. More??
11+
12+
# Keep track of the current devstack directory.
13+
TOP_DIR=$(cd $(dirname "$0") && pwd)
14+
15+
# Import common functions
16+
source $TOP_DIR/functions
17+
18+
# Load local configuration
19+
source $TOP_DIR/stackrc
20+
21+
# Get the variables that are set in stack.sh
22+
source $TOP_DIR/.stackenv
23+
24+
# Determine what system we are running on. This provides ``os_VENDOR``,
25+
# ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME``
26+
# and ``DISTRO``
27+
GetDistro
28+
29+
30+
# Import database library
31+
source $TOP_DIR/lib/database
32+
source $TOP_DIR/lib/rpc_backend
33+
34+
source $TOP_DIR/lib/tls
35+
source $TOP_DIR/lib/horizon
36+
source $TOP_DIR/lib/keystone
37+
source $TOP_DIR/lib/glance
38+
source $TOP_DIR/lib/nova
39+
source $TOP_DIR/lib/cinder
40+
source $TOP_DIR/lib/swift
41+
source $TOP_DIR/lib/ceilometer
42+
source $TOP_DIR/lib/heat
43+
source $TOP_DIR/lib/quantum
44+
source $TOP_DIR/lib/baremetal
45+
source $TOP_DIR/lib/ldap
46+
47+
48+
# See if there is anything running...
49+
# need to adapt when run_service is merged
50+
SESSION=$(screen -ls | awk '/[0-9].stack/ { print $1 }')
51+
if [[ -n "$SESSION" ]]; then
52+
# Let unstack.sh do its thing first
53+
$TOP_DIR/unstack.sh --all
54+
fi
55+
56+
# Clean projects
57+
cleanup_cinder
58+
cleanup_glance
59+
cleanup_keystone
60+
cleanup_nova
61+
cleanup_quantum
62+
cleanup_swift
63+
64+
# cinder doesn't clean up the volume group as it might be used elsewhere...
65+
# clean it up if it is a loop device
66+
VG_DEV=$(sudo losetup -j $DATA_DIR/${VOLUME_GROUP}-backing-file | awk -F':' '/backing-file/ { print $1}')
67+
if [[ -n "$VG_DEV" ]]; then
68+
sudo losetup -d $VG_DEV
69+
fi
70+
71+
#if mount | grep $DATA_DIR/swift/drives; then
72+
# sudo umount $DATA_DIR/swift/drives/sdb1
73+
#fi
74+
75+
76+
# Clean out /etc
77+
sudo rm -rf /etc/keystone /etc/glance /etc/nova /etc/cinder /etc/swift
78+
79+
# Clean out tgt
80+
sudo rm /etc/tgt/conf.d/*
81+
82+
# Clean up the message queue
83+
cleanup_rpc_backend
84+
cleanup_database
85+
86+
# Clean up networking...
87+
# should this be in nova?
88+
# FIXED_IP_ADDR in br100
89+
90+
# Clean up files
91+
#rm -f .stackenv

functions

+15
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,21 @@ function install_package() {
775775
}
776776

777777

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+
778793
# Distro-agnostic function to tell if a package is installed
779794
# is_package_installed package [package ...]
780795
function is_package_installed() {

lib/database

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ done
4242
# This is not an error as multi-node installs will do this on the compute nodes
4343

4444

45+
# Get rid of everything enough to cleanly change database backends
46+
function cleanup_database {
47+
cleanup_database_$DATABASE_TYPE
48+
}
49+
4550
# Set the database type based on the configuration
4651
function initialize_database_backends {
4752
for backend in $DATABASE_BACKENDS; do

lib/databases/mysql

+18
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,24 @@ set +o xtrace
1010

1111
register_database mysql
1212

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+
1331
function recreate_database_mysql {
1432
local db=$1
1533
local charset=$2

lib/databases/postgresql

+14
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ set +o xtrace
1010

1111
register_database postgresql
1212

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+
1327
function recreate_database_postgresql {
1428
local db=$1
1529
local charset=$2

lib/glance

+1-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ GLANCE_HOSTPORT=${GLANCE_HOSTPORT:-$SERVICE_HOST:9292}
5959
function cleanup_glance() {
6060
# kill instances (nova)
6161
# 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
6463
}
6564

6665
# configure_glanceclient() - Set config files, create data dirs, etc

lib/nova

+2-3
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ function cleanup_nova() {
106106
# Clean out the instances directory.
107107
sudo rm -rf $NOVA_INSTANCES_PATH/*
108108
fi
109+
110+
sudo rm -rf $NOVA_STATE_PATH $NOVA_AUTH_CACHE_DIR
109111
}
110112

111113
# configure_novaclient() - Set config files, create data dirs, etc
@@ -308,9 +310,6 @@ EOF"
308310
sudo chown -R $STACK_USER $NOVA_INSTANCES_PATH
309311
fi
310312
fi
311-
312-
# Clean up old instances
313-
cleanup_nova
314313
fi
315314
}
316315

lib/quantum

+2-4
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,6 @@ function configure_quantum() {
211211
fi
212212

213213
_configure_quantum_debug_command
214-
215-
_cleanup_quantum
216214
}
217215

218216
function create_nova_conf_quantum() {
@@ -385,9 +383,9 @@ function stop_quantum() {
385383
fi
386384
}
387385

388-
# _cleanup_quantum() - Remove residual data files, anything left over from previous
386+
# cleanup_quantum() - Remove residual data files, anything left over from previous
389387
# runs that a clean run would need to clean up
390-
function _cleanup_quantum() {
388+
function cleanup_quantum() {
391389
:
392390
}
393391

lib/rpc_backend

+32
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,38 @@ function check_rpc_backend() {
4343
fi
4444
}
4545

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+
4678
# install rpc backend
4779
function install_rpc_backend() {
4880
if is_service_enabled rabbit; then

lib/swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,11 @@ function start_swift() {
388388
# stop_swift() - Stop running processes (non-screen)
389389
function stop_swift() {
390390
# screen normally killed by unstack.sh
391-
if type -p swift-init >/dev/null;then
391+
if type -p swift-init >/dev/null; then
392392
swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
393393
fi
394+
# Dump the proxy server
395+
sudo pkill -f swift-proxy-server
394396
}
395397

396398
# Restore xtrace

stack.sh

+2
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,8 @@ fi
725725
configure_glanceclient
726726

727727
if is_service_enabled nova; then
728+
# First clean up old instances
729+
cleanup_nova
728730
configure_nova
729731
fi
730732
if is_service_enabled horizon; then

0 commit comments

Comments
 (0)