| Sean Dague | 9a413ab | 2015-02-04 12:44:18 -0500 | [diff] [blame] | 1 | #!/bin/bash | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 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 |  | 
| Dean Troyer | b9e2513 | 2013-10-01 14:45:04 -0500 | [diff] [blame] | 18 | FILES=$TOP_DIR/files | 
|  | 19 |  | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 20 | # Load local configuration | 
| Sean Dague | 5375329 | 2014-12-04 19:38:15 -0500 | [diff] [blame] | 21 | source $TOP_DIR/openrc | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 22 |  | 
|  | 23 | # Get the variables that are set in stack.sh | 
| Dean Troyer | 58f9cf7 | 2013-06-04 12:51:54 -0500 | [diff] [blame] | 24 | if [[ -r $TOP_DIR/.stackenv ]]; then | 
|  | 25 | source $TOP_DIR/.stackenv | 
|  | 26 | fi | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 27 |  | 
|  | 28 | # Determine what system we are running on.  This provides ``os_VENDOR``, | 
| Ian Wienand | 7710e7f | 2014-08-27 16:15:32 +1000 | [diff] [blame] | 29 | # ``os_RELEASE``, ``os_PACKAGE``, ``os_CODENAME`` | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 30 | # and ``DISTRO`` | 
|  | 31 | GetDistro | 
|  | 32 |  | 
| Dean Troyer | 53ffc71 | 2013-12-17 11:13:40 -0600 | [diff] [blame] | 33 | # Import apache functions | 
|  | 34 | source $TOP_DIR/lib/apache | 
|  | 35 | source $TOP_DIR/lib/ldap | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 36 |  | 
|  | 37 | # Import database library | 
|  | 38 | source $TOP_DIR/lib/database | 
|  | 39 | source $TOP_DIR/lib/rpc_backend | 
|  | 40 |  | 
|  | 41 | source $TOP_DIR/lib/tls | 
| Dean Troyer | 53ffc71 | 2013-12-17 11:13:40 -0600 | [diff] [blame] | 42 |  | 
| Sean Dague | 59d9cec | 2014-04-02 18:43:42 -0400 | [diff] [blame] | 43 | source $TOP_DIR/lib/oslo | 
| Mahito | 67168e8 | 2015-08-18 23:59:29 -0700 | [diff] [blame] | 44 | source $TOP_DIR/lib/lvm | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 45 | source $TOP_DIR/lib/horizon | 
|  | 46 | source $TOP_DIR/lib/keystone | 
|  | 47 | source $TOP_DIR/lib/glance | 
|  | 48 | source $TOP_DIR/lib/nova | 
| Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 49 | source $TOP_DIR/lib/placement | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 50 | source $TOP_DIR/lib/cinder | 
|  | 51 | source $TOP_DIR/lib/swift | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 52 | source $TOP_DIR/lib/neutron | 
| Dean Troyer | 5a9739a | 2015-03-25 11:33:51 -0500 | [diff] [blame] | 53 | source $TOP_DIR/lib/neutron-legacy | 
| Dean Troyer | 53ffc71 | 2013-12-17 11:13:40 -0600 | [diff] [blame] | 54 |  | 
| Sean Dague | e73f88e | 2016-02-03 06:58:39 -0500 | [diff] [blame] | 55 | set -o xtrace | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 56 |  | 
| Dean Troyer | cdf3d76 | 2013-10-15 09:42:43 -0500 | [diff] [blame] | 57 | # Extras Source | 
|  | 58 | # -------------- | 
|  | 59 |  | 
|  | 60 | # Phase: source | 
|  | 61 | if [[ -d $TOP_DIR/extras.d ]]; then | 
|  | 62 | for i in $TOP_DIR/extras.d/*.sh; do | 
|  | 63 | [[ -r $i ]] && source $i source | 
|  | 64 | done | 
|  | 65 | fi | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 66 |  | 
| Sean Dague | eaadffe | 2017-05-04 16:05:19 -0400 | [diff] [blame] | 67 | # Let unstack.sh do its thing first | 
|  | 68 | $TOP_DIR/unstack.sh --all | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 69 |  | 
| Dean Troyer | cdf3d76 | 2013-10-15 09:42:43 -0500 | [diff] [blame] | 70 | # Run extras | 
|  | 71 | # ========== | 
|  | 72 |  | 
|  | 73 | # Phase: clean | 
| ajmiller | e6843e5 | 2015-04-11 09:52:48 -0700 | [diff] [blame] | 74 | load_plugin_settings | 
| Al Miller | a1701fa | 2015-02-20 08:10:41 -0800 | [diff] [blame] | 75 | run_phase clean | 
|  | 76 |  | 
| Dean Troyer | cdf3d76 | 2013-10-15 09:42:43 -0500 | [diff] [blame] | 77 | if [[ -d $TOP_DIR/extras.d ]]; then | 
|  | 78 | for i in $TOP_DIR/extras.d/*.sh; do | 
|  | 79 | [[ -r $i ]] && source $i clean | 
|  | 80 | done | 
|  | 81 | fi | 
|  | 82 |  | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 83 | # Clean projects | 
| Sean Dague | 9a413ab | 2015-02-04 12:44:18 -0500 | [diff] [blame] | 84 |  | 
|  | 85 | # BUG: cinder tgt doesn't exit cleanly if it's not running. | 
|  | 86 | cleanup_cinder || /bin/true | 
|  | 87 |  | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 88 | cleanup_glance | 
|  | 89 | cleanup_keystone | 
|  | 90 | cleanup_nova | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 91 | cleanup_neutron | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 92 | cleanup_swift | 
| Rob Crittenden | 5631ca5 | 2016-08-02 13:19:14 -0400 | [diff] [blame] | 93 | cleanup_horizon | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 94 |  | 
| Dean Troyer | b9e2513 | 2013-10-01 14:45:04 -0500 | [diff] [blame] | 95 | if is_service_enabled ldap; then | 
|  | 96 | cleanup_ldap | 
|  | 97 | fi | 
|  | 98 |  | 
| Dean Troyer | 2aa2a89 | 2013-08-04 19:53:19 -0500 | [diff] [blame] | 99 | # Do the hypervisor cleanup until this can be moved back into lib/nova | 
| Dean Troyer | e4fa721 | 2014-01-15 15:04:49 -0600 | [diff] [blame] | 100 | if is_service_enabled nova && [[ -r $NOVA_PLUGINS/hypervisor-$VIRT_DRIVER ]]; then | 
| Dean Troyer | 2aa2a89 | 2013-08-04 19:53:19 -0500 | [diff] [blame] | 101 | cleanup_nova_hypervisor | 
|  | 102 | fi | 
|  | 103 |  | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 104 | # Clean out /etc | 
| xiaolihope | 8f985b6 | 2016-05-18 00:32:08 +0800 | [diff] [blame] | 105 | sudo rm -rf /etc/keystone /etc/glance /etc/nova /etc/cinder /etc/swift /etc/neutron /etc/openstack/ | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 106 |  | 
|  | 107 | # Clean out tgt | 
| Dean Troyer | 53ffc71 | 2013-12-17 11:13:40 -0600 | [diff] [blame] | 108 | sudo rm -f /etc/tgt/conf.d/* | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 109 |  | 
|  | 110 | # Clean up the message queue | 
|  | 111 | cleanup_rpc_backend | 
|  | 112 | cleanup_database | 
|  | 113 |  | 
| Davanum Srinivas | 93d09c2 | 2015-04-11 18:45:09 -0400 | [diff] [blame] | 114 | # Clean out data and status | 
|  | 115 | sudo rm -rf $DATA_DIR $DEST/status | 
|  | 116 |  | 
|  | 117 | # Clean out the log file and log directories | 
|  | 118 | if [[ -n "$LOGFILE" ]] && [[ -f "$LOGFILE" ]]; then | 
|  | 119 | sudo rm -f $LOGFILE | 
|  | 120 | fi | 
|  | 121 | if [[ -n "$LOGDIR" ]] && [[ -d "$LOGDIR" ]]; then | 
|  | 122 | sudo rm -rf $LOGDIR | 
|  | 123 | fi | 
| Dean Troyer | 53ffc71 | 2013-12-17 11:13:40 -0600 | [diff] [blame] | 124 | if [[ -n "$SCREEN_LOGDIR" ]] && [[ -d "$SCREEN_LOGDIR" ]]; then | 
|  | 125 | sudo rm -rf $SCREEN_LOGDIR | 
|  | 126 | fi | 
|  | 127 |  | 
| Markus Zoeller | 15b0a5f | 2017-05-31 11:21:22 +0200 | [diff] [blame] | 128 | # Clean out the sytemd user unit files if systemd was used. | 
|  | 129 | if [[ "$USE_SYSTEMD" = "True" ]]; then | 
|  | 130 | sudo find $SYSTEMD_DIR -type f -name '*devstack@*service' -delete | 
|  | 131 | # Make systemd aware of the deletion. | 
|  | 132 | $SYSTEMCTL daemon-reload | 
|  | 133 | fi | 
|  | 134 |  | 
| Dean Troyer | b1d8e8e | 2015-02-16 13:58:35 -0600 | [diff] [blame] | 135 | # Clean up venvs | 
| Monty Taylor | 61045ca | 2015-05-14 11:20:39 -0400 | [diff] [blame] | 136 | DIRS_TO_CLEAN="$WHEELHOUSE ${PROJECT_VENV[@]} .config/openstack" | 
| Dean Troyer | b1d8e8e | 2015-02-16 13:58:35 -0600 | [diff] [blame] | 137 | rm -rf $DIRS_TO_CLEAN | 
|  | 138 |  | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 139 | # Clean up files | 
| Sean Dague | 2e2b28b | 2014-02-19 09:02:02 -0500 | [diff] [blame] | 140 |  | 
| Ian Wienand | 975f420 | 2015-10-14 15:12:32 +1100 | [diff] [blame] | 141 | FILES_TO_CLEAN=".localrc.auto .localrc.password " | 
|  | 142 | FILES_TO_CLEAN+="docs/files docs/html shocco/ " | 
|  | 143 | FILES_TO_CLEAN+="stack-screenrc test*.conf* test.ini* " | 
| ZhiQiang Fan | 0b4a009 | 2016-04-12 20:26:33 +0800 | [diff] [blame] | 144 | FILES_TO_CLEAN+=".stackenv .prereqs" | 
| Sean Dague | 2e2b28b | 2014-02-19 09:02:02 -0500 | [diff] [blame] | 145 |  | 
| Shashank Hegde | cb41569 | 2014-02-27 16:46:43 -0800 | [diff] [blame] | 146 | for file in $FILES_TO_CLEAN; do | 
| ZhiQiang Fan | ecd0563 | 2014-06-28 16:50:22 +0800 | [diff] [blame] | 147 | rm -rf $TOP_DIR/$file | 
| Sean Dague | 2e2b28b | 2014-02-19 09:02:02 -0500 | [diff] [blame] | 148 | done | 
| ZhiQiang Fan | 0b4a009 | 2016-04-12 20:26:33 +0800 | [diff] [blame] | 149 |  | 
|  | 150 | rm -rf ~/.config/openstack | 
| WenyanZhang | 8f0e97c | 2016-07-07 18:57:32 +0800 | [diff] [blame] | 151 |  | 
|  | 152 | # Clean up all *.pyc files | 
|  | 153 | if [[ -n "$DEST" ]] && [[ -d "$DEST" ]]; then | 
| Victor Morales | b612b62 | 2017-01-12 19:53:07 -0600 | [diff] [blame] | 154 | find_version=`find --version | awk '{ print $NF; exit}'` | 
|  | 155 | if vercmp "$find_version" "<" "4.2.3" ; then | 
|  | 156 | sudo find $DEST -name "*.pyc" -print0 | xargs -0 rm | 
|  | 157 | else | 
|  | 158 | sudo find $DEST -name "*.pyc" -delete | 
|  | 159 | fi | 
| WenyanZhang | 8f0e97c | 2016-07-07 18:57:32 +0800 | [diff] [blame] | 160 | fi |