Skip to content

Commit d3bf9bd

Browse files
author
Dean Troyer
committed
Re-order stack.sh 1: sanity checks
Part 1 of a series Re-order the setup and check bits in the top portion of stack.sh to have a logical flow with similar things done together. No behaviour changes are intended aside from the order of execution. Any such changes are bugs. * Do sanity checks that have no configuration needs earlier * Do supported distro check earlier Change-Id: I7d15bac199d6c4382d4a4d222784d34f2707da56
1 parent 0824c17 commit d3bf9bd

1 file changed

Lines changed: 61 additions & 60 deletions

File tree

stack.sh

Lines changed: 61 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,56 @@ umask 022
3737
# Keep track of the devstack directory
3838
TOP_DIR=$(cd $(dirname "$0") && pwd)
3939

40+
41+
# Sanity Checks
42+
# -------------
43+
44+
# Clean up last environment var cache
45+
if [[ -r $TOP_DIR/.stackenv ]]; then
46+
rm $TOP_DIR/.stackenv
47+
fi
48+
49+
# ``stack.sh`` keeps the list of ``apt`` and ``rpm`` dependencies and config
50+
# templates and other useful files in the ``files`` subdirectory
51+
FILES=$TOP_DIR/files
52+
if [ ! -d $FILES ]; then
53+
die $LINENO "missing devstack/files"
54+
fi
55+
56+
# ``stack.sh`` keeps function libraries here
57+
# Make sure ``$TOP_DIR/lib`` directory is present
58+
if [ ! -d $TOP_DIR/lib ]; then
59+
die $LINENO "missing devstack/lib"
60+
fi
61+
62+
# Check if run as root
63+
# OpenStack is designed to be run as a non-root user; Horizon will fail to run
64+
# as **root** since Apache will not serve content from **root** user).
65+
# ``stack.sh`` must not be run as **root**. It aborts and suggests one course of
66+
# action to create a suitable user account.
67+
68+
if [[ $EUID -eq 0 ]]; then
69+
echo "You are running this script as root."
70+
echo "Cut it out."
71+
echo "Really."
72+
echo "If you need an account to run DevStack, do this (as root, heh) to create $STACK_USER:"
73+
echo "$TOP_DIR/tools/create-stack-user.sh"
74+
exit 1
75+
fi
76+
77+
# Check to see if we are already running DevStack
78+
# Note that this may fail if USE_SCREEN=False
79+
if type -p screen >/dev/null && screen -ls | egrep -q "[0-9].$SCREEN_NAME"; then
80+
echo "You are already running a stack.sh session."
81+
echo "To rejoin this session type 'screen -x stack'."
82+
echo "To destroy this session, type './unstack.sh'."
83+
exit 1
84+
fi
85+
86+
87+
# Prepare the environment
88+
# -----------------------
89+
4090
# Import common functions
4191
source $TOP_DIR/functions
4292

@@ -48,6 +98,15 @@ source $TOP_DIR/lib/config
4898
# and ``DISTRO``
4999
GetDistro
50100

101+
# Warn users who aren't on an explicitly supported distro, but allow them to
102+
# override check and attempt installation with ``FORCE=yes ./stack``
103+
if [[ ! ${DISTRO} =~ (precise|trusty|7.0|wheezy|sid|testing|jessie|f19|f20|rhel6|rhel7) ]]; then
104+
echo "WARNING: this script has not been tested on $DISTRO"
105+
if [[ "$FORCE" != "yes" ]]; then
106+
die $LINENO "If you wish to run this script anyway run with FORCE=yes"
107+
fi
108+
fi
109+
51110

52111
# Global Settings
53112
# ===============
@@ -110,27 +169,6 @@ export_proxy_variables
110169
DEST=${DEST:-/opt/stack}
111170

112171

113-
# Sanity Check
114-
# ------------
115-
116-
# Clean up last environment var cache
117-
if [[ -r $TOP_DIR/.stackenv ]]; then
118-
rm $TOP_DIR/.stackenv
119-
fi
120-
121-
# ``stack.sh`` keeps the list of ``apt`` and ``rpm`` dependencies and config
122-
# templates and other useful files in the ``files`` subdirectory
123-
FILES=$TOP_DIR/files
124-
if [ ! -d $FILES ]; then
125-
die $LINENO "missing devstack/files"
126-
fi
127-
128-
# ``stack.sh`` keeps function libraries here
129-
# Make sure ``$TOP_DIR/lib`` directory is present
130-
if [ ! -d $TOP_DIR/lib ]; then
131-
die $LINENO "missing devstack/lib"
132-
fi
133-
134172
# Import common services (database, message queue) configuration
135173
source $TOP_DIR/lib/database
136174
source $TOP_DIR/lib/rpc_backend
@@ -140,14 +178,6 @@ source $TOP_DIR/lib/rpc_backend
140178
# calling disable_service().
141179
disable_negated_services
142180

143-
# Warn users who aren't on an explicitly supported distro, but allow them to
144-
# override check and attempt installation with ``FORCE=yes ./stack``
145-
if [[ ! ${DISTRO} =~ (precise|trusty|7.0|wheezy|sid|testing|jessie|f19|f20|rhel6|rhel7) ]]; then
146-
echo "WARNING: this script has not been tested on $DISTRO"
147-
if [[ "$FORCE" != "yes" ]]; then
148-
die $LINENO "If you wish to run this script anyway run with FORCE=yes"
149-
fi
150-
fi
151181

152182
# Look for obsolete stuff
153183
if [[ ,${ENABLED_SERVICES}, =~ ,"swift", ]]; then
@@ -157,38 +187,9 @@ if [[ ,${ENABLED_SERVICES}, =~ ,"swift", ]]; then
157187
exit 1
158188
fi
159189

160-
# Make sure we only have one rpc backend enabled,
161-
# and the specified rpc backend is available on your platform.
162-
check_rpc_backend
163-
164-
# Check to see if we are already running DevStack
165-
# Note that this may fail if USE_SCREEN=False
166-
if type -p screen >/dev/null && screen -ls | egrep -q "[0-9].$SCREEN_NAME"; then
167-
echo "You are already running a stack.sh session."
168-
echo "To rejoin this session type 'screen -x stack'."
169-
echo "To destroy this session, type './unstack.sh'."
170-
exit 1
171-
fi
172-
173-
# Set up logging level
174-
VERBOSE=$(trueorfalse True $VERBOSE)
175-
176-
# root Access
177-
# -----------
178-
179-
# OpenStack is designed to be run as a non-root user; Horizon will fail to run
180-
# as **root** since Apache will not serve content from **root** user).
181-
# ``stack.sh`` must not be run as **root**. It aborts and suggests one course of
182-
# action to create a suitable user account.
183190

184-
if [[ $EUID -eq 0 ]]; then
185-
echo "You are running this script as root."
186-
echo "Cut it out."
187-
echo "Really."
188-
echo "If you need an account to run DevStack, do this (as root, heh) to create $STACK_USER:"
189-
echo "$TOP_DIR/tools/create-stack-user.sh"
190-
exit 1
191-
fi
191+
# Configure sudo
192+
# --------------
192193

193194
# We're not **root**, make sure ``sudo`` is available
194195
is_package_installed sudo || install_package sudo

0 commit comments

Comments
 (0)