blob: 07b323bf3f005d47801a880875ff700452cf44c0 [file] [log] [blame]
Jesse Andrewsba23cc72011-09-11 03:22:13 -07001#!/usr/bin/env bash
2
Jesse Andrews5e2fc412011-09-18 21:16:42 -07003# **stack.sh** is an opinionated openstack dev installation.
Jesse Andrewsba23cc72011-09-11 03:22:13 -07004
Jesse Andrewsc4b3aab2011-09-15 22:54:52 -07005# To keep this script simple we assume you are running on an **Ubuntu 11.04
Jesse Andrews24859062011-09-15 21:28:23 -07006# Natty** machine. It should work in a VM or physical server. Additionally we
7# put the list of *apt* and *pip* dependencies and other configuration files in
8# this repo. So start by grabbing this script and the dependencies.
9
root40a37002011-09-20 18:06:14 +000010# You can grab the most recent version of this script and files from Rackspace
Jesse Andrews5e2fc412011-09-18 21:16:42 -070011# Cloud Builders at https://github.com/cloudbuilders/devstack
Jesse Andrews6edd17f2011-09-15 22:19:42 -070012
13# Sanity Check
14# ============
15
termie523c4052011-09-28 19:49:40 -050016# Start our timer
17START_TIME=`python -c "import time; print time.time()"`
18
Jesse Andrewsc4b3aab2011-09-15 22:54:52 -070019# Warn users who aren't on natty, but allow them to override check and attempt
Jesse Andrews6edd17f2011-09-15 22:19:42 -070020# installation with ``FORCE=yes ./stack``
Jesse Andrews6edd17f2011-09-15 22:19:42 -070021if ! grep -q natty /etc/lsb-release; then
22 echo "WARNING: this script has only been tested on natty"
23 if [[ "$FORCE" != "yes" ]]; then
24 echo "If you wish to run this script anyway run with FORCE=yes"
25 exit 1
26 fi
27fi
28
root40a37002011-09-20 18:06:14 +000029# stack.sh keeps the list of **apt** and **pip** dependencies in external
Jesse Andrews4d282182011-09-16 11:27:43 -070030# files, along with config templates and other useful files. You can find these
root40a37002011-09-20 18:06:14 +000031# in the ``files`` directory (next to this script). We will reference this
Jesse Andrewsbf3868d2011-09-16 11:31:16 -070032# directory using the ``FILES`` variable in this script.
33FILES=`pwd`/files
34if [ ! -d $FILES ]; then
35 echo "ERROR: missing devstack/files - did you grab more than just stack.sh?"
Jesse Andrews6edd17f2011-09-15 22:19:42 -070036 exit 1
37fi
38
Vishvananda Ishayac9e3fff2011-09-29 10:48:49 -070039# If stack.sh is run as root, it automatically creates a stack user with
40# sudo privileges and runs as that user.
Jesse Andrewsd4622952011-09-28 14:08:26 -070041if [[ $EUID -eq 0 ]]; then
Vishvananda Ishayac9e3fff2011-09-29 10:48:49 -070042 echo "You are running this script as root."
43 apt-get update
44 apt-get install -y sudo
45 if ! getent passwd | grep -q stack; then
46 echo "Creating a user called stack"
Vishvananda Ishayacd101642011-10-01 00:37:27 -070047 useradd -U -G sudo -s /bin/bash -m stack
Vishvananda Ishayac9e3fff2011-09-29 10:48:49 -070048 fi
49 echo "Making sure stack has passwordless sudo"
Jesse Andrews6e9fae02011-10-02 08:48:34 -070050 echo "stack ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
Vishvananda Ishayac9e3fff2011-09-29 10:48:49 -070051 echo "Copying files to stack user"
52 cp -r -f `pwd` /home/stack/
53 THIS_DIR=$(basename $(dirname $(readlink -f $0)))
54 chown -R stack:sudo /home/stack/$THIS_DIR
55 echo "Running the script as stack in 3 seconds..."
56 sleep 3
57 exec su -c "cd /home/stack/$THIS_DIR/; bash stack.sh; bash" stack
58 exit 0
Jesse Andrewsd4622952011-09-28 14:08:26 -070059fi
60
61
Jesse Andrews6edd17f2011-09-15 22:19:42 -070062# Settings
63# ========
Jesse Andrews30f68e92011-09-13 00:59:54 -070064
Jesse Andrewsd74257d2011-09-13 01:24:50 -070065# This script is customizable through setting environment variables. If you
66# want to override a setting you can either::
67#
68# export MYSQL_PASS=anothersecret
69# ./stack.sh
70#
Jesse Andrews6edd17f2011-09-15 22:19:42 -070071# You can also pass options on a single line ``MYSQL_PASS=simple ./stack.sh``
72#
termie197d53d2011-09-28 17:18:23 -070073# Additionally, you can put any local variables into a ``localrc`` file, like::
74#
75# MYSQL_PASS=anothersecret
76# MYSQL_USER=hellaroot
77#
Jesse Andrews6edd17f2011-09-15 22:19:42 -070078# We try to have sensible defaults, so you should be able to run ``./stack.sh``
79# in most cases.
Jesse Andrewsd74257d2011-09-13 01:24:50 -070080
Jesse Andrews6edd17f2011-09-15 22:19:42 -070081# So that errors don't compound we exit on any errors so you see only the
82# first error that occured.
Jesse Andrewsba23cc72011-09-11 03:22:13 -070083set -o errexit
84
root40a37002011-09-20 18:06:14 +000085# Print the commands being run so that we can see the command that triggers
Jesse Andrewsd74257d2011-09-13 01:24:50 -070086# an error. It is also useful for following allowing as the install occurs.
Jesse Andrewsba23cc72011-09-11 03:22:13 -070087set -o xtrace
88
Anthony Young2f140202011-09-26 13:02:40 -070089# Import variables
90source ./stackrc
91
Jesse Andrews6edd17f2011-09-15 22:19:42 -070092# Destination path for installation ``DEST``
Anthony Younge8fed482011-09-26 19:50:43 -070093DEST=${DEST:-/opt/stack}
94sudo mkdir -p $DEST
95sudo chown `whoami` $DEST
Jesse Andrewsba23cc72011-09-11 03:22:13 -070096
Jesse Andrews6f3baaf2011-09-12 11:59:38 -070097# Set the destination directories for openstack projects
Jesse Andrewsba23cc72011-09-11 03:22:13 -070098NOVA_DIR=$DEST/nova
99DASH_DIR=$DEST/dash
100GLANCE_DIR=$DEST/glance
101KEYSTONE_DIR=$DEST/keystone
102NOVACLIENT_DIR=$DEST/python-novaclient
Anthony Young2f140202011-09-26 13:02:40 -0700103OPENSTACKX_DIR=$DEST/openstackx
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700104NOVNC_DIR=$DEST/noVNC
Anthony Younga8416442011-09-13 20:07:44 -0700105
106# Specify which services to launch. These generally correspond to screen tabs
Jesse Andrews9b6741e2011-10-02 10:01:00 -0700107ENABLED_SERVICES=${ENABLED_SERVICES:-g-api,g-reg,key,n-api,n-cpu,n-net,n-sch,n-vnc,dash,mysql,rabbit}
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700108
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700109# Use the first IP unless an explicit is set by ``HOST_IP`` environment variable
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700110if [ ! -n "$HOST_IP" ]; then
Dean Troyer2a15a7c2011-09-13 13:22:14 -0500111 HOST_IP=`LC_ALL=C /sbin/ifconfig | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700112fi
113
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700114# Nova network configuration
Anthony Youngb1bdd5e2011-09-20 09:39:50 -0700115PUBLIC_INTERFACE=${PUBLIC_INTERFACE:-eth0}
Jesse Andrews8ff5dbc2011-09-25 22:28:08 -0700116VLAN_INTERFACE=${VLAN_INTERFACE:-$PUBLIC_INTERFACE}
Jesse Andrewsa72f7ad2011-09-25 13:41:22 -0700117FLOATING_RANGE=${FLOATING_RANGE:-172.24.4.1/28}
Jesse Andrewsb5197e42011-09-26 12:48:31 -0700118FIXED_RANGE=${FIXED_RANGE:-10.0.0.0/24}
119FIXED_NETWORK_SIZE=${FIXED_NETWORK_SIZE:-256}
Jesse Andrewsa72f7ad2011-09-25 13:41:22 -0700120NET_MAN=${NET_MAN:-FlatDHCPManager}
Anthony Younga8416442011-09-13 20:07:44 -0700121EC2_DMZ_HOST=${EC2_DMZ_HOST:-$HOST_IP}
Anthony Youngb1bdd5e2011-09-20 09:39:50 -0700122FLAT_NETWORK_BRIDGE=${FLAT_NETWORK_BRIDGE:-br100}
Jesse Andrews8ff5dbc2011-09-25 22:28:08 -0700123SCHEDULER=${SCHEDULER:-nova.scheduler.simple.SimpleScheduler}
Jesse Andrews30f68e92011-09-13 00:59:54 -0700124
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700125# If you are using FlatDHCP on multiple hosts, set the ``FLAT_INTERFACE``
126# variable but make sure that the interface doesn't already have an
127# ip or you risk breaking things.
Jesse Andrews8ff5dbc2011-09-25 22:28:08 -0700128FLAT_INTERFACE=${FLAT_INTERFACE:-eth0}
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700129
root40a37002011-09-20 18:06:14 +0000130# Nova hypervisor configuration. We default to **kvm** but will drop back to
Jesse Andrewsd1879c52011-09-16 16:28:13 -0700131# **qemu** if we are unable to load the kvm module.
132LIBVIRT_TYPE=${LIBVIRT_TYPE:-kvm}
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700133
Anthony Younga8416442011-09-13 20:07:44 -0700134# Mysql connection info
Anthony Young320412b2011-09-14 02:39:10 -0700135MYSQL_USER=${MYSQL_USER:-root}
Jesse Andrewsfa418f62011-10-02 09:30:54 -0700136MYSQL_PASS=${MYSQL_PASS:-`openssl rand -hex 12`}
Anthony Younga8416442011-09-13 20:07:44 -0700137MYSQL_HOST=${MYSQL_HOST:-localhost}
138# don't specify /db in this string, so we can use it for multiple services
Anthony Youngfdaf21a2011-09-13 20:11:42 -0700139BASE_SQL_CONN=${BASE_SQL_CONN:-mysql://$MYSQL_USER:$MYSQL_PASS@$MYSQL_HOST}
Anthony Younga8416442011-09-13 20:07:44 -0700140
141# Rabbit connection info
142RABBIT_HOST=${RABBIT_HOST:-localhost}
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700143
Anthony Young377aae62011-09-14 09:55:31 -0700144# Glance connection info. Note the port must be specified.
Anthony Youngb1bdd5e2011-09-20 09:39:50 -0700145GLANCE_HOSTPORT=${GLANCE_HOSTPORT:-$HOST_IP:9292}
Anthony Young377aae62011-09-14 09:55:31 -0700146
Jesse Andrewsb96871e2011-10-02 09:02:46 -0700147# Service Token - Openstack components need to have an admin token
148# to validate user tokens.
149SERVICE_TOKEN=${SERVICE_TOKEN:-`uuidgen`}
Jesse Andrews89358af2011-10-02 14:11:17 -0400150ADMIN_PASSWORD=${ADMIN_PASSWORD:-`openssl rand -hex 12`}
Jesse Andrewsb96871e2011-10-02 09:02:46 -0700151
Jesse Andrews30f68e92011-09-13 00:59:54 -0700152# Install Packages
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700153# ================
Jesse Andrews30f68e92011-09-13 00:59:54 -0700154#
155# Openstack uses a fair number of other projects.
156
root40a37002011-09-20 18:06:14 +0000157# Seed configuration with mysql password so that apt-get install doesn't
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700158# prompt us for a password upon install.
Jesse Andrews18d350d2011-09-12 21:46:12 -0700159cat <<MYSQL_PRESEED | sudo debconf-set-selections
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700160mysql-server-5.1 mysql-server/root_password password $MYSQL_PASS
161mysql-server-5.1 mysql-server/root_password_again password $MYSQL_PASS
162mysql-server-5.1 mysql-server/start_on_boot boolean true
163MYSQL_PRESEED
Jesse Andrews2caf8fd2011-09-12 16:15:11 -0700164
Jesse Andrews75a37652011-09-12 17:09:08 -0700165# install apt requirements
Jesse Andrewsbf3868d2011-09-16 11:31:16 -0700166sudo apt-get install -y -q `cat $FILES/apts/* | cut -d\# -f1 | grep -Ev "mysql-server|rabbitmq-server"`
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700167
Jesse Andrews75a37652011-09-12 17:09:08 -0700168# install python requirements
Jesse Andrewsbf3868d2011-09-16 11:31:16 -0700169sudo PIP_DOWNLOAD_CACHE=/var/cache/pip pip install `cat $FILES/pips/*`
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700170
Jesse Andrewsd61db852011-09-16 14:13:17 -0700171# git clone only if directory doesn't exist already. Since ``DEST`` might not
172# be owned by the installation user, we create the directory and change the
173# ownership to the proper user.
Jesse Andrews61632572011-09-12 17:40:00 -0700174function git_clone {
175 if [ ! -d $2 ]; then
Jesse Andrewsd61db852011-09-16 14:13:17 -0700176 sudo mkdir $2
177 sudo chown `whoami` $2
Jesse Andrews61632572011-09-12 17:40:00 -0700178 git clone $1 $2
Anthony Young2f140202011-09-26 13:02:40 -0700179 cd $2
Anthony Young303233e2011-09-26 13:12:57 -0700180 # This checkout syntax works for both branches and tags
Anthony Young2f140202011-09-26 13:02:40 -0700181 git checkout $3
Jesse Andrews61632572011-09-12 17:40:00 -0700182 fi
183}
184
Jesse Andrews75a37652011-09-12 17:09:08 -0700185# compute service
Anthony Young2f140202011-09-26 13:02:40 -0700186git_clone $NOVA_REPO $NOVA_DIR $NOVA_BRANCH
Jesse Andrews75a37652011-09-12 17:09:08 -0700187# image catalog service
Anthony Young2f140202011-09-26 13:02:40 -0700188git_clone $GLANCE_REPO $GLANCE_DIR $GLANCE_BRANCH
Jesse Andrews75a37652011-09-12 17:09:08 -0700189# unified auth system (manages accounts/tokens)
Anthony Young2f140202011-09-26 13:02:40 -0700190git_clone $KEYSTONE_REPO $KEYSTONE_DIR $KEYSTONE_BRANCH
Jesse Andrews75a37652011-09-12 17:09:08 -0700191# a websockets/html5 or flash powered VNC console for vm instances
Anthony Young2f140202011-09-26 13:02:40 -0700192git_clone $NOVNC_REPO $NOVNC_DIR $NOVNC_BRANCH
Jesse Andrews75a37652011-09-12 17:09:08 -0700193# django powered web control panel for openstack
Anthony Young2f140202011-09-26 13:02:40 -0700194git_clone $DASH_REPO $DASH_DIR $DASH_BRANCH $DASH_TAG
Jesse Andrews75a37652011-09-12 17:09:08 -0700195# python client library to nova that dashboard (and others) use
Anthony Young2f140202011-09-26 13:02:40 -0700196git_clone $NOVACLIENT_REPO $NOVACLIENT_DIR $NOVACLIENT_BRANCH
root40a37002011-09-20 18:06:14 +0000197# openstackx is a collection of extensions to openstack.compute & nova
Jesse Andrews75a37652011-09-12 17:09:08 -0700198# that is *deprecated*. The code is being moved into python-novaclient & nova.
Anthony Young2f140202011-09-26 13:02:40 -0700199git_clone $OPENSTACKX_REPO $OPENSTACKX_DIR $OPENSTACKX_BRANCH
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700200
Jesse Andrews30f68e92011-09-13 00:59:54 -0700201# Initialization
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700202# ==============
Jesse Andrews30f68e92011-09-13 00:59:54 -0700203
Jesse Andrewsd1879c52011-09-16 16:28:13 -0700204
Jesse Andrews75a37652011-09-12 17:09:08 -0700205# setup our checkouts so they are installed into python path
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700206# allowing ``import nova`` or ``import glance.client``
Dean Troyer0017c8f2011-09-13 15:37:50 -0500207cd $NOVA_DIR; sudo python setup.py develop
Jesse Andrews18d350d2011-09-12 21:46:12 -0700208cd $NOVACLIENT_DIR; sudo python setup.py develop
209cd $KEYSTONE_DIR; sudo python setup.py develop
210cd $GLANCE_DIR; sudo python setup.py develop
Anthony Young2f140202011-09-26 13:02:40 -0700211cd $OPENSTACKX_DIR; sudo python setup.py develop
Jesse Andrews18d350d2011-09-12 21:46:12 -0700212cd $DASH_DIR/django-openstack; sudo python setup.py develop
213cd $DASH_DIR/openstack-dashboard; sudo python setup.py develop
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700214
Jesse Andrews6edd17f2011-09-15 22:19:42 -0700215# Add a useful screenrc. This isn't required to run openstack but is we do
root40a37002011-09-20 18:06:14 +0000216# it since we are going to run the services in screen for simple
Jesse Andrewsbf3868d2011-09-16 11:31:16 -0700217cp $FILES/screenrc ~/.screenrc
Jesse Andrews6f3baaf2011-09-12 11:59:38 -0700218
Jesse Andrews6edd17f2011-09-15 22:19:42 -0700219## TODO: update current user to allow sudo for all commands in files/sudo/*
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700220
Anthony Younga09ae2f2011-09-15 23:11:29 -0700221# Rabbit
222# ---------
223#
224if [[ "$ENABLED_SERVICES" =~ "rabbit" ]]; then
225 # Install and start rabbitmq-server
Anthony Young093eeb02011-09-15 23:17:44 -0700226 sudo apt-get install -y -q rabbitmq-server
Anthony Younga09ae2f2011-09-15 23:11:29 -0700227fi
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700228
Jesse Andrews24859062011-09-15 21:28:23 -0700229# Mysql
230# ---------
231#
232if [[ "$ENABLED_SERVICES" =~ "mysql" ]]; then
Anthony Younga09ae2f2011-09-15 23:11:29 -0700233 # Install and start mysql-server
Anthony Young093eeb02011-09-15 23:17:44 -0700234 sudo apt-get -y -q install mysql-server
Jesse Andrews24859062011-09-15 21:28:23 -0700235 # Update the DB to give user ‘$MYSQL_USER’@’%’ full control of the all databases:
236 sudo mysql -uroot -p$MYSQL_PASS -e "GRANT ALL PRIVILEGES ON *.* TO '$MYSQL_USER'@'%' identified by '$MYSQL_PASS';"
237
238 # Edit /etc/mysql/my.cnf to change ‘bind-address’ from localhost (127.0.0.1) to any (0.0.0.0) and restart the mysql service:
239 sudo sed -i 's/127.0.0.1/0.0.0.0/g' /etc/mysql/my.cnf
240 sudo service mysql restart
241fi
242
243
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700244# Dashboard
245# ---------
246#
247# Setup the django application to serve via apache/wsgi
Jesse Andrews75a37652011-09-12 17:09:08 -0700248
Anthony Young70dc5e02011-09-15 16:52:43 -0700249if [[ "$ENABLED_SERVICES" =~ "dash" ]]; then
Jesse Andrews24859062011-09-15 21:28:23 -0700250
root40a37002011-09-20 18:06:14 +0000251 # Dash currently imports quantum even if you aren't using it. Instead
252 # of installing quantum we can create a simple module that will pass the
Jesse Andrews24859062011-09-15 21:28:23 -0700253 # initial imports
Anthony Young70dc5e02011-09-15 16:52:43 -0700254 sudo mkdir -p $DASH_DIR/openstack-dashboard/quantum || true
255 sudo touch $DASH_DIR/openstack-dashboard/quantum/__init__.py
256 sudo touch $DASH_DIR/openstack-dashboard/quantum/client.py
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700257
Anthony Young70dc5e02011-09-15 16:52:43 -0700258 cd $DASH_DIR/openstack-dashboard
root40a37002011-09-20 18:06:14 +0000259
Jesse Andrewsbf3868d2011-09-16 11:31:16 -0700260 sudo cp $FILES/dash_settings.py local/local_settings.py
Jake Dahn9337b332011-09-15 21:46:20 -0700261
Anthony Young70dc5e02011-09-15 16:52:43 -0700262 dashboard/manage.py syncdb
Jesse Andrews75a37652011-09-12 17:09:08 -0700263
Anthony Young70dc5e02011-09-15 16:52:43 -0700264 # create an empty directory that apache uses as docroot
265 sudo mkdir -p $DASH_DIR/.blackhole
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700266
Anthony Young70dc5e02011-09-15 16:52:43 -0700267 ## Configure apache's 000-default to run dashboard
Jesse Andrewsbf3868d2011-09-16 11:31:16 -0700268 sudo cp $FILES/000-default.template /etc/apache2/sites-enabled/000-default
Jesse Andrews8f3e28c2011-09-27 18:26:27 -0700269 sudo sed -e "s,%USER%,$USER,g" -i /etc/apache2/sites-enabled/000-default
Anthony Young70dc5e02011-09-15 16:52:43 -0700270 sudo sed -e "s,%DASH_DIR%,$DASH_DIR,g" -i /etc/apache2/sites-enabled/000-default
Anthony Young70dc5e02011-09-15 16:52:43 -0700271fi
Jesse Andrews75a37652011-09-12 17:09:08 -0700272
Anthony Young3859f732011-09-14 02:33:43 -0700273
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700274# Glance
275# ------
276
Anthony Young70dc5e02011-09-15 16:52:43 -0700277if [[ "$ENABLED_SERVICES" =~ "g-reg" ]]; then
Anthony Youngc8357622011-09-20 10:38:06 -0700278 GLANCE_IMAGE_DIR=$DEST/glance/images
Anthony Younga531b772011-09-20 09:59:54 -0700279 # Delete existing images
280 rm -rf $GLANCE_IMAGE_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -0700281
Anthony Younga531b772011-09-20 09:59:54 -0700282 # Use local glance directories
283 mkdir -p $GLANCE_IMAGE_DIR
284
Anthony Young70dc5e02011-09-15 16:52:43 -0700285 # (re)create glance database
root40a37002011-09-20 18:06:14 +0000286 mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'DROP DATABASE IF EXISTS glance;'
Anthony Young70dc5e02011-09-15 16:52:43 -0700287 mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'CREATE DATABASE glance;'
288 # Copy over our glance-registry.conf
289 GLANCE_CONF=$GLANCE_DIR/etc/glance-registry.conf
Jesse Andrewsbf3868d2011-09-16 11:31:16 -0700290 cp $FILES/glance-registry.conf $GLANCE_CONF
Anthony Young70dc5e02011-09-15 16:52:43 -0700291 sudo sed -e "s,%SQL_CONN%,$BASE_SQL_CONN/glance,g" -i $GLANCE_CONF
Jesse Andrewsb96871e2011-10-02 09:02:46 -0700292 sudo sed -e "s,%SERVICE_TOKEN%,$SERVICE_TOKEN,g" -i $GLANCE_CONF
Anthony Younga531b772011-09-20 09:59:54 -0700293 sudo sed -e "s,%DEST%,$DEST,g" -i $GLANCE_CONF
Anthony Youngf12d3ab2011-09-20 00:33:51 -0700294
295 GLANCE_API_CONF=$GLANCE_DIR/etc/glance-api.conf
296 cp $FILES/glance-api.conf $GLANCE_API_CONF
Anthony Younga531b772011-09-20 09:59:54 -0700297 sudo sed -e "s,%DEST%,$DEST,g" -i $GLANCE_API_CONF
Jesse Andrewsb96871e2011-10-02 09:02:46 -0700298 sudo sed -e "s,%SERVICE_TOKEN%,$SERVICE_TOKEN,g" -i $GLANCE_API_CONF
Anthony Young70dc5e02011-09-15 16:52:43 -0700299fi
Jesse Andrews75a37652011-09-12 17:09:08 -0700300
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700301# Nova
302# ----
303
Jesse Andrews9f20f512011-10-02 09:18:03 -0700304sudo sed -e "s,999888777666,$SERVICE_TOKEN,g" -i $KEYSTONE_DIR/examples/paste/nova-api-paste.ini
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700305
Anthony Young70dc5e02011-09-15 16:52:43 -0700306if [[ "$ENABLED_SERVICES" =~ "n-cpu" ]]; then
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700307
root40a37002011-09-20 18:06:14 +0000308 # attempt to load modules: nbd (network block device - used to manage
309 # qcow images) and kvm (hardware based virtualization). If unable to
Jesse Andrewsd1879c52011-09-16 16:28:13 -0700310 # load kvm, set the libvirt type to qemu.
Anthony Young70dc5e02011-09-15 16:52:43 -0700311 sudo modprobe nbd || true
Jesse Andrewsc6d30422011-10-02 13:11:28 -0400312
313 if [[ "$LIBVIRT_TYPE" -eq "kvm" ]]; then
314 if [ ! -e /dev/kvm ]; then
315 LIBVIRT_TYPE=qemu
316 fi
Jesse Andrewsd1879c52011-09-16 16:28:13 -0700317 fi
Jesse Andrewsc6d30422011-10-02 13:11:28 -0400318
319 if [[ "$LIBVIRT_TYPE" -eq "lxc" ]]; then
Jesse Andrews8cfd8b62011-10-02 13:17:31 -0400320 sudo apt-get install lxc -y
Jesse Andrewsc6d30422011-10-02 13:11:28 -0400321 sudo mkdir -p /cgroup
322 sudo mount none -t cgroup -o cpuacct,memory,devices,cpu,freezer,blkio /cgroup
323 if ! grep -q cgroup /etc/fstab; then
Jesse Andrewsc315ebf2011-10-02 13:25:33 -0400324 echo none /cgroup cgroup cpuacct,memory,devices,cpu,freezer,blkio 0 0 | sudo tee -a /etc/fstab
Jesse Andrewsc6d30422011-10-02 13:11:28 -0400325 fi
326 fi
327
Jesse Andrewse30432f2011-09-16 14:54:48 -0700328 # User needs to be member of libvirtd group for nova-compute to use libvirt.
Anthony Young70dc5e02011-09-15 16:52:43 -0700329 sudo usermod -a -G libvirtd `whoami`
330 # if kvm wasn't running before we need to restart libvirt to enable it
331 sudo /etc/init.d/libvirt-bin restart
332
Anthony Young70dc5e02011-09-15 16:52:43 -0700333 # setup nova instance directory
334 mkdir -p $NOVA_DIR/instances
335
336 # if there is a partition labeled nova-instances use it (ext filesystems
337 # can be labeled via e2label)
338 ## FIXME: if already mounted this blows up...
339 if [ -L /dev/disk/by-label/nova-instances ]; then
340 sudo mount -L nova-instances $NOVA_DIR/instances
341 sudo chown -R `whoami` $NOVA_DIR/instances
342 fi
343
344 # Clean out the instances directory
345 rm -rf $NOVA_DIR/instances/*
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700346fi
347
Anthony Young70dc5e02011-09-15 16:52:43 -0700348if [[ "$ENABLED_SERVICES" =~ "n-net" ]]; then
349 # delete traces of nova networks from prior runs
Anthony Young09fde812011-09-20 02:23:54 -0700350 sudo killall dnsmasq || true
Anthony Young70dc5e02011-09-15 16:52:43 -0700351 rm -rf $NOVA_DIR/networks
352 mkdir -p $NOVA_DIR/networks
353fi
Jesse Andrews75a37652011-09-12 17:09:08 -0700354
Jesse Andrewsd1879c52011-09-16 16:28:13 -0700355function add_nova_flag {
356 echo "$1" >> $NOVA_DIR/bin/nova.conf
357}
358
359# (re)create nova.conf
360rm -f $NOVA_DIR/bin/nova.conf
361add_nova_flag "--verbose"
362add_nova_flag "--nodaemon"
Jesse Andrews8ff5dbc2011-09-25 22:28:08 -0700363add_nova_flag "--scheduler_driver=$SCHEDULER"
Jesse Andrewsd1879c52011-09-16 16:28:13 -0700364add_nova_flag "--dhcpbridge_flagfile=$NOVA_DIR/bin/nova.conf"
365add_nova_flag "--network_manager=nova.network.manager.$NET_MAN"
366add_nova_flag "--my_ip=$HOST_IP"
Anthony Youngb1bdd5e2011-09-20 09:39:50 -0700367add_nova_flag "--public_interface=$PUBLIC_INTERFACE"
368add_nova_flag "--vlan_interface=$VLAN_INTERFACE"
Jesse Andrewsd1879c52011-09-16 16:28:13 -0700369add_nova_flag "--sql_connection=$BASE_SQL_CONN/nova"
370add_nova_flag "--libvirt_type=$LIBVIRT_TYPE"
Anthony Young2f140202011-09-26 13:02:40 -0700371add_nova_flag "--osapi_extensions_path=$OPENSTACKX_DIR/extensions"
Jesse Andrewsd1879c52011-09-16 16:28:13 -0700372add_nova_flag "--vncproxy_url=http://$HOST_IP:6080"
373add_nova_flag "--vncproxy_wwwroot=$NOVNC_DIR/"
374add_nova_flag "--api_paste_config=$KEYSTONE_DIR/examples/paste/nova-api-paste.ini"
375add_nova_flag "--image_service=nova.image.glance.GlanceImageService"
376add_nova_flag "--ec2_dmz_host=$EC2_DMZ_HOST"
377add_nova_flag "--rabbit_host=$RABBIT_HOST"
378add_nova_flag "--glance_api_servers=$GLANCE_HOSTPORT"
Anthony Youngb1bdd5e2011-09-20 09:39:50 -0700379add_nova_flag "--flat_network_bridge=$FLAT_NETWORK_BRIDGE"
Jesse Andrewsd1879c52011-09-16 16:28:13 -0700380if [ -n "$FLAT_INTERFACE" ]; then
381 add_nova_flag "--flat_interface=$FLAT_INTERFACE"
382fi
383if [ -n "$MULTI_HOST" ]; then
384 add_nova_flag "--multi_host=$MULTI_HOST"
385fi
386
Anthony Younga0748002011-09-16 21:37:36 -0700387if [[ "$ENABLED_SERVICES" =~ "mysql" ]]; then
388 # (re)create nova database
root40a37002011-09-20 18:06:14 +0000389 mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'DROP DATABASE IF EXISTS nova;'
Anthony Younga0748002011-09-16 21:37:36 -0700390 mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'CREATE DATABASE nova;'
391 $NOVA_DIR/bin/nova-manage db sync
392
393 # create a small network
termie197d53d2011-09-28 17:18:23 -0700394 $NOVA_DIR/bin/nova-manage network create private $FIXED_RANGE 1 $FIXED_NETWORK_SIZE
Anthony Younga0748002011-09-16 21:37:36 -0700395
396 # create some floating ips
397 $NOVA_DIR/bin/nova-manage floating create $FLOATING_RANGE
398fi
399
400
Jesse Andrewse8d9cd82011-09-13 15:16:26 -0700401# Keystone
402# --------
403
Anthony Young70dc5e02011-09-15 16:52:43 -0700404if [[ "$ENABLED_SERVICES" =~ "key" ]]; then
405 # (re)create keystone database
root40a37002011-09-20 18:06:14 +0000406 mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'DROP DATABASE IF EXISTS keystone;'
Anthony Young70dc5e02011-09-15 16:52:43 -0700407 mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'CREATE DATABASE keystone;'
Jesse Andrews75a37652011-09-12 17:09:08 -0700408
Anthony Young70dc5e02011-09-15 16:52:43 -0700409 # FIXME (anthony) keystone should use keystone.conf.example
410 KEYSTONE_CONF=$KEYSTONE_DIR/etc/keystone.conf
Jesse Andrewsbf3868d2011-09-16 11:31:16 -0700411 cp $FILES/keystone.conf $KEYSTONE_CONF
Anthony Young70dc5e02011-09-15 16:52:43 -0700412 sudo sed -e "s,%SQL_CONN%,$BASE_SQL_CONN/keystone,g" -i $KEYSTONE_CONF
Anthony Younge8fed482011-09-26 19:50:43 -0700413 sudo sed -e "s,%DEST%,$DEST,g" -i $KEYSTONE_CONF
Anthony Young3a093122011-09-13 19:01:45 +0000414
Anthony Youngec21d932011-09-16 16:05:55 -0700415 KEYSTONE_DATA=$KEYSTONE_DIR/bin/keystone_data.sh
416 cp $FILES/keystone_data.sh $KEYSTONE_DATA
417 sudo sed -e "s,%HOST_IP%,$HOST_IP,g" -i $KEYSTONE_DATA
Jesse Andrewsb96871e2011-10-02 09:02:46 -0700418 sudo sed -e "s,%SERVICE_TOKEN%,$SERVICE_TOKEN,g" -i $KEYSTONE_DATA
Jesse Andrews89358af2011-10-02 14:11:17 -0400419 sudo sed -e "s,%ADMIN_PASSWORD%,$ADMIN_PASSWORD,g" -i $KEYSTONE_DATA
Anthony Young70dc5e02011-09-15 16:52:43 -0700420 # initialize keystone with default users/endpoints
Anthony Youngec21d932011-09-16 16:05:55 -0700421 BIN_DIR=$KEYSTONE_DIR/bin bash $KEYSTONE_DATA
Anthony Young70dc5e02011-09-15 16:52:43 -0700422fi
Jesse Andrews75a37652011-09-12 17:09:08 -0700423
Jesse Andrews75a37652011-09-12 17:09:08 -0700424
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700425# Launch Services
426# ===============
Jesse Andrews30f68e92011-09-13 00:59:54 -0700427
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700428# nova api crashes if we start it with a regular screen command,
429# so send the start command by forcing text into the window.
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700430# Only run the services specified in ``ENABLED_SERVICES``
431
Jesse Andrews1f717602011-09-16 15:18:53 -0700432# our screen helper to launch a service in a hidden named screen
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700433function screen_it {
Jesse Andrews1f717602011-09-16 15:18:53 -0700434 NL=`echo -ne '\015'`
Anthony Young292e46d2011-09-13 11:28:56 -0700435 if [[ "$ENABLED_SERVICES" =~ "$1" ]]; then
436 screen -S nova -X screen -t $1
437 screen -S nova -p $1 -X stuff "$2$NL"
438 fi
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700439}
440
Jesse Andrewsa16e5e92011-09-16 16:30:55 -0700441# create a new named screen to run processes in
442screen -d -m -S nova -t nova
443sleep 1
444
Anthony Youngd000b222011-09-19 14:46:53 -0700445if [[ "$ENABLED_SERVICES" =~ "g-reg" ]]; then
446 screen_it g-reg "cd $GLANCE_DIR; bin/glance-registry --config-file=etc/glance-registry.conf"
447fi
448
449if [[ "$ENABLED_SERVICES" =~ "g-api" ]]; then
450 screen_it g-api "cd $GLANCE_DIR; bin/glance-api --config-file=etc/glance-api.conf"
451 while ! wget -q -O- http://$GLANCE_HOSTPORT; do
452 echo "Waiting for g-api ($GLANCE_HOSTPORT) to start..."
453 sleep 1
454 done
455fi
456
457if [[ "$ENABLED_SERVICES" =~ "key" ]]; then
Anthony Youngf33796e2011-09-22 00:14:12 -0700458 screen_it key "cd $KEYSTONE_DIR && $KEYSTONE_DIR/bin/keystone --config-file $KEYSTONE_CONF -d"
Anthony Youngd000b222011-09-19 14:46:53 -0700459 while ! wget -q -O- http://127.0.0.1:5000; do
460 echo "Waiting for keystone to start..."
461 sleep 1
462 done
463fi
464
465if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then
Anthony Young9bf3d762011-09-20 09:51:16 -0700466 screen_it n-api "cd $NOVA_DIR && $NOVA_DIR/bin/nova-api"
Anthony Youngd000b222011-09-19 14:46:53 -0700467 while ! wget -q -O- http://127.0.0.1:8774; do
468 echo "Waiting for nova-api to start..."
469 sleep 1
470 done
471fi
root40a37002011-09-20 18:06:14 +0000472# Launching nova-compute should be as simple as running ``nova-compute`` but
473# have to do a little more than that in our script. Since we add the group
Jesse Andrews1f717602011-09-16 15:18:53 -0700474# ``libvirtd`` to our user in this script, when nova-compute is run it is
root40a37002011-09-20 18:06:14 +0000475# within the context of our original shell (so our groups won't be updated).
Jesse Andrews1f717602011-09-16 15:18:53 -0700476# We can send the command nova-compute to the ``newgrp`` command to execute
477# in a specific context.
Anthony Young9bf3d762011-09-20 09:51:16 -0700478screen_it n-cpu "cd $NOVA_DIR && echo $NOVA_DIR/bin/nova-compute | newgrp libvirtd"
479screen_it n-net "cd $NOVA_DIR && $NOVA_DIR/bin/nova-network"
480screen_it n-sch "cd $NOVA_DIR && $NOVA_DIR/bin/nova-scheduler"
Anthony Young527e3412011-09-27 15:05:37 -0700481screen_it n-vnc "cd $NOVNC_DIR && ./utils/nova-wsproxy.py 6080 --web ."
Anthony Young9bf3d762011-09-20 09:51:16 -0700482screen_it dash "cd $DASH_DIR && sudo /etc/init.d/apache2 restart; sudo tail -f /var/log/apache2/error.log"
Jesse Andrews75a37652011-09-12 17:09:08 -0700483
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700484# Install Images
485# ==============
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700486
Anthony Young70dc5e02011-09-15 16:52:43 -0700487if [[ "$ENABLED_SERVICES" =~ "g-reg" ]]; then
root40a37002011-09-20 18:06:14 +0000488 # Downloads a tty image (ami/aki/ari style), then extracts it. Upon extraction
Anthony Young70dc5e02011-09-15 16:52:43 -0700489 # we upload to glance with the glance cli tool.
Jesse Andrews543d7d42011-09-16 14:16:36 -0700490 if [ ! -f $FILES/tty.tgz ]; then
491 wget -c http://images.ansolabs.com/tty.tgz -O $FILES/tty.tgz
Anthony Young70dc5e02011-09-15 16:52:43 -0700492 fi
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700493
Anthony Young70dc5e02011-09-15 16:52:43 -0700494 # extract ami-tty/image, aki-tty/image & ari-tty/image
Jesse Andrews543d7d42011-09-16 14:16:36 -0700495 mkdir -p $FILES/images
Jesse Andrews74e965f2011-09-16 14:19:46 -0700496 tar -zxf $FILES/tty.tgz -C $FILES/images
Anthony Young70dc5e02011-09-15 16:52:43 -0700497
root40a37002011-09-20 18:06:14 +0000498 # add images to glance
Anthony Young70dc5e02011-09-15 16:52:43 -0700499 # FIXME: kernel/ramdisk is hardcoded - use return result from add
Jesse Andrewsb96871e2011-10-02 09:02:46 -0700500 glance add -A $SERVICE_TOKEN name="tty-kernel" is_public=true container_format=aki disk_format=aki < $FILES/images/aki-tty/image
501 glance add -A $SERVICE_TOKEN name="tty-ramdisk" is_public=true container_format=ari disk_format=ari < $FILES/images/ari-tty/image
502 glance add -A $SERVICE_TOKEN name="tty" is_public=true container_format=ami disk_format=ami kernel_id=1 ramdisk_id=2 < $FILES/images/ami-tty/image
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700503fi
Jesse Andrews24859062011-09-15 21:28:23 -0700504
505# Using the cloud
506# ===============
507
508# If you installed the dashboard on this server, then you should be able
root40a37002011-09-20 18:06:14 +0000509# to access the site using your browser.
Jesse Andrews24859062011-09-15 21:28:23 -0700510if [[ "$ENABLED_SERVICES" =~ "dash" ]]; then
511 echo "dashboard is now available at http://$HOST_IP/"
512fi
513
514# If keystone is present, you can point nova cli to this server
515if [[ "$ENABLED_SERVICES" =~ "key" ]]; then
516 echo "keystone is serving at http://$HOST_IP:5000/v2.0/"
517 echo "examples on using novaclient command line is in exercise.sh"
Jesse Andrews89358af2011-10-02 14:11:17 -0400518 echo "the default users are: admin and demo"
519 echo "the password: $ADMIN_PASSWORD"
Jesse Andrews24859062011-09-15 21:28:23 -0700520fi
termie523c4052011-09-28 19:49:40 -0500521
522# Summary
523# =======
524
525# End our timer and give a timing summary
526END_TIME=`python -c "import time; print time.time()"`
527ELAPSED=`python -c "print $END_TIME - $START_TIME"`
528echo "stack.sh completed in $ELAPSED seconds."