| 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 | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 52 | source $TOP_DIR/lib/heat | 
| Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 53 | source $TOP_DIR/lib/neutron | 
| Dean Troyer | 5a9739a | 2015-03-25 11:33:51 -0500 | [diff] [blame] | 54 | source $TOP_DIR/lib/neutron-legacy | 
| Dean Troyer | 53ffc71 | 2013-12-17 11:13:40 -0600 | [diff] [blame] | 55 |  | 
| Sean Dague | e73f88e | 2016-02-03 06:58:39 -0500 | [diff] [blame] | 56 | set -o xtrace | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 57 |  | 
| Dean Troyer | cdf3d76 | 2013-10-15 09:42:43 -0500 | [diff] [blame] | 58 | # Extras Source | 
 | 59 | # -------------- | 
 | 60 |  | 
 | 61 | # Phase: source | 
 | 62 | if [[ -d $TOP_DIR/extras.d ]]; then | 
 | 63 |     for i in $TOP_DIR/extras.d/*.sh; do | 
 | 64 |         [[ -r $i ]] && source $i source | 
 | 65 |     done | 
 | 66 | fi | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 67 |  | 
 | 68 | # See if there is anything running... | 
 | 69 | # need to adapt when run_service is merged | 
 | 70 | SESSION=$(screen -ls | awk '/[0-9].stack/ { print $1 }') | 
 | 71 | if [[ -n "$SESSION" ]]; then | 
 | 72 |     # Let unstack.sh do its thing first | 
 | 73 |     $TOP_DIR/unstack.sh --all | 
 | 74 | fi | 
 | 75 |  | 
| Dean Troyer | cdf3d76 | 2013-10-15 09:42:43 -0500 | [diff] [blame] | 76 | # Run extras | 
 | 77 | # ========== | 
 | 78 |  | 
 | 79 | # Phase: clean | 
| ajmiller | e6843e5 | 2015-04-11 09:52:48 -0700 | [diff] [blame] | 80 | load_plugin_settings | 
| Al Miller | a1701fa | 2015-02-20 08:10:41 -0800 | [diff] [blame] | 81 | run_phase clean | 
 | 82 |  | 
| Dean Troyer | cdf3d76 | 2013-10-15 09:42:43 -0500 | [diff] [blame] | 83 | if [[ -d $TOP_DIR/extras.d ]]; then | 
 | 84 |     for i in $TOP_DIR/extras.d/*.sh; do | 
 | 85 |         [[ -r $i ]] && source $i clean | 
 | 86 |     done | 
 | 87 | fi | 
 | 88 |  | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 89 | # Clean projects | 
| Sean Dague | 9a413ab | 2015-02-04 12:44:18 -0500 | [diff] [blame] | 90 |  | 
 | 91 | # BUG: cinder tgt doesn't exit cleanly if it's not running. | 
 | 92 | cleanup_cinder || /bin/true | 
 | 93 |  | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 94 | cleanup_glance | 
 | 95 | cleanup_keystone | 
 | 96 | cleanup_nova | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 97 | cleanup_neutron | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 98 | cleanup_swift | 
| Rob Crittenden | 5631ca5 | 2016-08-02 13:19:14 -0400 | [diff] [blame] | 99 | cleanup_horizon | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 100 |  | 
| Dean Troyer | b9e2513 | 2013-10-01 14:45:04 -0500 | [diff] [blame] | 101 | if is_service_enabled ldap; then | 
 | 102 |     cleanup_ldap | 
 | 103 | fi | 
 | 104 |  | 
| Dean Troyer | 2aa2a89 | 2013-08-04 19:53:19 -0500 | [diff] [blame] | 105 | # 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] | 106 | if is_service_enabled nova && [[ -r $NOVA_PLUGINS/hypervisor-$VIRT_DRIVER ]]; then | 
| Dean Troyer | 2aa2a89 | 2013-08-04 19:53:19 -0500 | [diff] [blame] | 107 |     cleanup_nova_hypervisor | 
 | 108 | fi | 
 | 109 |  | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 110 | # Clean out /etc | 
| Steve Martinelli | 8e3df96 | 2016-01-18 14:00:41 -0500 | [diff] [blame] | 111 | sudo rm -rf /etc/keystone /etc/glance /etc/nova /etc/cinder /etc/swift /etc/heat /etc/neutron /etc/openstack/ | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 112 |  | 
 | 113 | # Clean out tgt | 
| Dean Troyer | 53ffc71 | 2013-12-17 11:13:40 -0600 | [diff] [blame] | 114 | sudo rm -f /etc/tgt/conf.d/* | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 115 |  | 
 | 116 | # Clean up the message queue | 
 | 117 | cleanup_rpc_backend | 
 | 118 | cleanup_database | 
 | 119 |  | 
| Davanum Srinivas | 93d09c2 | 2015-04-11 18:45:09 -0400 | [diff] [blame] | 120 | # Clean out data and status | 
 | 121 | sudo rm -rf $DATA_DIR $DEST/status | 
 | 122 |  | 
 | 123 | # Clean out the log file and log directories | 
 | 124 | if [[ -n "$LOGFILE" ]] && [[ -f "$LOGFILE" ]]; then | 
 | 125 |     sudo rm -f $LOGFILE | 
 | 126 | fi | 
 | 127 | if [[ -n "$LOGDIR" ]] && [[ -d "$LOGDIR" ]]; then | 
 | 128 |     sudo rm -rf $LOGDIR | 
 | 129 | fi | 
| Dean Troyer | 53ffc71 | 2013-12-17 11:13:40 -0600 | [diff] [blame] | 130 | if [[ -n "$SCREEN_LOGDIR" ]] && [[ -d "$SCREEN_LOGDIR" ]]; then | 
 | 131 |     sudo rm -rf $SCREEN_LOGDIR | 
 | 132 | fi | 
 | 133 |  | 
| Dean Troyer | b1d8e8e | 2015-02-16 13:58:35 -0600 | [diff] [blame] | 134 | # Clean up venvs | 
| Monty Taylor | 61045ca | 2015-05-14 11:20:39 -0400 | [diff] [blame] | 135 | DIRS_TO_CLEAN="$WHEELHOUSE ${PROJECT_VENV[@]} .config/openstack" | 
| Dean Troyer | b1d8e8e | 2015-02-16 13:58:35 -0600 | [diff] [blame] | 136 | rm -rf $DIRS_TO_CLEAN | 
 | 137 |  | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 138 | # Clean up files | 
| Sean Dague | 2e2b28b | 2014-02-19 09:02:02 -0500 | [diff] [blame] | 139 |  | 
| Ian Wienand | 975f420 | 2015-10-14 15:12:32 +1100 | [diff] [blame] | 140 | FILES_TO_CLEAN=".localrc.auto .localrc.password " | 
 | 141 | FILES_TO_CLEAN+="docs/files docs/html shocco/ " | 
 | 142 | FILES_TO_CLEAN+="stack-screenrc test*.conf* test.ini* " | 
| ZhiQiang Fan | 0b4a009 | 2016-04-12 20:26:33 +0800 | [diff] [blame] | 143 | FILES_TO_CLEAN+=".stackenv .prereqs" | 
| Sean Dague | 2e2b28b | 2014-02-19 09:02:02 -0500 | [diff] [blame] | 144 |  | 
| Shashank Hegde | cb41569 | 2014-02-27 16:46:43 -0800 | [diff] [blame] | 145 | for file in $FILES_TO_CLEAN; do | 
| ZhiQiang Fan | ecd0563 | 2014-06-28 16:50:22 +0800 | [diff] [blame] | 146 |     rm -rf $TOP_DIR/$file | 
| Sean Dague | 2e2b28b | 2014-02-19 09:02:02 -0500 | [diff] [blame] | 147 | done | 
| ZhiQiang Fan | 0b4a009 | 2016-04-12 20:26:33 +0800 | [diff] [blame] | 148 |  | 
 | 149 | rm -rf ~/.config/openstack | 
| WenyanZhang | 8f0e97c | 2016-07-07 18:57:32 +0800 | [diff] [blame] | 150 |  | 
 | 151 | # Clean up all *.pyc files | 
 | 152 | if [[ -n "$DEST" ]] && [[ -d "$DEST" ]]; then | 
 | 153 |     sudo find $DEST -name "*.pyc" -print0 | xargs -0 rm | 
 | 154 | fi |