blob: 33b069b6a34a334d8ebe6427e2dbc8b13df012dc [file] [log] [blame]
Sean Dague9a413ab2015-02-04 12:44:18 -05001#!/bin/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#
Sean Dague53753292014-12-04 19:38:15 -05009# Stop all processes by setting ``UNSTACK_ALL`` or specifying ``-a``
Dean Troyerf4d23952012-03-28 11:19:24 -050010# on the command line
11
Mike Chester8040e692016-02-17 10:52:33 -080012UNSTACK_ALL=${UNSTACK_ALL:-""}
Sean Dague53753292014-12-04 19:38:15 -050013
14while getopts ":a" opt; do
15 case $opt in
16 a)
Mike Chester8040e692016-02-17 10:52:33 -080017 UNSTACK_ALL="-1"
Sean Dague53753292014-12-04 19:38:15 -050018 ;;
19 esac
20done
21
Dean Troyerdc97cb72015-03-28 08:20:50 -050022# Keep track of the current DevStack directory.
Dean Troyerf4d23952012-03-28 11:19:24 -050023TOP_DIR=$(cd $(dirname "$0") && pwd)
Sean Dague53753292014-12-04 19:38:15 -050024FILES=$TOP_DIR/files
Dean Troyerf4d23952012-03-28 11:19:24 -050025
26# Import common functions
27source $TOP_DIR/functions
28
Terry Wilson428af5a2012-11-01 16:12:39 -040029# Import database library
30source $TOP_DIR/lib/database
31
Dean Troyerf4d23952012-03-28 11:19:24 -050032# Load local configuration
Sean Dague53753292014-12-04 19:38:15 -050033source $TOP_DIR/openrc
Dean Troyerf4d23952012-03-28 11:19:24 -050034
John Griffithd53bedc2012-09-11 14:15:54 -060035# Destination path for service data
36DATA_DIR=${DATA_DIR:-${DEST}/data}
37
Dean Troyer23f69d82013-10-04 12:35:24 -050038if [[ $EUID -eq 0 ]]; then
39 echo "You are running this script as root."
40 echo "It might work but you will have a better day running it as $STACK_USER"
41 exit 1
42fi
43
Brant Knudson0049c0c2014-01-16 18:16:48 -060044
45# Configure Projects
46# ==================
47
Takashi NATSUME7b1b6f32017-12-20 11:38:23 +090048# Determine what system we are running on. This provides ``os_VENDOR``,
49# ``os_RELEASE``, ``os_PACKAGE``, ``os_CODENAME`` and ``DISTRO``
50GetDistro
51
Wei Jiangangbe65c6f2015-09-14 18:52:47 +080052# Plugin Phase 0: override_defaults - allow plugins to override
Sean Dague6e275e12015-03-26 05:54:28 -040053# defaults before other services are run
54run_phase override_defaults
55
zhang-hared98a5d02013-06-21 18:18:02 +080056# Import apache functions
57source $TOP_DIR/lib/apache
58
Brant Knudson0049c0c2014-01-16 18:16:48 -060059# Import TLS functions
60source $TOP_DIR/lib/tls
61
62# Source project function libraries
63source $TOP_DIR/lib/infra
64source $TOP_DIR/lib/oslo
Daniel Genind4708672014-10-31 15:01:29 -040065source $TOP_DIR/lib/lvm
Brant Knudson0049c0c2014-01-16 18:16:48 -060066source $TOP_DIR/lib/horizon
Dean Troyer9fc87922013-05-22 17:19:06 -050067source $TOP_DIR/lib/keystone
68source $TOP_DIR/lib/glance
69source $TOP_DIR/lib/nova
Chris Dent4d601752016-07-12 19:34:09 +000070source $TOP_DIR/lib/placement
Brant Knudson0049c0c2014-01-16 18:16:48 -060071source $TOP_DIR/lib/cinder
Attila Fazekasece6a332012-11-29 14:19:41 +010072source $TOP_DIR/lib/swift
Sean M. Collins2a242512016-05-03 09:03:09 -040073source $TOP_DIR/lib/neutron
Brant Knudson0049c0c2014-01-16 18:16:48 -060074source $TOP_DIR/lib/ldap
Martin André48a75c12014-09-08 08:58:58 +000075source $TOP_DIR/lib/dstat
Davanum Srinivas546656f2017-03-14 07:05:19 -040076source $TOP_DIR/lib/etcd3
John Griffithd53bedc2012-09-11 14:15:54 -060077
Dean Troyercdf3d762013-10-15 09:42:43 -050078# Extras Source
79# --------------
80
81# Phase: source
82if [[ -d $TOP_DIR/extras.d ]]; then
83 for i in $TOP_DIR/extras.d/*.sh; do
84 [[ -r $i ]] && source $i source
85 done
86fi
87
Sean Dague2c65e712014-12-18 09:44:56 -050088load_plugin_settings
89
Sean Daguee73f88e2016-02-03 06:58:39 -050090set -o xtrace
91
Dean Troyer768295e2013-01-09 13:42:03 -060092# Run extras
93# ==========
94
Dean Troyercdf3d762013-10-15 09:42:43 -050095# Phase: unstack
Sean Dague2c65e712014-12-18 09:44:56 -050096run_phase unstack
Dean Troyer768295e2013-01-09 13:42:03 -060097
Dean Troyer9fc87922013-05-22 17:19:06 -050098# Call service stop
Dean Troyerf4d23952012-03-28 11:19:24 -050099
Dean Troyer9fc87922013-05-22 17:19:06 -0500100if is_service_enabled nova; then
101 stop_nova
Akihiro Motoki85c5ec12020-01-15 10:58:29 +0900102 cleanup_nova
Dean Troyer9fc87922013-05-22 17:19:06 -0500103fi
104
Chris Dent4d601752016-07-12 19:34:09 +0000105if is_service_enabled placement; then
106 stop_placement
107fi
108
Dean Troyere4fa7212014-01-15 15:04:49 -0600109if is_service_enabled glance; then
Dean Troyer9fc87922013-05-22 17:19:06 -0500110 stop_glance
111fi
112
Dean Troyer5ce44cd2015-02-12 22:18:33 -0600113if is_service_enabled keystone; then
Dean Troyer9fc87922013-05-22 17:19:06 -0500114 stop_keystone
Dean Troyer2aa2a892013-08-04 19:53:19 -0500115fi
116
Dean Troyerf4d23952012-03-28 11:19:24 -0500117# Swift runs daemons
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100118if is_service_enabled s-proxy; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100119 stop_swift
Chmouel Boudjnah43eb0b32013-01-12 20:10:34 +0000120 cleanup_swift
Dean Troyerf4d23952012-03-28 11:19:24 -0500121fi
122
123# Apache has the WSGI processes
124if is_service_enabled horizon; then
Sean Dagueb562e6a2012-11-19 16:00:01 -0500125 stop_horizon
Dean Troyerf4d23952012-03-28 11:19:24 -0500126fi
127
Stanislaw Pituchabd5dae02014-06-25 15:29:43 +0100128# Kill TLS proxies and cleanup certificates
Dean Troyerc83a7e12012-11-29 11:47:58 -0600129if is_service_enabled tls-proxy; then
Stanislaw Pituchabd5dae02014-06-25 15:29:43 +0100130 stop_tls_proxy
131 cleanup_CA
Dean Troyerc83a7e12012-11-29 11:47:58 -0600132fi
133
John Griffithd53bedc2012-09-11 14:15:54 -0600134SCSI_PERSIST_DIR=$CINDER_STATE_PATH/volumes/*
135
Sean Dague9a413ab2015-02-04 12:44:18 -0500136# BUG: tgt likes to exit 1 on service stop if everything isn't
137# perfect, we should clean up cinder stop paths.
138
Dean Troyerf4d23952012-03-28 11:19:24 -0500139# Get the iSCSI volumes
Joe Gordon6fd28112012-11-13 16:55:41 -0800140if is_service_enabled cinder; then
Sean Dague9a413ab2015-02-04 12:44:18 -0500141 stop_cinder || /bin/true
142 cleanup_cinder || /bin/true
Dean Troyerf4d23952012-03-28 11:19:24 -0500143fi
144
145if [[ -n "$UNSTACK_ALL" ]]; then
146 # Stop MySQL server
147 if is_service_enabled mysql; then
148 stop_service mysql
149 fi
Josh Kearney659eabf2012-09-06 13:47:06 -0500150
Matt Riedemannb14665f2019-10-17 19:34:05 +0000151 if is_service_enabled postgresql; then
152 stop_service postgresql
153 fi
154
Josh Kearney659eabf2012-09-06 13:47:06 -0500155 # Stop rabbitmq-server
156 if is_service_enabled rabbit; then
157 stop_service rabbitmq-server
158 fi
Dean Troyerf4d23952012-03-28 11:19:24 -0500159fi
Gary Kotton722fe672012-07-18 07:43:01 -0400160
Mark McClainb05c8762013-07-06 23:29:39 -0400161if is_service_enabled neutron; then
162 stop_neutron
Mark McClainb05c8762013-07-06 23:29:39 -0400163 cleanup_neutron
Gary Kotton722fe672012-07-18 07:43:01 -0400164fi
Ian Wienand31dcd3e2013-07-16 13:36:34 +1000165
Davanum Srinivas546656f2017-03-14 07:05:19 -0400166if is_service_enabled etcd3; then
167 stop_etcd3
168 cleanup_etcd3
169fi
170
Nobuhiro MIKI0572d732023-02-22 10:38:49 +0900171stop_dstat
Joe Gordone0b08d02014-08-20 00:34:55 -0700172
Jordan Pittier23bf0452015-05-29 11:38:22 +0200173# NOTE: Cinder automatically installs the lvm2 package, independently of the
Clay Gerrard40b433f2016-09-01 02:07:12 -0700174# enabled backends. So if Cinder is enabled, and installed successfully we are
175# sure lvm2 (lvremove, /etc/lvm/lvm.conf, etc.) is here.
176if is_service_enabled cinder && is_package_installed lvm2; then
Jordan Pittier23bf0452015-05-29 11:38:22 +0200177 clean_lvm_filter
178fi
Sean Mooneyae21b352020-09-01 14:11:45 +0000179
180clean_pyc_files
Dan Smith30d9bf92021-01-19 12:10:52 -0800181rm -Rf $DEST/async
Dan Smith4baeb3b2022-04-13 13:44:07 -0700182
183# Clean any safe.directory items we wrote into the global
184# gitconfig. We can identify the relevant ones by checking that they
185# point to somewhere in our $DEST directory.
Balazs Gibizer7191c5e2022-04-22 12:01:13 +0200186sudo sed -i "\+directory = ${DEST}+ d" /etc/gitconfig