| Dean Troyer | f4d2395 | 2012-03-28 11:19:24 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash | 
| Dean Troyer | 7d28a0e | 2012-06-27 17:55:52 -0500 | [diff] [blame] | 2 |  | 
|  | 3 | # **unstack.sh** | 
|  | 4 |  | 
| Dean Troyer | f4d2395 | 2012-03-28 11:19:24 -0500 | [diff] [blame] | 5 | # Stops that which is started by ``stack.sh`` (mostly) | 
|  | 6 | # mysql and rabbit are left running as OpenStack code refreshes | 
|  | 7 | # do not require them to be restarted. | 
|  | 8 | # | 
| Dean Troyer | 4a43b7b | 2012-08-28 17:43:40 -0500 | [diff] [blame] | 9 | # Stop all processes by setting ``UNSTACK_ALL`` or specifying ``--all`` | 
| Dean Troyer | f4d2395 | 2012-03-28 11:19:24 -0500 | [diff] [blame] | 10 | # on the command line | 
|  | 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 |  | 
| Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 18 | # Import database library | 
|  | 19 | source $TOP_DIR/lib/database | 
|  | 20 |  | 
| Dean Troyer | f4d2395 | 2012-03-28 11:19:24 -0500 | [diff] [blame] | 21 | # Load local configuration | 
|  | 22 | source $TOP_DIR/stackrc | 
|  | 23 |  | 
| John Griffith | d53bedc | 2012-09-11 14:15:54 -0600 | [diff] [blame] | 24 | # Destination path for service data | 
|  | 25 | DATA_DIR=${DATA_DIR:-${DEST}/data} | 
|  | 26 |  | 
|  | 27 | # Get project function libraries | 
|  | 28 | source $TOP_DIR/lib/cinder | 
| John Griffith | d53bedc | 2012-09-11 14:15:54 -0600 | [diff] [blame] | 29 |  | 
| Dean Troyer | f4d2395 | 2012-03-28 11:19:24 -0500 | [diff] [blame] | 30 | # Determine what system we are running on.  This provides ``os_VENDOR``, | 
|  | 31 | # ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME`` | 
|  | 32 | GetOSVersion | 
|  | 33 |  | 
|  | 34 | if [[ "$1" == "--all" ]]; then | 
|  | 35 | UNSTACK_ALL=${UNSTACK_ALL:-1} | 
|  | 36 | fi | 
|  | 37 |  | 
|  | 38 | # Shut down devstack's screen to get the bulk of OpenStack services in one shot | 
| Dean Troyer | eeaf266 | 2012-06-14 09:11:38 -0500 | [diff] [blame] | 39 | SCREEN=$(which screen) | 
|  | 40 | if [[ -n "$SCREEN" ]]; then | 
|  | 41 | SESSION=$(screen -ls | awk '/[0-9].stack/ { print $1 }') | 
|  | 42 | if [[ -n "$SESSION" ]]; then | 
|  | 43 | screen -X -S $SESSION quit | 
|  | 44 | fi | 
| Dean Troyer | f4d2395 | 2012-03-28 11:19:24 -0500 | [diff] [blame] | 45 | fi | 
|  | 46 |  | 
|  | 47 | # Swift runs daemons | 
|  | 48 | if is_service_enabled swift; then | 
| Chmouel Boudjnah | 84394b9 | 2012-08-06 10:07:43 +0000 | [diff] [blame] | 49 | swift-init all stop 2>/dev/null || true | 
| Dean Troyer | f4d2395 | 2012-03-28 11:19:24 -0500 | [diff] [blame] | 50 | fi | 
|  | 51 |  | 
|  | 52 | # Apache has the WSGI processes | 
|  | 53 | if is_service_enabled horizon; then | 
|  | 54 | stop_service apache2 | 
|  | 55 | fi | 
|  | 56 |  | 
| John Griffith | d53bedc | 2012-09-11 14:15:54 -0600 | [diff] [blame] | 57 | SCSI_PERSIST_DIR=$CINDER_STATE_PATH/volumes/* | 
|  | 58 |  | 
| Dean Troyer | f4d2395 | 2012-03-28 11:19:24 -0500 | [diff] [blame] | 59 | # Get the iSCSI volumes | 
| Joe Gordon | 6fd2811 | 2012-11-13 16:55:41 -0800 | [diff] [blame] | 60 | if is_service_enabled cinder; then | 
| Dean Troyer | f4d2395 | 2012-03-28 11:19:24 -0500 | [diff] [blame] | 61 | TARGETS=$(sudo tgtadm --op show --mode target) | 
| John Griffith | d53bedc | 2012-09-11 14:15:54 -0600 | [diff] [blame] | 62 | if [ $? -ne 0 ]; then | 
|  | 63 | # If tgt driver isn't running this won't work obviously | 
|  | 64 | # So check the response and restart if need be | 
|  | 65 | echo "tgtd seems to be in a bad state, restarting..." | 
|  | 66 | if [[ "$os_PACKAGE" = "deb" ]]; then | 
|  | 67 | restart_service tgt | 
|  | 68 | else | 
|  | 69 | restart_service tgtd | 
|  | 70 | fi | 
|  | 71 | TARGETS=$(sudo tgtadm --op show --mode target) | 
|  | 72 | fi | 
|  | 73 |  | 
| Dean Troyer | f4d2395 | 2012-03-28 11:19:24 -0500 | [diff] [blame] | 74 | if [[ -n "$TARGETS" ]]; then | 
| John Griffith | d53bedc | 2012-09-11 14:15:54 -0600 | [diff] [blame] | 75 | iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') ) | 
|  | 76 | for i in "${iqn_list[@]}"; do | 
|  | 77 | echo removing iSCSI target: $i | 
|  | 78 | sudo tgt-admin --delete $i | 
|  | 79 | done | 
|  | 80 | fi | 
|  | 81 |  | 
|  | 82 | if is_service_enabled cinder; then | 
|  | 83 | sudo rm -rf $CINDER_STATE_PATH/volumes/* | 
|  | 84 | fi | 
|  | 85 |  | 
| Sascha Peilicke | 5da67fe | 2012-07-18 13:27:32 +0200 | [diff] [blame] | 86 | if [[ "$os_PACKAGE" = "deb" ]]; then | 
|  | 87 | stop_service tgt | 
|  | 88 | else | 
|  | 89 | stop_service tgtd | 
|  | 90 | fi | 
| Dean Troyer | f4d2395 | 2012-03-28 11:19:24 -0500 | [diff] [blame] | 91 | fi | 
|  | 92 |  | 
|  | 93 | if [[ -n "$UNSTACK_ALL" ]]; then | 
|  | 94 | # Stop MySQL server | 
|  | 95 | if is_service_enabled mysql; then | 
|  | 96 | stop_service mysql | 
|  | 97 | fi | 
| Josh Kearney | 659eabf | 2012-09-06 13:47:06 -0500 | [diff] [blame] | 98 |  | 
| Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 99 | if is_service_enabled postgresql; then | 
|  | 100 | stop_service postgresql | 
|  | 101 | fi | 
|  | 102 |  | 
| Josh Kearney | 659eabf | 2012-09-06 13:47:06 -0500 | [diff] [blame] | 103 | # Stop rabbitmq-server | 
|  | 104 | if is_service_enabled rabbit; then | 
|  | 105 | stop_service rabbitmq-server | 
|  | 106 | fi | 
| Dean Troyer | f4d2395 | 2012-03-28 11:19:24 -0500 | [diff] [blame] | 107 | fi | 
| Gary Kotton | 722fe67 | 2012-07-18 07:43:01 -0400 | [diff] [blame] | 108 |  | 
|  | 109 | # Quantum dhcp agent runs dnsmasq | 
|  | 110 | if is_service_enabled q-dhcp; then | 
| Surya Prabhakar | a9c4a8a | 2012-10-06 19:35:56 +0530 | [diff] [blame] | 111 | pid=$(ps aux | awk '/[d]nsmasq.+interface=tap/ { print $2 }') | 
| Yoshihiro Kaneko | 602cf9b | 2012-07-23 06:27:36 +0000 | [diff] [blame] | 112 | [ ! -z "$pid" ] && sudo kill -9 $pid | 
| Gary Kotton | 722fe67 | 2012-07-18 07:43:01 -0400 | [diff] [blame] | 113 | fi |