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