blob: 6b34aa3aa72468d216f2d12608ea7afb9ee24c05 [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
29source $TOP_DIR/lib/n-vol
30
Dean Troyerf4d23952012-03-28 11:19:24 -050031# Determine what system we are running on. This provides ``os_VENDOR``,
32# ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME``
33GetOSVersion
34
35if [[ "$1" == "--all" ]]; then
36 UNSTACK_ALL=${UNSTACK_ALL:-1}
37fi
38
39# Shut down devstack's screen to get the bulk of OpenStack services in one shot
Dean Troyereeaf2662012-06-14 09:11:38 -050040SCREEN=$(which screen)
41if [[ -n "$SCREEN" ]]; then
42 SESSION=$(screen -ls | awk '/[0-9].stack/ { print $1 }')
43 if [[ -n "$SESSION" ]]; then
44 screen -X -S $SESSION quit
45 fi
Dean Troyerf4d23952012-03-28 11:19:24 -050046fi
47
48# Swift runs daemons
49if is_service_enabled swift; then
Chmouel Boudjnah84394b92012-08-06 10:07:43 +000050 swift-init all stop 2>/dev/null || true
Dean Troyerf4d23952012-03-28 11:19:24 -050051fi
52
53# Apache has the WSGI processes
54if is_service_enabled horizon; then
55 stop_service apache2
56fi
57
John Griffithd53bedc2012-09-11 14:15:54 -060058SCSI_PERSIST_DIR=$CINDER_STATE_PATH/volumes/*
59
Dean Troyerf4d23952012-03-28 11:19:24 -050060# Get the iSCSI volumes
Dean Troyer67787e62012-05-02 11:48:15 -050061if is_service_enabled cinder n-vol; then
John Griffithd53bedc2012-09-11 14:15:54 -060062 if is_service_enabled n-vol; then
63 SCSI_PERSIST_DIR=$NOVA_STATE_PATH/volumes/*
64 fi
65
Dean Troyerf4d23952012-03-28 11:19:24 -050066 TARGETS=$(sudo tgtadm --op show --mode target)
John Griffithd53bedc2012-09-11 14:15:54 -060067 if [ $? -ne 0 ]; then
68 # If tgt driver isn't running this won't work obviously
69 # So check the response and restart if need be
70 echo "tgtd seems to be in a bad state, restarting..."
71 if [[ "$os_PACKAGE" = "deb" ]]; then
72 restart_service tgt
73 else
74 restart_service tgtd
75 fi
76 TARGETS=$(sudo tgtadm --op show --mode target)
77 fi
78
Dean Troyerf4d23952012-03-28 11:19:24 -050079 if [[ -n "$TARGETS" ]]; then
John Griffithd53bedc2012-09-11 14:15:54 -060080 iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
81 for i in "${iqn_list[@]}"; do
82 echo removing iSCSI target: $i
83 sudo tgt-admin --delete $i
84 done
85 fi
86
87 if is_service_enabled cinder; then
88 sudo rm -rf $CINDER_STATE_PATH/volumes/*
89 fi
90
91 if is_service_enabled n-vol; then
92 sudo rm -rf $NOVA_STATE_PATH/volumes/*
Dean Troyerf4d23952012-03-28 11:19:24 -050093 fi
Sascha Peilicke5da67fe2012-07-18 13:27:32 +020094
95 if [[ "$os_PACKAGE" = "deb" ]]; then
96 stop_service tgt
97 else
98 stop_service tgtd
99 fi
Dean Troyerf4d23952012-03-28 11:19:24 -0500100fi
101
102if [[ -n "$UNSTACK_ALL" ]]; then
103 # Stop MySQL server
104 if is_service_enabled mysql; then
105 stop_service mysql
106 fi
Josh Kearney659eabf2012-09-06 13:47:06 -0500107
Terry Wilson428af5a2012-11-01 16:12:39 -0400108 if is_service_enabled postgresql; then
109 stop_service postgresql
110 fi
111
Josh Kearney659eabf2012-09-06 13:47:06 -0500112 # Stop rabbitmq-server
113 if is_service_enabled rabbit; then
114 stop_service rabbitmq-server
115 fi
Dean Troyerf4d23952012-03-28 11:19:24 -0500116fi
Gary Kotton722fe672012-07-18 07:43:01 -0400117
118# Quantum dhcp agent runs dnsmasq
119if is_service_enabled q-dhcp; then
Surya Prabhakara9c4a8a2012-10-06 19:35:56 +0530120 pid=$(ps aux | awk '/[d]nsmasq.+interface=tap/ { print $2 }')
Yoshihiro Kaneko602cf9b2012-07-23 06:27:36 +0000121 [ ! -z "$pid" ] && sudo kill -9 $pid
Gary Kotton722fe672012-07-18 07:43:01 -0400122fi