blob: 34195c211887d813b7efcdf3cfe0f3000af4a00c [file] [log] [blame]
Dean Troyerf4d23952012-03-28 11:19:24 -05001#!/usr/bin/env bash
Dean Troyer7d28a0e2012-06-27 17:55:52 -05002
3# **unstack.sh**
4
Dean Troyerf4d23952012-03-28 11:19:24 -05005# 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 Troyer4a43b7b2012-08-28 17:43:40 -05009# Stop all processes by setting ``UNSTACK_ALL`` or specifying ``--all``
Dean Troyerf4d23952012-03-28 11:19:24 -050010# on the command line
11
12# Keep track of the current devstack directory.
13TOP_DIR=$(cd $(dirname "$0") && pwd)
14
15# Import common functions
16source $TOP_DIR/functions
17
Terry Wilson428af5a2012-11-01 16:12:39 -040018# Import database library
19source $TOP_DIR/lib/database
20
Dean Troyerf4d23952012-03-28 11:19:24 -050021# Load local configuration
22source $TOP_DIR/stackrc
23
John Griffithd53bedc2012-09-11 14:15:54 -060024# Destination path for service data
25DATA_DIR=${DATA_DIR:-${DEST}/data}
26
27# Get project function libraries
28source $TOP_DIR/lib/cinder
Sean Dagueb562e6a2012-11-19 16:00:01 -050029source $TOP_DIR/lib/horizon
Attila Fazekasece6a332012-11-29 14:19:41 +010030source $TOP_DIR/lib/swift
John Griffithd53bedc2012-09-11 14:15:54 -060031
Dean Troyerf4d23952012-03-28 11:19:24 -050032# Determine what system we are running on. This provides ``os_VENDOR``,
33# ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME``
34GetOSVersion
35
36if [[ "$1" == "--all" ]]; then
37 UNSTACK_ALL=${UNSTACK_ALL:-1}
38fi
39
Nachi Ueno8bc21f62012-11-19 22:04:28 -080040if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then
41 source $TOP_DIR/openrc
42 source $TOP_DIR/lib/quantum
43 teardown_quantum
44fi
45
Dean Troyerf4d23952012-03-28 11:19:24 -050046# Shut down devstack's screen to get the bulk of OpenStack services in one shot
Dean Troyereeaf2662012-06-14 09:11:38 -050047SCREEN=$(which screen)
48if [[ -n "$SCREEN" ]]; then
49 SESSION=$(screen -ls | awk '/[0-9].stack/ { print $1 }')
50 if [[ -n "$SESSION" ]]; then
51 screen -X -S $SESSION quit
52 fi
Dean Troyerf4d23952012-03-28 11:19:24 -050053fi
54
55# Swift runs daemons
56if is_service_enabled swift; then
Attila Fazekasece6a332012-11-29 14:19:41 +010057 stop_swift
Dean Troyerf4d23952012-03-28 11:19:24 -050058fi
59
60# Apache has the WSGI processes
61if is_service_enabled horizon; then
Sean Dagueb562e6a2012-11-19 16:00:01 -050062 stop_horizon
Dean Troyerf4d23952012-03-28 11:19:24 -050063fi
64
John Griffithd53bedc2012-09-11 14:15:54 -060065SCSI_PERSIST_DIR=$CINDER_STATE_PATH/volumes/*
66
Dean Troyerf4d23952012-03-28 11:19:24 -050067# Get the iSCSI volumes
Joe Gordon6fd28112012-11-13 16:55:41 -080068if is_service_enabled cinder; then
Dean Troyerf4d23952012-03-28 11:19:24 -050069 TARGETS=$(sudo tgtadm --op show --mode target)
John Griffithd53bedc2012-09-11 14:15:54 -060070 if [ $? -ne 0 ]; then
71 # If tgt driver isn't running this won't work obviously
72 # So check the response and restart if need be
73 echo "tgtd seems to be in a bad state, restarting..."
Vincent Untzc18b9652012-12-04 12:36:34 +010074 if is_ubuntu; then
John Griffithd53bedc2012-09-11 14:15:54 -060075 restart_service tgt
76 else
77 restart_service tgtd
78 fi
79 TARGETS=$(sudo tgtadm --op show --mode target)
80 fi
81
Dean Troyerf4d23952012-03-28 11:19:24 -050082 if [[ -n "$TARGETS" ]]; then
John Griffithd53bedc2012-09-11 14:15:54 -060083 iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
84 for i in "${iqn_list[@]}"; do
85 echo removing iSCSI target: $i
86 sudo tgt-admin --delete $i
87 done
88 fi
89
90 if is_service_enabled cinder; then
91 sudo rm -rf $CINDER_STATE_PATH/volumes/*
92 fi
93
Vincent Untzc18b9652012-12-04 12:36:34 +010094 if is_ubuntu; then
Sascha Peilicke5da67fe2012-07-18 13:27:32 +020095 stop_service tgt
96 else
97 stop_service tgtd
98 fi
Dean Troyerf4d23952012-03-28 11:19:24 -050099fi
100
101if [[ -n "$UNSTACK_ALL" ]]; then
102 # Stop MySQL server
103 if is_service_enabled mysql; then
104 stop_service mysql
105 fi
Josh Kearney659eabf2012-09-06 13:47:06 -0500106
Terry Wilson428af5a2012-11-01 16:12:39 -0400107 if is_service_enabled postgresql; then
108 stop_service postgresql
109 fi
110
Josh Kearney659eabf2012-09-06 13:47:06 -0500111 # Stop rabbitmq-server
112 if is_service_enabled rabbit; then
113 stop_service rabbitmq-server
114 fi
Dean Troyerf4d23952012-03-28 11:19:24 -0500115fi
Gary Kotton722fe672012-07-18 07:43:01 -0400116
117# Quantum dhcp agent runs dnsmasq
118if is_service_enabled q-dhcp; then
Surya Prabhakara9c4a8a2012-10-06 19:35:56 +0530119 pid=$(ps aux | awk '/[d]nsmasq.+interface=tap/ { print $2 }')
Yoshihiro Kaneko602cf9b2012-07-23 06:27:36 +0000120 [ ! -z "$pid" ] && sudo kill -9 $pid
Gary Kotton722fe672012-07-18 07:43:01 -0400121fi