blob: 759a8dbacca4b3eb6a49ef7881440a9f97398132 [file] [log] [blame]
Jesse Andrewsba23cc72011-09-11 03:22:13 -07001#!/usr/bin/env bash
2
Dean Troyerc6c1d432012-03-27 20:59:22 -05003# ``stack.sh`` is an opinionated OpenStack developer installation. It
Chris Dente9a47502015-06-27 11:29:09 +00004# installs and configures various combinations of **Cinder**, **Glance**,
5# **Heat**, **Horizon**, **Keystone**, **Nova**, **Neutron**, and **Swift**
Jesse Andrewsba23cc72011-09-11 03:22:13 -07006
Brett Campbell27f29442014-02-19 18:23:16 -08007# This script's options can be changed by setting appropriate environment
8# variables. You can configure things like which git repositories to use,
9# services to enable, OS images to use, etc. Default values are located in the
10# ``stackrc`` file. If you are crafty you can run the script on multiple nodes
11# using shared settings for common resources (eg., mysql or rabbitmq) and build
12# a multi-node developer install.
Jesse Andrews782b9912011-10-02 16:53:21 -040013
Dean Troyer4a43b7b2012-08-28 17:43:40 -050014# To keep this script simple we assume you are running on a recent **Ubuntu**
Matt Riedemannff10ac32017-02-13 12:44:24 -050015# (16.04 Xenial or newer), **Fedora** (F24 or newer), or **CentOS/RHEL**
Martin Falatic5bee0cd2015-01-23 14:10:33 -080016# (7 or newer) machine. (It may work on other platforms but support for those
17# platforms is left to those who added them to DevStack.) It should work in
Dean Troyerdc97cb72015-03-28 08:20:50 -050018# a VM or physical server. Additionally, we maintain a list of ``deb`` and
Martin Falatic5bee0cd2015-01-23 14:10:33 -080019# ``rpm`` dependencies and other configuration files in this repo.
Jesse Andrews24859062011-09-15 21:28:23 -070020
Jesse Andrews0e7e8972011-10-02 16:36:54 -040021# Learn more and get the most recent version at http://devstack.org
Jesse Andrews6edd17f2011-09-15 22:19:42 -070022
Ian Wienandf0247ed2015-07-09 15:49:16 +100023# Print the commands being run so that we can see the command that triggers
24# an error. It is also useful for following along as the install occurs.
25set -o xtrace
26
Jason Dunsmore4e971112013-04-10 10:17:40 -050027# Make sure custom grep options don't get in the way
28unset GREP_OPTIONS
29
Ian Wienand91626082016-08-04 15:17:38 +100030# Sanitize language settings to avoid commands bailing out
31# with "unsupported locale setting" errors.
32unset LANG
33unset LANGUAGE
34LC_ALL=C
35export LC_ALL
36
Brett Campbell27f29442014-02-19 18:23:16 -080037# Make sure umask is sane
38umask 022
39
Angus Lees7df9d1b2014-07-21 15:35:34 +100040# Not all distros have sbin in PATH for regular users.
41PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin
42
Dean Troyerdc97cb72015-03-28 08:20:50 -050043# Keep track of the DevStack directory
Jesse Andrews51fb22e2011-10-19 09:24:17 -070044TOP_DIR=$(cd $(dirname "$0") && pwd)
45
Sean Dague53753292014-12-04 19:38:15 -050046# Check for uninitialized variables, a big cause of bugs
47NOUNSET=${NOUNSET:-}
48if [[ -n "$NOUNSET" ]]; then
49 set -o nounset
50fi
51
Matthew Treinish4af2afc2015-10-13 09:51:17 -040052# Set start of devstack timestamp
53DEVSTACK_START_TIME=$(date +%s)
Dean Troyerdc97cb72015-03-28 08:20:50 -050054
55# Configuration
56# =============
57
Dean Troyerd3bf9bd2014-07-25 10:20:19 -050058# Sanity Checks
59# -------------
60
61# Clean up last environment var cache
62if [[ -r $TOP_DIR/.stackenv ]]; then
63 rm $TOP_DIR/.stackenv
64fi
65
Dean Troyerdc97cb72015-03-28 08:20:50 -050066# ``stack.sh`` keeps the list of ``deb`` and ``rpm`` dependencies, config
Dean Troyerd3bf9bd2014-07-25 10:20:19 -050067# templates and other useful files in the ``files`` subdirectory
68FILES=$TOP_DIR/files
69if [ ! -d $FILES ]; then
70 die $LINENO "missing devstack/files"
71fi
72
73# ``stack.sh`` keeps function libraries here
Dean Troyerdc97cb72015-03-28 08:20:50 -050074# Make sure ``$TOP_DIR/inc`` directory is present
75if [ ! -d $TOP_DIR/inc ]; then
76 die $LINENO "missing devstack/inc"
77fi
78
79# ``stack.sh`` keeps project libraries here
Dean Troyerd3bf9bd2014-07-25 10:20:19 -050080# Make sure ``$TOP_DIR/lib`` directory is present
81if [ ! -d $TOP_DIR/lib ]; then
82 die $LINENO "missing devstack/lib"
83fi
84
Dean Troyerdc97cb72015-03-28 08:20:50 -050085# Check if run in POSIX shell
86if [[ "${POSIXLY_CORRECT}" == "y" ]]; then
Ian Wienand1afc28b2015-11-27 14:15:56 +110087 set +o xtrace
Dean Troyerdc97cb72015-03-28 08:20:50 -050088 echo "You are running POSIX compatibility mode, DevStack requires bash 4.2 or newer."
89 exit 1
90fi
91
Dean Troyerd3bf9bd2014-07-25 10:20:19 -050092# OpenStack is designed to be run as a non-root user; Horizon will fail to run
93# as **root** since Apache will not serve content from **root** user).
94# ``stack.sh`` must not be run as **root**. It aborts and suggests one course of
95# action to create a suitable user account.
96
97if [[ $EUID -eq 0 ]]; then
Ian Wienand1afc28b2015-11-27 14:15:56 +110098 set +o xtrace
99 echo "DevStack should be run as a user with sudo permissions, "
100 echo "not root."
101 echo "A \"stack\" user configured correctly can be created with:"
102 echo " $TOP_DIR/tools/create-stack-user.sh"
Dean Troyerd3bf9bd2014-07-25 10:20:19 -0500103 exit 1
104fi
105
Sean Dague90dd2622015-11-10 12:22:03 -0500106# OpenStack is designed to run at a system level, with system level
107# installation of python packages. It does not support running under a
108# virtual env, and will fail in really odd ways if you do this. Make
109# this explicit as it has come up on the mailing list.
110if [[ -n "$VIRTUAL_ENV" ]]; then
Ian Wienand1afc28b2015-11-27 14:15:56 +1100111 set +o xtrace
Sean Dague90dd2622015-11-10 12:22:03 -0500112 echo "You appear to be running under a python virtualenv."
Jordan Pittierc1750402015-11-12 11:03:20 +0100113 echo "DevStack does not support this, as we may break the"
Sean Dague90dd2622015-11-10 12:22:03 -0500114 echo "virtualenv you are currently in by modifying "
115 echo "external system-level components the virtualenv relies on."
Jordan Pittierc1750402015-11-12 11:03:20 +0100116 echo "We recommend you use a separate virtual-machine if "
Sean Dague90dd2622015-11-10 12:22:03 -0500117 echo "you are worried about DevStack taking over your system."
118 exit 1
119fi
120
Sean Dague56037e92015-10-08 12:27:07 -0400121# Provide a safety switch for devstack. If you do a lot of devstack,
122# on a lot of different environments, you sometimes run it on the
123# wrong box. This makes there be a way to prevent that.
124if [[ -e $HOME/.no-devstack ]]; then
Ian Wienand1afc28b2015-11-27 14:15:56 +1100125 set +o xtrace
Sean Dague56037e92015-10-08 12:27:07 -0400126 echo "You've marked this host as a no-devstack host, to save yourself from"
127 echo "running devstack accidentally. If this is in error, please remove the"
128 echo "~/.no-devstack file"
129 exit 1
130fi
Attila Fazekasd9de1192015-03-26 09:25:02 +0100131
Dean Troyerd3bf9bd2014-07-25 10:20:19 -0500132# Prepare the environment
133# -----------------------
134
Sean Dague53753292014-12-04 19:38:15 -0500135# Initialize variables:
136LAST_SPINNER_PID=""
137
Dean Troyer6563a3c2012-01-31 12:11:56 -0600138# Import common functions
Dean Troyerc6c1d432012-03-27 20:59:22 -0500139source $TOP_DIR/functions
Dean Troyer6563a3c2012-01-31 12:11:56 -0600140
Dean Troyer893e6632013-09-13 15:05:51 -0500141# Import config functions
Dean Troyerbf2ad702015-03-09 15:16:10 -0500142source $TOP_DIR/inc/meta-config
Dean Troyer893e6632013-09-13 15:05:51 -0500143
Dean Troyer8c2ce6e2015-02-18 14:47:54 -0600144# Import 'public' stack.sh functions
145source $TOP_DIR/lib/stack
146
Dean Troyerc6c1d432012-03-27 20:59:22 -0500147# Determine what system we are running on. This provides ``os_VENDOR``,
Ian Wienand7710e7f2014-08-27 16:15:32 +1000148# ``os_RELEASE``, ``os_PACKAGE``, ``os_CODENAME``
Dean Troyera9e0a482012-07-09 14:07:23 -0500149# and ``DISTRO``
150GetDistro
Jesse Andrews6edd17f2011-09-15 22:19:42 -0700151
Dean Troyerdc97cb72015-03-28 08:20:50 -0500152
Dean Troyer48352ee2012-12-12 12:50:38 -0600153# Global Settings
Dean Troyer0e8dced2014-07-25 10:33:21 -0500154# ---------------
Scott Moserf9da5082011-10-07 21:28:00 -0400155
Dean Troyer893e6632013-09-13 15:05:51 -0500156# Check for a ``localrc`` section embedded in ``local.conf`` and extract if
157# ``localrc`` does not already exist
158
159# Phase: local
160rm -f $TOP_DIR/.localrc.auto
Huan Xiecc6af3f2015-12-23 02:17:01 +0000161extract_localrc_section $TOP_DIR/local.conf $TOP_DIR/localrc $TOP_DIR/.localrc.auto
Dean Troyer893e6632013-09-13 15:05:51 -0500162
Dean Troyer1a6d4492013-06-03 16:47:36 -0500163# ``stack.sh`` is customizable by setting environment variables. Override a
Leticia Wanderley7f806492017-04-06 20:40:19 -0300164# default setting via export:
Scott Moserf9da5082011-10-07 21:28:00 -0400165#
Terry Wilson428af5a2012-11-01 16:12:39 -0400166# export DATABASE_PASSWORD=anothersecret
Scott Moserf9da5082011-10-07 21:28:00 -0400167# ./stack.sh
168#
Leticia Wanderley7f806492017-04-06 20:40:19 -0300169# or by setting the variable on the command line:
Scott Moserf9da5082011-10-07 21:28:00 -0400170#
Dean Troyer1a6d4492013-06-03 16:47:36 -0500171# DATABASE_PASSWORD=simple ./stack.sh
172#
Leticia Wanderley7f806492017-04-06 20:40:19 -0300173# Persistent variables can be placed in a ``local.conf`` file:
Scott Moserf9da5082011-10-07 21:28:00 -0400174#
Dean Troyerdc97cb72015-03-28 08:20:50 -0500175# [[local|localrc]]
Terry Wilson428af5a2012-11-01 16:12:39 -0400176# DATABASE_PASSWORD=anothersecret
177# DATABASE_USER=hellaroot
Scott Moserf9da5082011-10-07 21:28:00 -0400178#
179# We try to have sensible defaults, so you should be able to run ``./stack.sh``
Dean Troyerdc97cb72015-03-28 08:20:50 -0500180# in most cases. ``local.conf`` is not distributed with DevStack and will never
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500181# be overwritten by a DevStack update.
Scott Moserf9da5082011-10-07 21:28:00 -0400182#
Dean Troyerdf0972c2012-03-07 17:31:03 -0600183# DevStack distributes ``stackrc`` which contains locations for the OpenStack
Dean Troyercc6b4432013-04-08 15:38:03 -0500184# repositories, branches to configure, and other configuration defaults.
Dean Troyerdc97cb72015-03-28 08:20:50 -0500185# ``stackrc`` sources the ``localrc`` section of ``local.conf`` to allow you to
186# safely override those settings.
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500187
Dean Troyerbbafb1b2012-06-11 16:51:39 -0500188if [[ ! -r $TOP_DIR/stackrc ]]; then
Dean Troyer14fd9792014-07-25 10:34:11 -0500189 die $LINENO "missing $TOP_DIR/stackrc - did you grab more than just stack.sh?"
Dean Troyerbbafb1b2012-06-11 16:51:39 -0500190fi
191source $TOP_DIR/stackrc
Dean Troyerdf0972c2012-03-07 17:31:03 -0600192
Ian Wienandc973e6c2014-11-05 09:52:27 +1100193# Warn users who aren't on an explicitly supported distro, but allow them to
194# override check and attempt installation with ``FORCE=yes ./stack``
David Rabela4c57ca2017-03-17 16:14:00 +0100195if [[ ! ${DISTRO} =~ (xenial|yakkety|zesty|stretch|jessie|f24|f25|rhel7|kvmibm1) ]]; then
Ian Wienandc973e6c2014-11-05 09:52:27 +1100196 echo "WARNING: this script has not been tested on $DISTRO"
197 if [[ "$FORCE" != "yes" ]]; then
198 die $LINENO "If you wish to run this script anyway run with FORCE=yes"
199 fi
200fi
201
Shuichiro MAKIGAKI3710eec2014-08-28 19:07:09 +0900202# Check to see if we are already running DevStack
203# Note that this may fail if USE_SCREEN=False
204if type -p screen > /dev/null && screen -ls | egrep -q "[0-9]\.$SCREEN_NAME"; then
205 echo "You are already running a stack.sh session."
206 echo "To rejoin this session type 'screen -x stack'."
207 echo "To destroy this session, type './unstack.sh'."
208 exit 1
209fi
210
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500211
Dean Troyer48352ee2012-12-12 12:50:38 -0600212# Local Settings
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500213# --------------
214
Dean Troyer48352ee2012-12-12 12:50:38 -0600215# Make sure the proxy config is visible to sub-processes
216export_proxy_variables
Scott Moserf9da5082011-10-07 21:28:00 -0400217
Dean Troyerdc97cb72015-03-28 08:20:50 -0500218# Remove services which were negated in ``ENABLED_SERVICES``
Joe Gordon6fd28112012-11-13 16:55:41 -0800219# using the "-" prefix (e.g., "-rabbit") instead of
Doug Hellmannf04178f2012-07-05 17:10:03 -0400220# calling disable_service().
221disable_negated_services
Chmouel Boudjnahc4cd4142012-06-27 11:01:40 +0200222
Dean Troyera79617c2014-04-13 18:16:54 -0500223
Dean Troyerd3bf9bd2014-07-25 10:20:19 -0500224# Configure sudo
225# --------------
Dean Troyer9122e7b2011-10-17 14:07:11 -0500226
Dean Troyerdc97cb72015-03-28 08:20:50 -0500227# We're not as **root** so make sure ``sudo`` is available
Dean Troyer23f69d82013-10-04 12:35:24 -0500228is_package_installed sudo || install_package sudo
229
230# UEC images ``/etc/sudoers`` does not have a ``#includedir``, add one
231sudo grep -q "^#includedir.*/etc/sudoers.d" /etc/sudoers ||
232 echo "#includedir /etc/sudoers.d" | sudo tee -a /etc/sudoers
233
Sean Dagueb0160d02015-06-23 12:53:51 -0400234# Conditionally setup detailed logging for sudo
235if [[ -n "$LOG_SUDO" ]]; then
236 TEMPFILE=`mktemp`
237 echo "Defaults log_output" > $TEMPFILE
238 chmod 0440 $TEMPFILE
239 sudo chown root:root $TEMPFILE
240 sudo mv $TEMPFILE /etc/sudoers.d/00_logging
241fi
242
Dean Troyerdc97cb72015-03-28 08:20:50 -0500243# Set up DevStack sudoers
Dean Troyer23f69d82013-10-04 12:35:24 -0500244TEMPFILE=`mktemp`
245echo "$STACK_USER ALL=(root) NOPASSWD:ALL" >$TEMPFILE
Dean Troyerdc97cb72015-03-28 08:20:50 -0500246# Some binaries might be under ``/sbin`` or ``/usr/sbin``, so make sure sudo will
247# see them by forcing ``PATH``
Dean Troyer23f69d82013-10-04 12:35:24 -0500248echo "Defaults:$STACK_USER secure_path=/sbin:/usr/sbin:/usr/bin:/bin:/usr/local/sbin:/usr/local/bin" >> $TEMPFILE
Adam Gandelmanea2fcb52014-03-17 16:37:56 -0700249echo "Defaults:$STACK_USER !requiretty" >> $TEMPFILE
Dean Troyer23f69d82013-10-04 12:35:24 -0500250chmod 0440 $TEMPFILE
251sudo chown root:root $TEMPFILE
252sudo mv $TEMPFILE /etc/sudoers.d/50_stack_sh
253
Dean Troyer0e8dced2014-07-25 10:33:21 -0500254
255# Configure Distro Repositories
256# -----------------------------
Ian Wienand531aeb72014-02-28 11:24:29 +1100257
Dean Troyerdc97cb72015-03-28 08:20:50 -0500258# For Debian/Ubuntu make apt attempt to retry network ops on it's own
Sean Daguee83f7782014-06-23 08:11:05 -0400259if is_ubuntu; then
Chmouel Boudjnah9246d962014-06-30 12:52:51 +0000260 echo 'APT::Acquire::Retries "20";' | sudo tee /etc/apt/apt.conf.d/80retry >/dev/null
Sean Daguee83f7782014-06-23 08:11:05 -0400261fi
262
Ian Wienand531aeb72014-02-28 11:24:29 +1100263# Some distros need to add repos beyond the defaults provided by the vendor
264# to pick up required packages.
265
Ian Wienand95a9ff02015-11-12 14:49:20 +1100266function _install_epel_and_rdo {
Dean Troyerdc97cb72015-03-28 08:20:50 -0500267 # NOTE: We always remove and install latest -- some environments
Ian Wienanded077b22014-10-22 11:35:29 +1100268 # use snapshot images, and if EPEL version updates they break
269 # unless we update them to latest version.
270 if sudo yum repolist enabled epel | grep -q 'epel'; then
271 uninstall_package epel-release || true
272 fi
273
274 # This trick installs the latest epel-release from a bootstrap
275 # repo, then removes itself (as epel-release installed the
276 # "real" repo).
277 #
Dean Troyerdc97cb72015-03-28 08:20:50 -0500278 # You would think that rather than this, you could use
Ian Wienanded077b22014-10-22 11:35:29 +1100279 # $releasever directly in .repo file we create below. However
280 # RHEL gives a $releasever of "6Server" which breaks the path;
281 # see https://bugzilla.redhat.com/show_bug.cgi?id=1150759
Ian Wienanded077b22014-10-22 11:35:29 +1100282 cat <<EOF | sudo tee /etc/yum.repos.d/epel-bootstrap.repo
283[epel-bootstrap]
Ian Wienand3682b6d2014-10-08 15:37:23 +1100284name=Bootstrap EPEL
Attila Fazekas1f316be2015-01-26 16:39:57 +0100285mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-7&arch=\$basearch
Ian Wienand3682b6d2014-10-08 15:37:23 +1100286failovermethod=priority
287enabled=0
288gpgcheck=0
289EOF
Noboru Iwamatsua67ef002015-02-27 13:34:12 +0900290 # Enable a bootstrap repo. It is removed after finishing
291 # the epel-release installation.
Matt Riedemann2f63da92015-06-21 09:02:59 -0700292 is_package_installed yum-utils || install_package yum-utils
Noboru Iwamatsua67ef002015-02-27 13:34:12 +0900293 sudo yum-config-manager --enable epel-bootstrap
294 yum_install epel-release || \
Ian Wienanded077b22014-10-22 11:35:29 +1100295 die $LINENO "Error installing EPEL repo, cannot continue"
Ian Wienanded077b22014-10-22 11:35:29 +1100296 sudo rm -f /etc/yum.repos.d/epel-bootstrap.repo
Ian Wienand531aeb72014-02-28 11:24:29 +1100297
298 # ... and also optional to be enabled
Attila Fazekas1f316be2015-01-26 16:39:57 +0100299 sudo yum-config-manager --enable rhel-7-server-optional-rpms
Zhang Jinnanfc994262014-12-14 19:19:53 -0500300
Ian Wienand95a9ff02015-11-12 14:49:20 +1100301 # install the lastest RDO
Yusuke Hayashi6e187212016-01-22 00:08:31 +0900302 is_package_installed rdo-release || yum_install https://rdoproject.org/repos/rdo-release.rpm
Zhang Jinnanfc994262014-12-14 19:19:53 -0500303
Wiekus Beukesec47bc12015-03-19 08:20:38 -0700304 if is_oraclelinux; then
305 sudo yum-config-manager --enable ol7_optional_latest ol7_addons ol7_MySQL56
306 fi
Ian Wienand95a9ff02015-11-12 14:49:20 +1100307}
Wiekus Beukesec47bc12015-03-19 08:20:38 -0700308
Dean Troyer0e8dced2014-07-25 10:33:21 -0500309
310# Configure Target Directories
311# ----------------------------
312
313# Destination path for installation ``DEST``
314DEST=${DEST:-/opt/stack}
Dean Troyer23f69d82013-10-04 12:35:24 -0500315
Dean Troyere26232b2012-06-27 17:55:15 -0500316# Create the destination directory and ensure it is writable by the user
Bob Ball376b6312013-07-29 13:10:25 +0100317# and read/executable by everybody for daemons (e.g. apache run for horizon)
Dean Troyere26232b2012-06-27 17:55:15 -0500318sudo mkdir -p $DEST
Doug Hellmanne7002672013-09-05 08:10:07 -0400319safe_chown -R $STACK_USER $DEST
320safe_chmod 0755 $DEST
Dean Troyere26232b2012-06-27 17:55:15 -0500321
Ihar Hrachyshka09a3e712016-01-13 11:35:12 +0100322# Destination path for devstack logs
323if [[ -n ${LOGDIR:-} ]]; then
324 mkdir -p $LOGDIR
325fi
326
Dean Troyer0e8dced2014-07-25 10:33:21 -0500327# Destination path for service data
328DATA_DIR=${DATA_DIR:-${DEST}/data}
329sudo mkdir -p $DATA_DIR
330safe_chown -R $STACK_USER $DATA_DIR
Hongbin Lu571ba8b2017-03-29 22:06:54 -0400331safe_chmod 0755 $DATA_DIR
Dean Troyer0e8dced2014-07-25 10:33:21 -0500332
333# Configure proper hostname
Ben Nemec3ee52c82013-12-12 19:26:12 +0000334# Certain services such as rabbitmq require that the local hostname resolves
335# correctly. Make sure it exists in /etc/hosts so that is always true.
336LOCAL_HOSTNAME=`hostname -s`
337if [ -z "`grep ^127.0.0.1 /etc/hosts | grep $LOCAL_HOSTNAME`" ]; then
338 sudo sed -i "s/\(^127.0.0.1.*\)/\1 $LOCAL_HOSTNAME/" /etc/hosts
339fi
340
Ihar Hrachyshka09a3e712016-01-13 11:35:12 +0100341# If you have all the repos installed above already setup (e.g. a CI
342# situation where they are on your image) you may choose to skip this
343# to speed things up
344SKIP_EPEL_INSTALL=$(trueorfalse False SKIP_EPEL_INSTALL)
345
Ian Wienandbda194a2016-05-18 10:42:56 +1000346# If we have /etc/nodepool/provider assume we're on a OpenStack CI
347# node, where EPEL is already pointing at our internal mirror and RDO
348# is pre-installed.
349if [[ -f /etc/nodepool/provider ]]; then
350 SKIP_EPEL_INSTALL=True
351fi
352
Ihar Hrachyshka09a3e712016-01-13 11:35:12 +0100353if is_fedora && [[ $DISTRO == "rhel7" ]] && \
354 [[ ${SKIP_EPEL_INSTALL} != True ]]; then
355 _install_epel_and_rdo
356fi
357
Attila Fazekasadcf40d2015-11-05 09:47:38 +0100358# Ensure python is installed
359# --------------------------
360is_package_installed python || install_package python
361
Ian Wienand531aeb72014-02-28 11:24:29 +1100362
Dean Troyerffd17682014-08-02 16:07:03 -0500363# Configure Logging
364# -----------------
365
366# Set up logging level
Sean Dague53753292014-12-04 19:38:15 -0500367VERBOSE=$(trueorfalse True VERBOSE)
Dean Troyerffd17682014-08-02 16:07:03 -0500368
369# Draw a spinner so the user knows something is happening
370function spinner {
371 local delay=0.75
372 local spinstr='/-\|'
373 printf "..." >&3
374 while [ true ]; do
375 local temp=${spinstr#?}
376 printf "[%c]" "$spinstr" >&3
377 local spinstr=$temp${spinstr%"$temp"}
378 sleep $delay
379 printf "\b\b\b" >&3
380 done
381}
382
383function kill_spinner {
384 if [ ! -z "$LAST_SPINNER_PID" ]; then
385 kill >/dev/null 2>&1 $LAST_SPINNER_PID
386 printf "\b\b\bdone\n" >&3
387 fi
388}
389
390# Echo text to the log file, summary log file and stdout
391# echo_summary "something to say"
392function echo_summary {
393 if [[ -t 3 && "$VERBOSE" != "True" ]]; then
394 kill_spinner
395 echo -n -e $@ >&6
396 spinner &
397 LAST_SPINNER_PID=$!
398 else
399 echo -e $@ >&6
400 fi
401}
402
403# Echo text only to stdout, no log files
404# echo_nolog "something not for the logs"
405function echo_nolog {
406 echo $@ >&3
407}
408
Dean Troyerffd17682014-08-02 16:07:03 -0500409# Set up logging for ``stack.sh``
410# Set ``LOGFILE`` to turn on logging
411# Append '.xxxxxxxx' to the given name to maintain history
412# where 'xxxxxxxx' is a representation of the date the file was created
413TIMESTAMP_FORMAT=${TIMESTAMP_FORMAT:-"%F-%H%M%S"}
Dean Troyerdde41d02014-12-09 17:47:57 -0600414LOGDAYS=${LOGDAYS:-7}
415CURRENT_LOG_TIME=$(date "+$TIMESTAMP_FORMAT")
Dean Troyerffd17682014-08-02 16:07:03 -0500416
417if [[ -n "$LOGFILE" ]]; then
Dean Troyerad5cc982014-12-10 16:35:32 -0600418 # Clean up old log files. Append '.*' to the user-specified
419 # ``LOGFILE`` to match the date in the search template.
Mikhail S Medvedevfc9cc962015-01-20 11:04:48 -0600420 LOGFILE_DIR="${LOGFILE%/*}" # dirname
421 LOGFILE_NAME="${LOGFILE##*/}" # basename
422 mkdir -p $LOGFILE_DIR
423 find $LOGFILE_DIR -maxdepth 1 -name $LOGFILE_NAME.\* -mtime +$LOGDAYS -exec rm {} \;
Dean Troyerffd17682014-08-02 16:07:03 -0500424 LOGFILE=$LOGFILE.${CURRENT_LOG_TIME}
Dean Troyerad5cc982014-12-10 16:35:32 -0600425 SUMFILE=$LOGFILE.summary.${CURRENT_LOG_TIME}
Dean Troyerffd17682014-08-02 16:07:03 -0500426
427 # Redirect output according to config
428
429 # Set fd 3 to a copy of stdout. So we can set fd 1 without losing
430 # stdout later.
431 exec 3>&1
432 if [[ "$VERBOSE" == "True" ]]; then
433 # Set fd 1 and 2 to write the log file
434 exec 1> >( $TOP_DIR/tools/outfilter.py -v -o "${LOGFILE}" ) 2>&1
435 # Set fd 6 to summary log file
436 exec 6> >( $TOP_DIR/tools/outfilter.py -o "${SUMFILE}" )
437 else
438 # Set fd 1 and 2 to primary logfile
439 exec 1> >( $TOP_DIR/tools/outfilter.py -o "${LOGFILE}" ) 2>&1
440 # Set fd 6 to summary logfile and stdout
441 exec 6> >( $TOP_DIR/tools/outfilter.py -v -o "${SUMFILE}" >&3 )
442 fi
443
444 echo_summary "stack.sh log $LOGFILE"
445 # Specified logfile name always links to the most recent log
Mikhail S Medvedevfc9cc962015-01-20 11:04:48 -0600446 ln -sf $LOGFILE $LOGFILE_DIR/$LOGFILE_NAME
447 ln -sf $SUMFILE $LOGFILE_DIR/$LOGFILE_NAME.summary
Dean Troyerffd17682014-08-02 16:07:03 -0500448else
449 # Set up output redirection without log files
450 # Set fd 3 to a copy of stdout. So we can set fd 1 without losing
451 # stdout later.
452 exec 3>&1
453 if [[ "$VERBOSE" != "True" ]]; then
454 # Throw away stdout and stderr
455 exec 1>/dev/null 2>&1
456 fi
457 # Always send summary fd to original stdout
458 exec 6> >( $TOP_DIR/tools/outfilter.py -v >&3 )
459fi
460
461# Set up logging of screen windows
462# Set ``SCREEN_LOGDIR`` to turn on logging of screen windows to the
Wei Jiangang2af69152015-09-08 18:03:22 +0800463# directory specified in ``SCREEN_LOGDIR``, we will log to the file
Dean Troyerffd17682014-08-02 16:07:03 -0500464# ``screen-$SERVICE_NAME-$TIMESTAMP.log`` in that dir and have a link
465# ``screen-$SERVICE_NAME.log`` to the latest log file.
466# Logs are kept for as long specified in ``LOGDAYS``.
Dean Troyerdde41d02014-12-09 17:47:57 -0600467# This is deprecated....logs go in ``LOGDIR``, only symlinks will be here now.
Dean Troyerffd17682014-08-02 16:07:03 -0500468if [[ -n "$SCREEN_LOGDIR" ]]; then
469
470 # We make sure the directory is created.
471 if [[ -d "$SCREEN_LOGDIR" ]]; then
472 # We cleanup the old logs
473 find $SCREEN_LOGDIR -maxdepth 1 -name screen-\*.log -mtime +$LOGDAYS -exec rm {} \;
474 else
475 mkdir -p $SCREEN_LOGDIR
476 fi
477fi
478
Einst Crazy9e11e092015-09-29 20:01:44 +0800479# Basic test for ``$DEST`` path permissions (fatal on error unless skipped)
480check_path_perm_sanity ${DEST}
Dean Troyerffd17682014-08-02 16:07:03 -0500481
482# Configure Error Traps
483# ---------------------
484
485# Kill background processes on exit
486trap exit_trap EXIT
487function exit_trap {
488 local r=$?
489 jobs=$(jobs -p)
490 # Only do the kill when we're logging through a process substitution,
491 # which currently is only to verbose logfile
492 if [[ -n $jobs && -n "$LOGFILE" && "$VERBOSE" == "True" ]]; then
493 echo "exit_trap: cleaning up child processes"
494 kill 2>&1 $jobs
495 fi
496
497 # Kill the last spinner process
498 kill_spinner
499
500 if [[ $r -ne 0 ]]; then
501 echo "Error on exit"
Matthew Treinish4af2afc2015-10-13 09:51:17 -0400502 generate-subunit $DEVSTACK_START_TIME $SECONDS 'fail' >> ${SUBUNIT_OUTPUT}
Dean Troyerffd17682014-08-02 16:07:03 -0500503 if [[ -z $LOGDIR ]]; then
504 $TOP_DIR/tools/worlddump.py
505 else
506 $TOP_DIR/tools/worlddump.py -d $LOGDIR
507 fi
Matthew Treinish4af2afc2015-10-13 09:51:17 -0400508 else
509 generate-subunit $DEVSTACK_START_TIME $SECONDS >> ${SUBUNIT_OUTPUT}
Dean Troyerffd17682014-08-02 16:07:03 -0500510 fi
511
512 exit $r
513}
514
515# Exit on any errors so that errors don't compound
516trap err_trap ERR
517function err_trap {
518 local r=$?
519 set +o xtrace
520 if [[ -n "$LOGFILE" ]]; then
521 echo "${0##*/} failed: full log in $LOGFILE"
522 else
523 echo "${0##*/} failed"
524 fi
525 exit $r
526}
527
528# Begin trapping error exit codes
529set -o errexit
530
Dean Troyerdc97cb72015-03-28 08:20:50 -0500531# Print the kernel version
532uname -a
533
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000534# Reset the bundle of CA certificates
535SSL_BUNDLE_FILE="$DATA_DIR/ca-bundle.pem"
536rm -f $SSL_BUNDLE_FILE
537
Dean Troyer0e8dced2014-07-25 10:33:21 -0500538# Import common services (database, message queue) configuration
539source $TOP_DIR/lib/database
540source $TOP_DIR/lib/rpc_backend
541
Dean Troyerdc97cb72015-03-28 08:20:50 -0500542# Service to enable with SSL if ``USE_SSL`` is True
Sergey Lukjanov3381e092015-07-01 14:20:23 +0300543SSL_ENABLED_SERVICES="key,nova,cinder,glance,s-proxy,neutron"
Rob Crittenden18d47782014-03-19 17:47:42 -0400544
545if is_service_enabled tls-proxy && [ "$USE_SSL" == "True" ]; then
546 die $LINENO "tls-proxy and SSL are mutually exclusive"
547fi
Dean Troyerd81a0272012-08-31 18:04:55 -0500548
549# Configure Projects
550# ==================
551
Bharat Kumar Kobagana7b9341e2015-03-30 11:58:10 +0530552# Clone all external plugins
553fetch_plugins
554
Wei Jiangang2af69152015-09-08 18:03:22 +0800555# Plugin Phase 0: override_defaults - allow plugins to override
Sean Dague6e275e12015-03-26 05:54:28 -0400556# defaults before other services are run
557run_phase override_defaults
558
Dean Troyerdc97cb72015-03-28 08:20:50 -0500559# Import Apache functions
zhang-hared98a5d02013-06-21 18:18:02 +0800560source $TOP_DIR/lib/apache
Brant Knudson0049c0c2014-01-16 18:16:48 -0600561
562# Import TLS functions
Dean Troyerc83a7e12012-11-29 11:47:58 -0600563source $TOP_DIR/lib/tls
Brant Knudson0049c0c2014-01-16 18:16:48 -0600564
565# Source project function libraries
Sean Dague0392a102013-07-31 13:07:45 -0400566source $TOP_DIR/lib/infra
Sean Dague1b6b5312013-07-31 06:46:34 -0400567source $TOP_DIR/lib/oslo
Daniel Genind4708672014-10-31 15:01:29 -0400568source $TOP_DIR/lib/lvm
Sean Dagueb562e6a2012-11-19 16:00:01 -0500569source $TOP_DIR/lib/horizon
Dean Troyerd81a0272012-08-31 18:04:55 -0500570source $TOP_DIR/lib/keystone
Dean Troyer73f6f252012-09-17 11:22:21 -0500571source $TOP_DIR/lib/glance
Dean Troyerbf67c192012-09-21 15:09:37 -0500572source $TOP_DIR/lib/nova
Chris Dent4d601752016-07-12 19:34:09 +0000573source $TOP_DIR/lib/placement
Dean Troyerd81a0272012-08-31 18:04:55 -0500574source $TOP_DIR/lib/cinder
Attila Fazekasece6a332012-11-29 14:19:41 +0100575source $TOP_DIR/lib/swift
Sean M. Collins2a242512016-05-03 09:03:09 -0400576source $TOP_DIR/lib/neutron
Brad Topolf127e2f2013-01-22 10:17:50 -0600577source $TOP_DIR/lib/ldap
Joe Gordone0b08d02014-08-20 00:34:55 -0700578source $TOP_DIR/lib/dstat
Sean Dague5cad4d32015-11-10 14:39:07 -0500579source $TOP_DIR/lib/dlm
Patrick East657cdcd2016-07-01 16:08:15 -0700580source $TOP_DIR/lib/os_brick
Dean Troyerd81a0272012-08-31 18:04:55 -0500581
Dean Troyercdf3d762013-10-15 09:42:43 -0500582# Extras Source
583# --------------
584
585# Phase: source
Sean Dague2c65e712014-12-18 09:44:56 -0500586run_phase source
Dean Troyercdf3d762013-10-15 09:42:43 -0500587
Chris Dentc6d47012015-10-09 14:57:05 +0000588
Dean Troyerb7490da2013-03-18 16:07:56 -0500589# Interactive Configuration
590# -------------------------
591
592# Do all interactive config up front before the logging spew begins
James E. Blair213c4162012-11-06 09:38:36 +0100593
Anthony Young7a549f42011-10-12 07:13:13 +0000594# Generic helper to configure passwords
595function read_password {
Ian Wienand523f4882015-10-13 11:03:03 +1100596 local xtrace
597 xtrace=$(set +o | grep xtrace)
Anthony Young7a549f42011-10-12 07:13:13 +0000598 set +o xtrace
599 var=$1; msg=$2
600 pw=${!var}
601
Sahid Orentino Ferdjaoui9e032c22014-02-10 11:36:25 +0100602 if [[ -f $RC_DIR/localrc ]]; then
603 localrc=$TOP_DIR/localrc
604 else
Ian Wienand975f4202015-10-14 15:12:32 +1100605 localrc=$TOP_DIR/.localrc.password
Sahid Orentino Ferdjaoui9e032c22014-02-10 11:36:25 +0100606 fi
Anthony Young6015c822011-10-12 07:17:11 +0000607
Anthony Young7a549f42011-10-12 07:13:13 +0000608 # If the password is not defined yet, proceed to prompt user for a password.
609 if [ ! $pw ]; then
610 # If there is no localrc file, create one
Anthony Youngb4db2252011-10-12 14:08:08 -0700611 if [ ! -e $localrc ]; then
612 touch $localrc
Anthony Young7a549f42011-10-12 07:13:13 +0000613 fi
614
Ian Wienand975f4202015-10-14 15:12:32 +1100615 # Presumably if we got this far it can only be that our
616 # localrc is missing the required password. Prompt user for a
617 # password and write to localrc.
618
Anthony Youngb4db2252011-10-12 14:08:08 -0700619 echo ''
620 echo '################################################################################'
621 echo $msg
622 echo '################################################################################'
Ian Wienand975f4202015-10-14 15:12:32 +1100623 echo "This value will be written to ${localrc} file so you don't have to enter it "
Dean Troyer4e6a2b72011-12-29 17:27:45 -0600624 echo "again. Use only alphanumeric characters."
Anthony Youngb4db2252011-10-12 14:08:08 -0700625 echo "If you leave this blank, a random default value will be used."
Dean Troyer4e6a2b72011-12-29 17:27:45 -0600626 pw=" "
627 while true; do
628 echo "Enter a password now:"
629 read -e $var
630 pw=${!var}
631 [[ "$pw" = "`echo $pw | tr -cd [:alnum:]`" ]] && break
632 echo "Invalid chars in password. Try again:"
633 done
Anthony Youngb4db2252011-10-12 14:08:08 -0700634 if [ ! $pw ]; then
Attila Fazekasf71b5002014-05-28 09:52:22 +0200635 pw=$(generate_hex_string 10)
Anthony Young7a549f42011-10-12 07:13:13 +0000636 fi
Anthony Youngb4db2252011-10-12 14:08:08 -0700637 eval "$var=$pw"
638 echo "$var=$pw" >> $localrc
Anthony Young7a549f42011-10-12 07:13:13 +0000639 fi
Ian Wienand523f4882015-10-13 11:03:03 +1100640
641 # restore previous xtrace value
642 $xtrace
Anthony Young7a549f42011-10-12 07:13:13 +0000643}
644
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500645
Dean Troyerb9182d62012-11-07 12:31:34 -0600646# Database Configuration
Dean Troyerdc97cb72015-03-28 08:20:50 -0500647# ----------------------
Dean Troyerb9182d62012-11-07 12:31:34 -0600648
Dean Troyerdc97cb72015-03-28 08:20:50 -0500649# To select between database backends, add the following to ``local.conf``:
Terry Wilson428af5a2012-11-01 16:12:39 -0400650#
Dean Troyerafc29fe2013-02-07 15:56:24 -0600651# disable_service mysql
652# enable_service postgresql
Terry Wilson428af5a2012-11-01 16:12:39 -0400653#
Dean Troyerafc29fe2013-02-07 15:56:24 -0600654# The available database backends are listed in ``DATABASE_BACKENDS`` after
655# ``lib/database`` is sourced. ``mysql`` is the default.
Terry Wilson428af5a2012-11-01 16:12:39 -0400656
Daniel P. Berrangea99e5c92015-02-11 17:25:32 +0000657initialize_database_backends && echo "Using $DATABASE_TYPE database backend" || echo "No database enabled"
Terry Wilson428af5a2012-11-01 16:12:39 -0400658
Dean Troyerb9182d62012-11-07 12:31:34 -0600659
Dean Troyerb7490da2013-03-18 16:07:56 -0500660# Queue Configuration
Dean Troyerdc97cb72015-03-28 08:20:50 -0500661# -------------------
Jesse Andrews782b9912011-10-02 16:53:21 -0400662
Anthony Younga8416442011-09-13 20:07:44 -0700663# Rabbit connection info
Dean Troyerdc97cb72015-03-28 08:20:50 -0500664# In multi node DevStack, second node needs ``RABBIT_USERID``, but rabbit
Joe Gordonf6287c22014-12-16 13:32:41 -0800665# isn't enabled.
Russell Bryant4a221452012-03-13 13:44:12 -0400666if is_service_enabled rabbit; then
Russell Bryant4a221452012-03-13 13:44:12 -0400667 read_password RABBIT_PASSWORD "ENTER A PASSWORD TO USE FOR RABBIT."
668fi
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700669
Dean Troyerb7490da2013-03-18 16:07:56 -0500670
671# Keystone
Dean Troyerdc97cb72015-03-28 08:20:50 -0500672# --------
Dean Troyerb7490da2013-03-18 16:07:56 -0500673
Dean Troyer5ce44cd2015-02-12 22:18:33 -0600674if is_service_enabled keystone; then
Dean Troyerb7490da2013-03-18 16:07:56 -0500675 # Services authenticate to Identity with servicename/``SERVICE_PASSWORD``
676 read_password SERVICE_PASSWORD "ENTER A SERVICE_PASSWORD TO USE FOR THE SERVICE AUTHENTICATION."
677 # Horizon currently truncates usernames and passwords at 20 characters
678 read_password ADMIN_PASSWORD "ENTER A PASSWORD TO USE FOR HORIZON AND KEYSTONE (20 CHARS OR LESS)."
679
680 # Keystone can now optionally install OpenLDAP by enabling the ``ldap``
Dean Troyerdc97cb72015-03-28 08:20:50 -0500681 # service in ``local.conf`` (e.g. ``enable_service ldap``).
Dean Troyerb7490da2013-03-18 16:07:56 -0500682 # To clean out the Keystone contents in OpenLDAP set ``KEYSTONE_CLEAR_LDAP``
Dean Troyerdc97cb72015-03-28 08:20:50 -0500683 # to ``yes`` (e.g. ``KEYSTONE_CLEAR_LDAP=yes``) in ``local.conf``. To enable the
Dean Troyerb7490da2013-03-18 16:07:56 -0500684 # Keystone Identity Driver (``keystone.identity.backends.ldap.Identity``)
685 # set ``KEYSTONE_IDENTITY_BACKEND`` to ``ldap`` (e.g.
Dean Troyerdc97cb72015-03-28 08:20:50 -0500686 # ``KEYSTONE_IDENTITY_BACKEND=ldap``) in ``local.conf``.
Dean Troyerb7490da2013-03-18 16:07:56 -0500687
Dean Troyerdc97cb72015-03-28 08:20:50 -0500688 # Only request LDAP password if the service is enabled
Dean Troyerb7490da2013-03-18 16:07:56 -0500689 if is_service_enabled ldap; then
690 read_password LDAP_PASSWORD "ENTER A PASSWORD TO USE FOR LDAP"
Chmouel Boudjnah6ae9ea52012-07-05 06:50:51 +0000691 fi
Dean Troyerb7490da2013-03-18 16:07:56 -0500692fi
693
694
695# Swift
Dean Troyerdc97cb72015-03-28 08:20:50 -0500696# -----
Dean Troyerb7490da2013-03-18 16:07:56 -0500697
698if is_service_enabled s-proxy; then
Chmouel Boudjnah77b0e1d2012-02-29 16:55:43 +0000699 # We only ask for Swift Hash if we have enabled swift service.
Dean Troyerb9182d62012-11-07 12:31:34 -0600700 # ``SWIFT_HASH`` is a random unique string for a swift cluster that
Chmouel Boudjnahb2857e42011-11-03 16:19:14 +0100701 # can never change.
702 read_password SWIFT_HASH "ENTER A RANDOM SWIFT HASH."
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000703
704 if [[ -z "$SWIFT_TEMPURL_KEY" ]] && [[ "$SWIFT_ENABLE_TEMPURLS" == "True" ]]; then
705 read_password SWIFT_TEMPURL_KEY "ENTER A KEY FOR SWIFT TEMPURLS."
706 fi
Chmouel Boudjnahb2857e42011-11-03 16:19:14 +0100707fi
Vishvananda Ishaya5f039322011-11-05 16:12:20 -0700708
Dean Troyer68162342015-05-13 15:41:03 -0500709# Save configuration values
710save_stackenv $LINENO
711
Dean Troyerdf0972c2012-03-07 17:31:03 -0600712
Jesse Andrews30f68e92011-09-13 00:59:54 -0700713# Install Packages
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700714# ================
Dean Troyer7d28a0e2012-06-27 17:55:52 -0500715
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500716# OpenStack uses a fair number of other projects.
Jesse Andrews30f68e92011-09-13 00:59:54 -0700717
Shashank Hegde2d91fe82015-08-18 18:33:55 -0700718# Bring down global requirements before any use of pip_install. This is
719# necessary to ensure that the constraints file is in place before we
720# attempt to apply any constraints to pip installs.
721git_clone $REQUIREMENTS_REPO $REQUIREMENTS_DIR $REQUIREMENTS_BRANCH
722
Dean Troyer7d28a0e2012-06-27 17:55:52 -0500723# Install package requirements
Dean Troyer48352ee2012-12-12 12:50:38 -0600724# Source it so the entire environment is available
Dean Troyer7903b792012-09-13 17:16:12 -0500725echo_summary "Installing package prerequisites"
Dean Troyer48352ee2012-12-12 12:50:38 -0600726source $TOP_DIR/tools/install_prereqs.sh
Monty Taylor47f02062012-07-26 11:09:24 -0500727
Dean Troyerdc97cb72015-03-28 08:20:50 -0500728# Configure an appropriate Python environment
Arata Notsu8b5d3cf2013-10-17 21:42:49 +0900729if [[ "$OFFLINE" != "True" ]]; then
Sean Dague53753292014-12-04 19:38:15 -0500730 PYPI_ALTERNATIVE_URL=${PYPI_ALTERNATIVE_URL:-""} $TOP_DIR/tools/install_pip.sh
Arata Notsu8b5d3cf2013-10-17 21:42:49 +0900731fi
Dean Troyer1a6d4492013-06-03 16:47:36 -0500732
Matthew Treinish4af2afc2015-10-13 09:51:17 -0400733# Install subunit for the subunit output stream
734pip_install -U os-testr
735
Joe Gordon981ed292014-12-15 21:11:20 -0800736TRACK_DEPENDS=${TRACK_DEPENDS:-False}
737
Dean Troyerdc97cb72015-03-28 08:20:50 -0500738# Install Python packages into a virtualenv so that we can track them
Joe Gordon981ed292014-12-15 21:11:20 -0800739if [[ $TRACK_DEPENDS = True ]]; then
740 echo_summary "Installing Python packages into a virtualenv $DEST/.venv"
741 pip_install -U virtualenv
742
743 rm -rf $DEST/.venv
744 virtualenv --system-site-packages $DEST/.venv
745 source $DEST/.venv/bin/activate
746 $DEST/.venv/bin/pip freeze > $DEST/requires-pre-pip
747fi
748
Gael Chamoulaudd3121f62014-07-24 23:53:02 +0200749# Do the ugly hacks for broken packages and distros
Dean Troyer04a35112014-08-15 14:03:52 -0500750source $TOP_DIR/tools/fixup_stuff.sh
Dean Troyer9acc12a2013-08-09 15:09:31 -0500751
Dean Troyer5c3a63e2014-07-09 11:27:42 -0500752
Dean Troyerb1d8e8e2015-02-16 13:58:35 -0600753# Virtual Environment
754# -------------------
755
Yuki Nishiwaki0a9d03d2015-05-08 16:29:55 +0900756# Install required infra support libraries
757install_infra
758
Dean Troyer5c3a63e2014-07-09 11:27:42 -0500759# Extras Pre-install
760# ------------------
Dean Troyer5c3a63e2014-07-09 11:27:42 -0500761# Phase: pre-install
Sean Dague2c65e712014-12-18 09:44:56 -0500762run_phase stack pre-install
Dean Troyer5c3a63e2014-07-09 11:27:42 -0500763
Dean Troyer62d1d692013-08-01 17:40:40 -0500764install_rpc_backend
Dan Smithb1d85192017-02-23 08:01:32 -0800765restart_rpc_backend
Dean Troyer62d1d692013-08-01 17:40:40 -0500766
Sean Dague5cad4d32015-11-10 14:39:07 -0500767# NOTE(sdague): dlm install is conditional on one being enabled by configuration
768install_dlm
769configure_dlm
770
Dean Troyer62d1d692013-08-01 17:40:40 -0500771if is_service_enabled $DATABASE_BACKENDS; then
772 install_database
Olivier Lemasle7dd890d2015-09-14 14:21:12 +0200773fi
774if [ -n "$DATABASE_TYPE" ]; then
Dean Troyer5686dbc2015-03-09 14:27:51 -0500775 install_database_python
Dean Troyer62d1d692013-08-01 17:40:40 -0500776fi
777
778if is_service_enabled neutron; then
779 install_neutron_agent_packages
780fi
781
Dean Troyerfe51a902013-04-01 15:48:44 -0500782# Check Out and Install Source
783# ----------------------------
Dean Troyer4a43b7b2012-08-28 17:43:40 -0500784
Dean Troyer7903b792012-09-13 17:16:12 -0500785echo_summary "Installing OpenStack project source"
786
Dean Troyerdc97cb72015-03-28 08:20:50 -0500787# Install Oslo libraries
Sean Dague1b6b5312013-07-31 06:46:34 -0400788install_oslo
789
Dean Troyerdc97cb72015-03-28 08:20:50 -0500790# Install client libraries
Jamie Lennox21a90772015-07-03 11:54:38 +1000791install_keystoneauth
Dean Troyerd81a0272012-08-31 18:04:55 -0500792install_keystoneclient
Dean Troyer73f6f252012-09-17 11:22:21 -0500793install_glanceclient
Dean Troyer253a1a32013-04-01 18:23:22 -0500794install_cinderclient
Dean Troyerbf67c192012-09-21 15:09:37 -0500795install_novaclient
Sean Dague75195b52013-07-25 15:38:09 -0400796if is_service_enabled swift glance horizon; then
Dean Troyerfe51a902013-04-01 15:48:44 -0500797 install_swiftclient
798fi
Sean Dague75195b52013-07-25 15:38:09 -0400799if is_service_enabled neutron nova horizon; then
Mark McClainb05c8762013-07-06 23:29:39 -0400800 install_neutronclient
Dean Troyerfe51a902013-04-01 15:48:44 -0500801fi
802
Patrick East657cdcd2016-07-01 16:08:15 -0700803# Install shared libraries
804if is_service_enabled cinder nova; then
805 install_os_brick
806fi
807
Daniel P. Berrangec30b8de2016-11-14 13:23:14 +0000808# Setup TLS certs
809if is_service_enabled tls-proxy || [ "$USE_SSL" == "True" ]; then
810 configure_CA
811 init_CA
812 init_cert
813fi
814
Morgan Fainberg58936fd2014-06-24 12:26:07 -0700815# Install middleware
816install_keystonemiddleware
817
Dean Troyer5ce44cd2015-02-12 22:18:33 -0600818if is_service_enabled keystone; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100819 if [ "$KEYSTONE_AUTH_HOST" == "$SERVICE_HOST" ]; then
Dean Troyer8c2ce6e2015-02-18 14:47:54 -0600820 stack_install_service keystone
Bartosz Górski0abde392014-02-28 14:15:19 +0100821 configure_keystone
822 fi
Jesse Andrews38df1222011-11-20 09:55:44 -0800823fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100824
Sean Dague8b416ae2016-03-25 08:58:54 -0400825if is_service_enabled swift; then
gordon chungb6197e62015-02-12 15:33:35 -0500826 if is_service_enabled ceilometer; then
827 install_ceilometermiddleware
828 fi
Dean Troyer8c2ce6e2015-02-18 14:47:54 -0600829 stack_install_service swift
Dean Troyerfe51a902013-04-01 15:48:44 -0500830 configure_swift
831
rahmu9d2647a2013-04-24 10:40:07 +0200832 # swift3 middleware to provide S3 emulation to Swift
Chmouel Boudjnah6ae9ea52012-07-05 06:50:51 +0000833 if is_service_enabled swift3; then
Dean Troyerdc97cb72015-03-28 08:20:50 -0500834 # Replace the nova-objectstore port by the swift port
rahmu9d2647a2013-04-24 10:40:07 +0200835 S3_SERVICE_PORT=8080
Chmouel Boudjnah6ae9ea52012-07-05 06:50:51 +0000836 git_clone $SWIFT3_REPO $SWIFT3_DIR $SWIFT3_BRANCH
Dean Troyerfe51a902013-04-01 15:48:44 -0500837 setup_develop $SWIFT3_DIR
Chmouel Boudjnah6ae9ea52012-07-05 06:50:51 +0000838 fi
James E. Blaire7ce24f2011-11-10 13:05:13 -0800839fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100840
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +0000841if is_service_enabled g-api n-api; then
Dean Troyerdc97cb72015-03-28 08:20:50 -0500842 # Image catalog service
Dean Troyer8c2ce6e2015-02-18 14:47:54 -0600843 stack_install_service glance
Dean Troyerfe51a902013-04-01 15:48:44 -0500844 configure_glance
James E. Blaire7ce24f2011-11-10 13:05:13 -0800845fi
Dean Troyerfe51a902013-04-01 15:48:44 -0500846
847if is_service_enabled cinder; then
Dean Troyerdc97cb72015-03-28 08:20:50 -0500848 # Block volume service
Dean Troyer8c2ce6e2015-02-18 14:47:54 -0600849 stack_install_service cinder
Dean Troyerfe51a902013-04-01 15:48:44 -0500850 configure_cinder
851fi
852
Mark McClainb05c8762013-07-06 23:29:39 -0400853if is_service_enabled neutron; then
Dean Troyerdc97cb72015-03-28 08:20:50 -0500854 # Network service
Dean Troyer8c2ce6e2015-02-18 14:47:54 -0600855 stack_install_service neutron
Dean Troyerfe51a902013-04-01 15:48:44 -0500856fi
857
Dean Troyerbf67c192012-09-21 15:09:37 -0500858if is_service_enabled nova; then
Dean Troyerdc97cb72015-03-28 08:20:50 -0500859 # Compute service
Dean Troyer8c2ce6e2015-02-18 14:47:54 -0600860 stack_install_service nova
Dean Troyerfe51a902013-04-01 15:48:44 -0500861 cleanup_nova
862 configure_nova
Dean Troyerbf67c192012-09-21 15:09:37 -0500863fi
Dean Troyerfe51a902013-04-01 15:48:44 -0500864
Chris Dent4d601752016-07-12 19:34:09 +0000865if is_service_enabled placement; then
866 # placement api
867 stack_install_service placement
868 cleanup_placement
869 configure_placement
870fi
871
Sean Dague51a225c2016-12-15 16:32:08 -0500872# create a placement-client fake service to know we need to configure
873# placement connectivity. We configure the placement service for nova
874# if placement-api or placement-client is active, and n-cpu on the
875# same box.
876if is_service_enabled placement placement-client; then
Prashant Shettyf58b3732017-02-23 13:48:12 +0000877 if is_service_enabled n-cpu || is_service_enabled n-sch; then
Sean Dague51a225c2016-12-15 16:32:08 -0500878 configure_placement_nova_compute
879 fi
880fi
881
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +0000882if is_service_enabled horizon; then
Zhenguo Niue385d1e2014-03-12 16:58:12 +0800883 # django openstack_auth
884 install_django_openstack_auth
Sean Dagueb562e6a2012-11-19 16:00:01 -0500885 # dashboard
Dean Troyer8c2ce6e2015-02-18 14:47:54 -0600886 stack_install_service horizon
James E. Blaire7ce24f2011-11-10 13:05:13 -0800887fi
Dean Troyerfe51a902013-04-01 15:48:44 -0500888
Rob Crittenden18d47782014-03-19 17:47:42 -0400889if is_service_enabled tls-proxy || [ "$USE_SSL" == "True" ]; then
Daniel P. Berrangec30b8de2016-11-14 13:23:14 +0000890 fix_system_ca_bundle_path
Dean Troyer67787e62012-05-02 11:48:15 -0500891fi
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700892
Dean Troyercdf3d762013-10-15 09:42:43 -0500893# Extras Install
894# --------------
895
896# Phase: install
Sean Dague2c65e712014-12-18 09:44:56 -0500897run_phase stack install
Dean Troyercdf3d762013-10-15 09:42:43 -0500898
Dean Troyerdc97cb72015-03-28 08:20:50 -0500899# Install the OpenStack client, needed for most setup commands
Ihar Hrachyshka1ffa3322015-02-20 16:23:15 +0100900if use_library_from_git "python-openstackclient"; then
901 git_clone_by_name "python-openstackclient"
902 setup_dev_lib "python-openstackclient"
903else
Sean Dague60996b12015-04-08 09:06:49 -0400904 pip_install_gr python-openstackclient
Ihar Hrachyshka1ffa3322015-02-20 16:23:15 +0100905fi
906
Dean Troyercc6b4432013-04-08 15:38:03 -0500907if [[ $TRACK_DEPENDS = True ]]; then
Monty Taylor47f02062012-07-26 11:09:24 -0500908 $DEST/.venv/bin/pip freeze > $DEST/requires-post-pip
Dean Troyercc6b4432013-04-08 15:38:03 -0500909 if ! diff -Nru $DEST/requires-pre-pip $DEST/requires-post-pip > $DEST/requires.diff; then
DennyZhange8fa8532013-11-03 12:22:04 -0600910 echo "Detect some changes for installed packages of pip, in depend tracking mode"
Monty Taylor47f02062012-07-26 11:09:24 -0500911 cat $DEST/requires.diff
912 fi
913 echo "Ran stack.sh in depend tracking mode, bailing out now"
914 exit 0
915fi
Dean Troyerdf0972c2012-03-07 17:31:03 -0600916
Dean Troyerb7490da2013-03-18 16:07:56 -0500917
Dean Troyerff603ef2011-11-22 17:48:10 -0600918# Syslog
Dean Troyerdf0972c2012-03-07 17:31:03 -0600919# ------
Dean Troyerff603ef2011-11-22 17:48:10 -0600920
921if [[ $SYSLOG != "False" ]]; then
Dean Troyerff603ef2011-11-22 17:48:10 -0600922 if [[ "$SYSLOG_HOST" = "$HOST_IP" ]]; then
923 # Configure the master host to receive
924 cat <<EOF >/tmp/90-stack-m.conf
925\$ModLoad imrelp
926\$InputRELPServerRun $SYSLOG_PORT
927EOF
928 sudo mv /tmp/90-stack-m.conf /etc/rsyslog.d
929 else
930 # Set rsyslog to send to remote host
931 cat <<EOF >/tmp/90-stack-s.conf
932*.* :omrelp:$SYSLOG_HOST:$SYSLOG_PORT
933EOF
934 sudo mv /tmp/90-stack-s.conf /etc/rsyslog.d
935 fi
cloudnulle4859f02013-05-28 14:10:58 -0500936
937 RSYSLOGCONF="/etc/rsyslog.conf"
938 if [ -f $RSYSLOGCONF ]; then
939 sudo cp -b $RSYSLOGCONF $RSYSLOGCONF.bak
940 if [[ $(grep '$SystemLogRateLimitBurst' $RSYSLOGCONF) ]]; then
941 sudo sed -i 's/$SystemLogRateLimitBurst\ .*/$SystemLogRateLimitBurst\ 0/' $RSYSLOGCONF
942 else
943 sudo sed -i '$ i $SystemLogRateLimitBurst\ 0' $RSYSLOGCONF
944 fi
945 if [[ $(grep '$SystemLogRateLimitInterval' $RSYSLOGCONF) ]]; then
946 sudo sed -i 's/$SystemLogRateLimitInterval\ .*/$SystemLogRateLimitInterval\ 0/' $RSYSLOGCONF
947 else
948 sudo sed -i '$ i $SystemLogRateLimitInterval\ 0' $RSYSLOGCONF
949 fi
950 fi
951
Dean Troyer7903b792012-09-13 17:16:12 -0500952 echo_summary "Starting rsyslog"
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500953 restart_service rsyslog
Dean Troyerff603ef2011-11-22 17:48:10 -0600954fi
955
Dean Troyerdf0972c2012-03-07 17:31:03 -0600956
Atsushi SAKAIfe7b56c2015-11-13 17:06:16 +0900957# Export Certificate Authority Bundle
958# -----------------------------------
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000959
960# If certificates were used and written to the SSL bundle file then these
961# should be exported so clients can validate their connections.
962
963if [ -f $SSL_BUNDLE_FILE ]; then
964 export OS_CACERT=$SSL_BUNDLE_FILE
965fi
966
967
Terry Wilson428af5a2012-11-01 16:12:39 -0400968# Configure database
969# ------------------
Dean Troyerb9182d62012-11-07 12:31:34 -0600970
Terry Wilson428af5a2012-11-01 16:12:39 -0400971if is_service_enabled $DATABASE_BACKENDS; then
972 configure_database
Jesse Andrews24859062011-09-15 21:28:23 -0700973fi
974
Dean Troyerb9182d62012-11-07 12:31:34 -0600975
976# Configure screen
977# ----------------
978
Sean Dague53753292014-12-04 19:38:15 -0500979USE_SCREEN=$(trueorfalse True USE_SCREEN)
Dean Troyer681f3fd2013-02-27 19:00:39 -0600980if [[ "$USE_SCREEN" == "True" ]]; then
981 # Create a new named screen to run processes in
982 screen -d -m -S $SCREEN_NAME -t shell -s /bin/bash
983 sleep 1
984
985 # Set a reasonable status bar
Ed Cranfordff72c502015-01-21 16:42:42 -0600986 SCREEN_HARDSTATUS=${SCREEN_HARDSTATUS:-}
Dean Troyer681f3fd2013-02-27 19:00:39 -0600987 if [ -z "$SCREEN_HARDSTATUS" ]; then
988 SCREEN_HARDSTATUS='%{= .} %-Lw%{= .}%> %n%f %t*%{= .}%+Lw%< %-=%{g}(%{d}%H/%l%{g})'
989 fi
990 screen -r $SCREEN_NAME -X hardstatus alwayslastline "$SCREEN_HARDSTATUS"
Steven Dake30396572013-06-30 16:11:54 -0700991 screen -r $SCREEN_NAME -X setenv PROMPT_COMMAND /bin/true
Sean Daguef06455e2016-10-07 06:57:03 -0400992
993 if is_service_enabled tls-proxy; then
994 follow_tls_proxy
995 fi
Josh Kearney0a7a41e2012-04-04 17:47:56 -0500996fi
997
Dean Troyerdc97cb72015-03-28 08:20:50 -0500998# Clear ``screenrc`` file
Jiajun Liu61bb2c12012-10-19 09:48:30 +0800999SCREENRC=$TOP_DIR/$SCREEN_NAME-screenrc
1000if [[ -e $SCREENRC ]]; then
Jiajun Liu8e58c072013-07-17 06:41:50 +00001001 rm -f $SCREENRC
Jiajun Liu61bb2c12012-10-19 09:48:30 +08001002fi
Dean Troyerb9182d62012-11-07 12:31:34 -06001003
jiajun xua9414242012-12-06 16:30:57 +08001004# Initialize the directory for service status check
1005init_service_check
Dean Troyer7d28a0e2012-06-27 17:55:52 -05001006
Dean Troyer68162342015-05-13 15:41:03 -05001007# Save configuration values
1008save_stackenv $LINENO
1009
Clark Boylanf85e0ba2017-03-17 12:54:30 -07001010# Kernel Samepage Merging (KSM)
1011# -----------------------------
1012
1013# Processes that mark their memory as mergeable can share identical memory
1014# pages if KSM is enabled. This is particularly useful for nova + libvirt
1015# backends but any other setup that marks its memory as mergeable can take
1016# advantage. The drawback is there is higher cpu load; however, we tend to
1017# be memory bound not cpu bound so enable KSM by default but allow people
1018# to opt out if the CPU time is more important to them.
1019
1020if [[ "ENABLE_KSM" == "True" ]] ; then
1021 if [[ -f /sys/kernel/mm/ksm/run ]] ; then
1022 sudo sh -c "echo 1 > /sys/kernel/mm/ksm/run"
1023 fi
1024fi
1025
Dean Troyerdc97cb72015-03-28 08:20:50 -05001026
1027# Start Services
1028# ==============
1029
Sean Dague78096b52014-02-25 10:23:04 -05001030# Dstat
Dean Troyerdc97cb72015-03-28 08:20:50 -05001031# -----
Dean Troyer1a6d4492013-06-03 16:47:36 -05001032
Sean Daguef1eb0472014-02-11 17:28:56 -05001033# A better kind of sysstat, with the top process per time slice
Joe Gordone0b08d02014-08-20 00:34:55 -07001034start_dstat
Sean Dague062cdaf2014-02-10 22:24:49 -05001035
Dean Troyer893e6632013-09-13 15:05:51 -05001036
Dean Troyerd81a0272012-08-31 18:04:55 -05001037# Keystone
1038# --------
1039
Patrick Easta5d965a2016-08-03 14:44:53 -07001040# Rather than just export these, we write them out to a
1041# intermediate userrc file that can also be used to debug if
1042# something goes wrong between here and running
1043# tools/create_userrc.sh (this script relies on services other
1044# than keystone being available, so we can't call it right now)
1045cat > $TOP_DIR/userrc_early <<EOF
Steve Martinelli923be5f2015-12-20 00:24:19 -05001046# Use this for debugging issues before files in accrc are created
1047
1048# Set up password auth credentials now that Keystone is bootstrapped
1049export OS_IDENTITY_API_VERSION=3
1050export OS_AUTH_URL=$KEYSTONE_AUTH_URI
1051export OS_USERNAME=admin
1052export OS_USER_DOMAIN_ID=default
1053export OS_PASSWORD=$ADMIN_PASSWORD
1054export OS_PROJECT_NAME=admin
1055export OS_PROJECT_DOMAIN_ID=default
zhiyuan_cai6f1781f2016-04-07 18:36:46 +08001056export OS_REGION_NAME=$KEYSTONE_REGION_NAME
Steve Martinelli923be5f2015-12-20 00:24:19 -05001057
1058EOF
1059
Patrick Easta5d965a2016-08-03 14:44:53 -07001060if is_service_enabled tls-proxy; then
1061 echo "export OS_CACERT=$INT_CA_DIR/ca-chain.pem" >> $TOP_DIR/userrc_early
1062 start_tls_proxy http-services '*' 443 $SERVICE_HOST 80
1063fi
Rob Crittendenbe00e952016-03-24 18:09:22 -04001064
Patrick Easta5d965a2016-08-03 14:44:53 -07001065source $TOP_DIR/userrc_early
1066
1067if is_service_enabled keystone; then
1068 echo_summary "Starting Keystone"
1069
1070 if [ "$KEYSTONE_AUTH_HOST" == "$SERVICE_HOST" ]; then
1071 init_keystone
1072 start_keystone
1073 bootstrap_keystone
1074 fi
Dean Troyer42a59c22014-03-03 14:31:29 -06001075
Dean Troyerd835de82012-11-29 17:11:35 -06001076 create_keystone_accounts
Édouard Thuleau93a41562017-03-09 18:53:18 +01001077 if is_service_enabled nova; then
1078 create_nova_accounts
1079 fi
1080 if is_service_enabled glance; then
1081 create_glance_accounts
1082 fi
1083 if is_service_enabled cinder; then
1084 create_cinder_accounts
1085 fi
1086 if is_service_enabled neutron; then
1087 create_neutron_accounts
1088 fi
Dean Troyer42a59c22014-03-03 14:31:29 -06001089 if is_service_enabled swift; then
Ian Wienand0ff314c2013-07-17 16:30:19 +10001090 create_swift_accounts
1091 fi
1092
Dean Troyerd81a0272012-08-31 18:04:55 -05001093fi
1094
Monty Taylor7224eec2015-09-19 11:26:18 -04001095# Write a clouds.yaml file
1096write_clouds_yaml
Monty Taylor16a2d642015-09-19 11:19:31 -04001097
Tres Henryca85b792011-10-28 14:00:21 -07001098# Horizon
Dean Troyerdf0972c2012-03-07 17:31:03 -06001099# -------
Jesse Andrewscbe98d52011-10-02 17:47:32 -04001100
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001101if is_service_enabled horizon; then
Akihiro Motoki43f62c02015-12-15 16:44:41 +09001102 echo_summary "Configuring Horizon"
1103 configure_horizon
Anthony Young70dc5e02011-09-15 16:52:43 -07001104fi
Jesse Andrews75a37652011-09-12 17:09:08 -07001105
Anthony Young3859f732011-09-14 02:33:43 -07001106
Jesse Andrewsd74257d2011-09-13 01:24:50 -07001107# Glance
1108# ------
1109
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001110if is_service_enabled g-reg; then
Dean Troyer7903b792012-09-13 17:16:12 -05001111 echo_summary "Configuring Glance"
Dean Troyer73f6f252012-09-17 11:22:21 -05001112 init_glance
Anthony Young70dc5e02011-09-15 16:52:43 -07001113fi
Jesse Andrews75a37652011-09-12 17:09:08 -07001114
Dean Troyer8c032d12013-09-23 13:53:13 -05001115
Mark McClainb05c8762013-07-06 23:29:39 -04001116# Neutron
Anthony Young60df29a2012-03-28 09:40:17 -07001117# -------
Dean Troyer7d28a0e2012-06-27 17:55:52 -05001118
Mark McClainb05c8762013-07-06 23:29:39 -04001119if is_service_enabled neutron; then
1120 echo_summary "Configuring Neutron"
Dean Troyerb9182d62012-11-07 12:31:34 -06001121
Mark McClainb05c8762013-07-06 23:29:39 -04001122 configure_neutron
Dean Troyerdc97cb72015-03-28 08:20:50 -05001123 # Run init_neutron only on the node hosting the Neutron API server
Sean M. Collins2a242512016-05-03 09:03:09 -04001124 if is_service_enabled $DATABASE_BACKENDS && is_service_enabled neutron; then
Salvatore Orlandodd649882013-08-05 08:56:17 -07001125 init_neutron
1126 fi
Dan Wendlandt0007f3a2012-05-18 13:37:47 -07001127fi
1128
Jesse Andrewsd74257d2011-09-13 01:24:50 -07001129# Nova
1130# ----
Dean Troyerbd13b702012-02-13 11:22:36 -06001131
Isaku Yamahata6f85ab32012-08-06 16:56:10 +09001132if is_service_enabled n-net q-dhcp; then
Anthony Young55458452011-12-17 00:21:49 +00001133 # Delete traces of nova networks from prior runs
Davanum Srinivasd71d6e72013-01-28 19:15:57 -05001134 # Do not kill any dnsmasq instance spawned by NetworkManager
1135 netman_pid=$(pidof NetworkManager || true)
1136 if [ -z "$netman_pid" ]; then
1137 sudo killall dnsmasq || true
1138 else
1139 sudo ps h -o pid,ppid -C dnsmasq | grep -v $netman_pid | awk '{print $1}' | sudo xargs kill || true
1140 fi
1141
Anthony Young55458452011-12-17 00:21:49 +00001142 clean_iptables
Christian Berendt7a7fb492014-04-07 13:31:07 +00001143
1144 if is_service_enabled n-net; then
1145 rm -rf ${NOVA_STATE_PATH}/networks
1146 sudo mkdir -p ${NOVA_STATE_PATH}/networks
Chris Denta0ced4d2014-05-27 22:08:46 +01001147 safe_chown -R ${STACK_USER} ${NOVA_STATE_PATH}/networks
Christian Berendt7a7fb492014-04-07 13:31:07 +00001148 fi
1149
Dean Troyer1a6d4492013-06-03 16:47:36 -05001150 # Force IP forwarding on, just in case
Dean Troyer0b31e862012-03-07 16:47:56 -06001151 sudo sysctl -w net.ipv4.ip_forward=1
Anthony Young70dc5e02011-09-15 16:52:43 -07001152fi
Jesse Andrews75a37652011-09-12 17:09:08 -07001153
Dean Troyer7d28a0e2012-06-27 17:55:52 -05001154
Chmouel Boudjnah28fa4e82011-11-01 12:30:55 +01001155# Storage Service
Dean Troyer7d28a0e2012-06-27 17:55:52 -05001156# ---------------
1157
Sean Dague8b416ae2016-03-25 08:58:54 -04001158if is_service_enabled swift; then
Dean Troyer7903b792012-09-13 17:16:12 -05001159 echo_summary "Configuring Swift"
Attila Fazekasece6a332012-11-29 14:19:41 +01001160 init_swift
Chmouel Boudjnah28fa4e82011-11-01 12:30:55 +01001161fi
1162
Dean Troyerdf0972c2012-03-07 17:31:03 -06001163
Anthony Youngacff87a2011-10-20 10:12:58 -07001164# Volume Service
1165# --------------
1166
Dean Troyer67787e62012-05-02 11:48:15 -05001167if is_service_enabled cinder; then
Dean Troyer7903b792012-09-13 17:16:12 -05001168 echo_summary "Configuring Cinder"
Dean Troyer67787e62012-05-02 11:48:15 -05001169 init_cinder
Anthony Youngacff87a2011-10-20 10:12:58 -07001170fi
1171
Dean Troyer2aa2a892013-08-04 19:53:19 -05001172
1173# Compute Service
1174# ---------------
1175
Dean Troyerbf67c192012-09-21 15:09:37 -05001176if is_service_enabled nova; then
1177 echo_summary "Configuring Nova"
1178 init_nova
Jesse Andrewsd1879c52011-09-16 16:28:13 -07001179
Dean Troyer86a79692012-10-22 15:24:46 -05001180 # Additional Nova configuration that is dependent on other services
Mark McClainb05c8762013-07-06 23:29:39 -04001181 if is_service_enabled neutron; then
Sean M. Collins2a242512016-05-03 09:03:09 -04001182 configure_neutron_nova
Dean Troyer86a79692012-10-22 15:24:46 -05001183 elif is_service_enabled n-net; then
Akihiro MOTOKI66afb472012-12-21 15:34:13 +09001184 create_nova_conf_nova_network
Brad Hall1bfa3d52011-10-27 18:18:20 -07001185 fi
Dean Troyerdf0972c2012-03-07 17:31:03 -06001186
Kieran Spearfb2a3ae2013-03-11 23:55:49 +00001187 init_nova_cells
Anthony Youngb62b4ca2011-10-26 22:29:08 -07001188fi
1189
Chris Dent4d601752016-07-12 19:34:09 +00001190if is_service_enabled placement; then
1191 echo_summary "Configuring placement"
1192 init_placement
1193fi
1194
Dean Troyerdc97cb72015-03-28 08:20:50 -05001195
Dean Troyercdf3d762013-10-15 09:42:43 -05001196# Extras Configuration
1197# ====================
1198
1199# Phase: post-config
Sean Dague2c65e712014-12-18 09:44:56 -05001200run_phase stack post-config
Dean Troyercdf3d762013-10-15 09:42:43 -05001201
1202
Dean Troyer893e6632013-09-13 15:05:51 -05001203# Local Configuration
1204# ===================
1205
Dean Troyerdc97cb72015-03-28 08:20:50 -05001206# Apply configuration from ``local.conf`` if it exists for layer 2 services
Dean Troyer893e6632013-09-13 15:05:51 -05001207# Phase: post-config
1208merge_config_group $TOP_DIR/local.conf post-config
1209
1210
Jesse Andrewsd74257d2011-09-13 01:24:50 -07001211# Launch Services
1212# ===============
Jesse Andrews30f68e92011-09-13 00:59:54 -07001213
Jesse Andrewsdfcd2002011-09-13 13:17:22 -07001214# Only run the services specified in ``ENABLED_SERVICES``
1215
Attila Fazekasece6a332012-11-29 14:19:41 +01001216# Launch Swift Services
Sean Dague8b416ae2016-03-25 08:58:54 -04001217if is_service_enabled swift; then
Attila Fazekasece6a332012-11-29 14:19:41 +01001218 echo_summary "Starting Swift"
1219 start_swift
1220fi
1221
Dean Troyer73f6f252012-09-17 11:22:21 -05001222# Launch the Glance services
Dean Troyere4fa7212014-01-15 15:04:49 -06001223if is_service_enabled glance; then
Dean Troyer7903b792012-09-13 17:16:12 -05001224 echo_summary "Starting Glance"
Dean Troyer73f6f252012-09-17 11:22:21 -05001225 start_glance
Anthony Youngd000b222011-09-19 14:46:53 -07001226fi
1227
Dean Troyerdc97cb72015-03-28 08:20:50 -05001228
Eric Windisch0b9776d2014-01-28 11:20:53 -05001229# Install Images
1230# ==============
1231
Dean Troyerdc97cb72015-03-28 08:20:50 -05001232# Upload an image to Glance.
Eric Windisch0b9776d2014-01-28 11:20:53 -05001233#
Dean Troyerdc97cb72015-03-28 08:20:50 -05001234# The default image is CirrOS, a small testing image which lets you login as **root**
1235# CirrOS has a ``cloud-init`` analog supporting login via keypair and sending
Eric Windisch0b9776d2014-01-28 11:20:53 -05001236# scripts as userdata.
Dean Troyerdc97cb72015-03-28 08:20:50 -05001237# See https://help.ubuntu.com/community/CloudInit for more on ``cloud-init``
Eric Windisch0b9776d2014-01-28 11:20:53 -05001238
1239if is_service_enabled g-reg; then
Eric Windisch0b9776d2014-01-28 11:20:53 -05001240
Sean Dague2f8e08b2014-12-05 08:31:16 -05001241 echo_summary "Uploading images"
Eric Windisch0b9776d2014-01-28 11:20:53 -05001242
Sean Dague2f8e08b2014-12-05 08:31:16 -05001243 for image_url in ${IMAGE_URLS//,/ }; do
Peter Stachowski5aeea6a2015-09-22 19:38:02 +00001244 upload_image $image_url
Sean Dague2f8e08b2014-12-05 08:31:16 -05001245 done
Eric Windisch0b9776d2014-01-28 11:20:53 -05001246fi
1247
Jordan Pittier50f22da2016-05-10 15:04:44 +02001248# Create a randomized default value for the key manager's fixed_key
Kaitlin Farrdef4c142014-01-06 08:52:49 -05001249if is_service_enabled nova; then
Jordan Pittier50f22da2016-05-10 15:04:44 +02001250 iniset $NOVA_CONF key_manager fixed_key $(generate_hex_string 32)
Kaitlin Farrdef4c142014-01-06 08:52:49 -05001251fi
1252
Dean Troyer7d28a0e2012-06-27 17:55:52 -05001253# Launch the nova-api and wait for it to answer before continuing
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001254if is_service_enabled n-api; then
Dean Troyer7903b792012-09-13 17:16:12 -05001255 echo_summary "Starting Nova API"
Dean Troyer3a3a2ba2012-12-11 15:26:24 -06001256 start_nova_api
Anthony Youngd000b222011-09-19 14:46:53 -07001257fi
Brad Hall1bfa3d52011-10-27 18:18:20 -07001258
Sean M. Collins2a242512016-05-03 09:03:09 -04001259if is_service_enabled neutron-api; then
1260 echo_summary "Starting Neutron"
1261 start_neutron_api
Sean M. Collins2a242512016-05-03 09:03:09 -04001262elif is_service_enabled q-svc; then
Mark McClainb05c8762013-07-06 23:29:39 -04001263 echo_summary "Starting Neutron"
Mark McClainb05c8762013-07-06 23:29:39 -04001264 start_neutron_service_and_check
Aaron Rosen8ec719b2012-10-30 12:57:47 -07001265elif is_service_enabled $DATABASE_BACKENDS && is_service_enabled n-net; then
Kieran Spearfb2a3ae2013-03-11 23:55:49 +00001266 NM_CONF=${NOVA_CONF}
1267 if is_service_enabled n-cell; then
1268 NM_CONF=${NOVA_CELLS_CONF}
1269 fi
1270
Gary Kotton37dda8d2012-08-08 03:46:33 -04001271 # Create a small network
Kieran Spearfb2a3ae2013-03-11 23:55:49 +00001272 $NOVA_BIN_DIR/nova-manage --config-file $NM_CONF network create "$PRIVATE_NETWORK_NAME" $FIXED_RANGE 1 $FIXED_NETWORK_SIZE $NETWORK_CREATE_ARGS
Dean Troyer696ad332012-01-10 15:34:34 -06001273
Gary Kotton37dda8d2012-08-08 03:46:33 -04001274 # Create some floating ips
Kieran Spearfb2a3ae2013-03-11 23:55:49 +00001275 $NOVA_BIN_DIR/nova-manage --config-file $NM_CONF floating create $FLOATING_RANGE --pool=$PUBLIC_NETWORK_NAME
Aaron Rosen9313dfa2012-07-06 16:08:49 -04001276
Gary Kotton37dda8d2012-08-08 03:46:33 -04001277 # Create a second pool
Kieran Spearfb2a3ae2013-03-11 23:55:49 +00001278 $NOVA_BIN_DIR/nova-manage --config-file $NM_CONF floating create --ip_range=$TEST_FLOATING_RANGE --pool=$TEST_FLOATING_POOL
Brad Hall1bfa3d52011-10-27 18:18:20 -07001279fi
1280
Mark McClainb05c8762013-07-06 23:29:39 -04001281if is_service_enabled neutron; then
Sean M. Collins2a242512016-05-03 09:03:09 -04001282 start_neutron
Akihiro MOTOKI66afb472012-12-21 15:34:13 +09001283fi
Salvatore Orlando6fbb28d2013-12-22 07:59:37 -08001284# Once neutron agents are started setup initial network elements
YAMAMOTO Takashi07edde12016-10-19 19:21:00 +00001285if is_service_enabled q-svc && [[ "$NEUTRON_CREATE_INITIAL_NETWORKS" == "True" ]]; then
1286 echo_summary "Creating initial neutron network elements"
1287 create_neutron_initial_network
1288fi
Sean M. Collins2a242512016-05-03 09:03:09 -04001289
Dean Troyerbf67c192012-09-21 15:09:37 -05001290if is_service_enabled nova; then
1291 echo_summary "Starting Nova"
1292 start_nova
Dan Smith4b205db2016-04-04 10:37:11 -07001293 create_flavors
Dean Troyerbf67c192012-09-21 15:09:37 -05001294fi
Chris Dent4d601752016-07-12 19:34:09 +00001295if is_service_enabled placement; then
1296 echo_summary "Starting Placement"
1297 start_placement
1298fi
Dean Troyer67787e62012-05-02 11:48:15 -05001299if is_service_enabled cinder; then
Dean Troyer7903b792012-09-13 17:16:12 -05001300 echo_summary "Starting Cinder"
Dean Troyer67787e62012-05-02 11:48:15 -05001301 start_cinder
Dean Troyer09718332014-07-03 10:46:57 -05001302 create_volume_types
Dean Troyer67787e62012-05-02 11:48:15 -05001303fi
Sean Dagueb562e6a2012-11-19 16:00:01 -05001304
Dean Troyer7d28a0e2012-06-27 17:55:52 -05001305
Akihiro Motoki43f62c02015-12-15 16:44:41 +09001306if is_service_enabled horizon; then
1307 echo_summary "Starting Horizon"
1308 init_horizon
1309 start_horizon
1310fi
1311
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +10001312
Andrey Pavlov50901422015-09-22 21:20:36 +03001313# Create account rc files
1314# =======================
1315
1316# Creates source able script files for easier user switching.
1317# This step also creates certificates for tenants and users,
1318# which is helpful in image bundle steps.
1319
1320if is_service_enabled nova && is_service_enabled keystone; then
1321 USERRC_PARAMS="-PA --target-dir $TOP_DIR/accrc"
1322
1323 if [ -f $SSL_BUNDLE_FILE ]; then
1324 USERRC_PARAMS="$USERRC_PARAMS --os-cacert $SSL_BUNDLE_FILE"
1325 fi
1326
1327 if [[ "$HEAT_STANDALONE" = "True" ]]; then
1328 USERRC_PARAMS="$USERRC_PARAMS --heat-url http://$HEAT_API_HOST:$HEAT_API_PORT/v1"
1329 fi
1330
1331 $TOP_DIR/tools/create_userrc.sh $USERRC_PARAMS
1332fi
1333
1334
1335# Save some values we generated for later use
1336save_stackenv
1337
1338
Dean Troyerdc97cb72015-03-28 08:20:50 -05001339# Wrapup configuration
1340# ====================
Dean Troyer893e6632013-09-13 15:05:51 -05001341
Dean Troyerdc97cb72015-03-28 08:20:50 -05001342# local.conf extra
1343# ----------------
1344
1345# Apply configuration from ``local.conf`` if it exists for layer 2 services
Dean Troyer893e6632013-09-13 15:05:51 -05001346# Phase: extra
1347merge_config_group $TOP_DIR/local.conf extra
1348
1349
Dean Troyer768295e2013-01-09 13:42:03 -06001350# Run extras
Dean Troyerdc97cb72015-03-28 08:20:50 -05001351# ----------
Dean Troyer768295e2013-01-09 13:42:03 -06001352
Dean Troyercdf3d762013-10-15 09:42:43 -05001353# Phase: extra
Sean Dague2c65e712014-12-18 09:44:56 -05001354run_phase stack extra
Dean Troyer768295e2013-01-09 13:42:03 -06001355
Ryan Hsufeb28832013-11-07 12:12:35 -08001356
Dean Troyerdc97cb72015-03-28 08:20:50 -05001357# local.conf post-extra
1358# ---------------------
1359
1360# Apply late configuration from ``local.conf`` if it exists for layer 2 services
Ryan Hsufeb28832013-11-07 12:12:35 -08001361# Phase: post-extra
1362merge_config_group $TOP_DIR/local.conf post-extra
1363
Dean Troyer768295e2013-01-09 13:42:03 -06001364
Dean Troyerf5633dd2012-03-28 11:21:40 -05001365# Run local script
Dean Troyerdc97cb72015-03-28 08:20:50 -05001366# ----------------
Dean Troyerf5633dd2012-03-28 11:21:40 -05001367
1368# Run ``local.sh`` if it exists to perform user-managed tasks
1369if [[ -x $TOP_DIR/local.sh ]]; then
1370 echo "Running user script $TOP_DIR/local.sh"
1371 $TOP_DIR/local.sh
1372fi
1373
Sean Daguec71973e2015-09-08 07:12:48 -04001374# Sanity checks
1375# =============
1376
jiajun xua9414242012-12-06 16:30:57 +08001377# Check the status of running services
1378service_check
Dean Troyerf5633dd2012-03-28 11:21:40 -05001379
Sean Daguec71973e2015-09-08 07:12:48 -04001380# ensure that all the libraries we think we installed from git,
1381# actually were.
1382check_libs_from_git
1383
Dean Troyerb7490da2013-03-18 16:07:56 -05001384
Dan Smith71119b42016-08-15 12:06:55 -07001385# Configure nova cellsv2
1386# ----------------------
1387
1388# Do this late because it requires compute hosts to have started
Matt Riedemannf1660812016-11-01 15:44:06 -04001389if is_service_enabled n-api; then
Sean Dague6d66e642016-12-05 06:28:26 -05001390 if is_service_enabled n-cpu; then
Matt Riedemannf15224c2017-03-02 12:45:47 -05001391 $TOP_DIR/tools/discover_hosts.sh
Sean Dague6d66e642016-12-05 06:28:26 -05001392 else
1393 # Some CI systems like Hyper-V build the control plane on
1394 # Linux, and join in non Linux Computes after setup. This
1395 # allows them to delay the processing until after their whole
1396 # environment is up.
1397 echo_summary "SKIPPING Cell setup because n-cpu is not enabled. You will have to do this manually before you have a working environment."
1398 fi
Dan Smith71119b42016-08-15 12:06:55 -07001399fi
1400
Steve Martinellibbe771a2015-01-20 13:30:33 -05001401# Bash completion
1402# ===============
1403
1404# Prepare bash completion for OSC
Steve Martinelli5ff77d62016-09-06 19:10:22 +00001405openstack complete | sudo tee /etc/bash_completion.d/osc.bash_completion > /dev/null
Steve Martinellibbe771a2015-01-20 13:30:33 -05001406
John Griffith4bf861c2015-03-17 21:07:39 -06001407# If cinder is configured, set global_filter for PV devices
1408if is_service_enabled cinder; then
1409 if is_ubuntu; then
1410 echo_summary "Configuring lvm.conf global device filter"
1411 set_lvm_filter
1412 else
1413 echo_summary "Skip setting lvm filters for non Ubuntu systems"
1414 fi
1415fi
Steve Martinellibbe771a2015-01-20 13:30:33 -05001416
Matthew Treinish655c22c2016-05-02 13:29:10 -04001417# Run test-config
1418# ---------------
1419
1420# Phase: test-config
1421run_phase stack test-config
1422
Sean Dague8bf8c8f2016-12-01 10:24:06 -05001423# Apply late configuration from ``local.conf`` if it exists for layer 2 services
1424# Phase: test-config
1425merge_config_group $TOP_DIR/local.conf test-config
Dean Troyerdc97cb72015-03-28 08:20:50 -05001426
Scott Moserb94f4bf2011-10-07 14:51:07 +00001427# Fin
1428# ===
1429
Dean Troyer471de7a2011-12-27 11:45:55 -06001430set +o xtrace
Scott Moserb94f4bf2011-10-07 14:51:07 +00001431
Dean Troyer7903b792012-09-13 17:16:12 -05001432if [[ -n "$LOGFILE" ]]; then
1433 exec 1>&3
1434 # Force all output to stdout and logs now
Dean Troyerbaa8b422012-09-24 15:02:05 -05001435 exec 1> >( tee -a "${LOGFILE}" ) 2>&1
Dean Troyer7903b792012-09-13 17:16:12 -05001436else
1437 # Force all output to stdout now
1438 exec 1>&3
1439fi
1440
Sean Dague95c33d52015-10-07 11:05:59 -04001441# Dump out the time totals
1442time_totals
Dean Troyerdf0972c2012-03-07 17:31:03 -06001443
Jesse Andrews24859062011-09-15 21:28:23 -07001444# Using the cloud
Dean Troyerdc97cb72015-03-28 08:20:50 -05001445# ===============
Jesse Andrews24859062011-09-15 21:28:23 -07001446
Jesse Andrewse19d8842011-11-01 20:06:55 -07001447echo ""
1448echo ""
1449echo ""
Brian Haley180f5eb2015-06-16 13:14:31 -04001450echo "This is your host IP address: $HOST_IP"
1451if [ "$HOST_IPV6" != "" ]; then
1452 echo "This is your host IPv6 address: $HOST_IPV6"
1453fi
Jesse Andrewse19d8842011-11-01 20:06:55 -07001454
Dean Troyerdf0972c2012-03-07 17:31:03 -06001455# If you installed Horizon on this server you should be able
root40a37002011-09-20 18:06:14 +00001456# to access the site using your browser.
Chmouel Boudjnaha6651e92012-02-16 10:16:52 +00001457if is_service_enabled horizon; then
David Lyle7b105c52015-07-27 17:14:32 -06001458 echo "Horizon is now available at http://$SERVICE_HOST$HORIZON_APACHE_ROOT"
Jesse Andrews24859062011-09-15 21:28:23 -07001459fi
1460
Dean Troyerdf0972c2012-03-07 17:31:03 -06001461# If Keystone is present you can point ``nova`` cli to this server
Dean Troyer5ce44cd2015-02-12 22:18:33 -06001462if is_service_enabled keystone; then
Dean Troyerdc97cb72015-03-28 08:20:50 -05001463 echo "Keystone is serving at $KEYSTONE_SERVICE_URI/"
Dean Troyerdf0972c2012-03-07 17:31:03 -06001464 echo "The default users are: admin and demo"
1465 echo "The password: $ADMIN_PASSWORD"
Jesse Andrews24859062011-09-15 21:28:23 -07001466fi
termie523c4052011-09-28 19:49:40 -05001467
Dean Troyerafc29fe2013-02-07 15:56:24 -06001468# Warn that a deprecated feature was used
1469if [[ -n "$DEPRECATED_TEXT" ]]; then
1470 echo_summary "WARNING: $DEPRECATED_TEXT"
Dean Troyerced65172012-03-02 16:36:16 -06001471fi
1472
Dean Troyer4a43b7b2012-08-28 17:43:40 -05001473# Indicate how long this took to run (bash maintained variable ``SECONDS``)
Dean Troyer7903b792012-09-13 17:16:12 -05001474echo_summary "stack.sh completed in $SECONDS seconds."
Dean Troyer80684552014-03-05 11:50:23 -06001475
1476# Restore/close logging file descriptors
1477exec 1>&3
1478exec 2>&3
1479exec 3>&-
1480exec 6>&-