| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 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 |  | 
| 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 | 
|  | 21 | source $TOP_DIR/stackrc | 
|  | 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``, | 
|  | 29 | # ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME`` | 
|  | 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 | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 44 | source $TOP_DIR/lib/horizon | 
|  | 45 | source $TOP_DIR/lib/keystone | 
|  | 46 | source $TOP_DIR/lib/glance | 
|  | 47 | source $TOP_DIR/lib/nova | 
|  | 48 | source $TOP_DIR/lib/cinder | 
|  | 49 | source $TOP_DIR/lib/swift | 
|  | 50 | source $TOP_DIR/lib/ceilometer | 
|  | 51 | source $TOP_DIR/lib/heat | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 52 | source $TOP_DIR/lib/neutron | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 53 | source $TOP_DIR/lib/baremetal | 
| Dean Troyer | 53ffc71 | 2013-12-17 11:13:40 -0600 | [diff] [blame] | 54 | source $TOP_DIR/lib/ironic | 
|  | 55 | source $TOP_DIR/lib/trove | 
|  | 56 |  | 
| 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 | 
|  | 80 | if [[ -d $TOP_DIR/extras.d ]]; then | 
|  | 81 | for i in $TOP_DIR/extras.d/*.sh; do | 
|  | 82 | [[ -r $i ]] && source $i clean | 
|  | 83 | done | 
|  | 84 | fi | 
|  | 85 |  | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 86 | # Clean projects | 
|  | 87 | cleanup_cinder | 
|  | 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 | 
|  | 93 |  | 
| Dean Troyer | b9e2513 | 2013-10-01 14:45:04 -0500 | [diff] [blame] | 94 | if is_service_enabled ldap; then | 
|  | 95 | cleanup_ldap | 
|  | 96 | fi | 
|  | 97 |  | 
| Dean Troyer | 2aa2a89 | 2013-08-04 19:53:19 -0500 | [diff] [blame] | 98 | # 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] | 99 | if is_service_enabled nova && [[ -r $NOVA_PLUGINS/hypervisor-$VIRT_DRIVER ]]; then | 
| Dean Troyer | 2aa2a89 | 2013-08-04 19:53:19 -0500 | [diff] [blame] | 100 | cleanup_nova_hypervisor | 
|  | 101 | fi | 
|  | 102 |  | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 103 | # Clean out /etc | 
| Gary Kotton | b00e418 | 2014-05-01 05:16:59 -0700 | [diff] [blame] | 104 | sudo rm -rf /etc/keystone /etc/glance /etc/nova /etc/cinder /etc/swift /etc/heat /etc/neutron | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 105 |  | 
|  | 106 | # Clean out tgt | 
| Dean Troyer | 53ffc71 | 2013-12-17 11:13:40 -0600 | [diff] [blame] | 107 | sudo rm -f /etc/tgt/conf.d/* | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 108 |  | 
|  | 109 | # Clean up the message queue | 
|  | 110 | cleanup_rpc_backend | 
|  | 111 | cleanup_database | 
|  | 112 |  | 
| Dean Troyer | 53ffc71 | 2013-12-17 11:13:40 -0600 | [diff] [blame] | 113 | # Clean out data, logs and status | 
|  | 114 | LOGDIR=$(dirname "$LOGFILE") | 
|  | 115 | sudo rm -rf $DATA_DIR $LOGDIR $DEST/status | 
|  | 116 | if [[ -n "$SCREEN_LOGDIR" ]] && [[ -d "$SCREEN_LOGDIR" ]]; then | 
|  | 117 | sudo rm -rf $SCREEN_LOGDIR | 
|  | 118 | fi | 
|  | 119 |  | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 120 | # Clean up files | 
| Sean Dague | 2e2b28b | 2014-02-19 09:02:02 -0500 | [diff] [blame] | 121 |  | 
| ZhiQiang Fan | ecd0563 | 2014-06-28 16:50:22 +0800 | [diff] [blame] | 122 | FILES_TO_CLEAN=".localrc.auto docs/files docs/html shocco/ stack-screenrc test*.conf* test.ini*" | 
| Sean Dague | 2e2b28b | 2014-02-19 09:02:02 -0500 | [diff] [blame] | 123 | FILES_TO_CLEAN+=".stackenv .prereqs" | 
|  | 124 |  | 
| Shashank Hegde | cb41569 | 2014-02-27 16:46:43 -0800 | [diff] [blame] | 125 | for file in $FILES_TO_CLEAN; do | 
| ZhiQiang Fan | ecd0563 | 2014-06-28 16:50:22 +0800 | [diff] [blame] | 126 | rm -rf $TOP_DIR/$file | 
| Sean Dague | 2e2b28b | 2014-02-19 09:02:02 -0500 | [diff] [blame] | 127 | done |