blob: 3cdc27bfe4dbede4817162f75fa164ed19fd13d0 [file] [log] [blame]
Jesse Andrewsba23cc72011-09-11 03:22:13 -07001#!/usr/bin/env bash
2
Jesse Andrews6f3baaf2011-09-12 11:59:38 -07003# **stack.sh** is rackspace cloudbuilder's opinionated openstack dev installation.
Jesse Andrewsba23cc72011-09-11 03:22:13 -07004
Jesse Andrews30f68e92011-09-13 00:59:54 -07005# Settings/Options
Jesse Andrewsd74257d2011-09-13 01:24:50 -07006# ================
Jesse Andrews30f68e92011-09-13 00:59:54 -07007
Jesse Andrewsd74257d2011-09-13 01:24:50 -07008# This script is customizable through setting environment variables. If you
9# want to override a setting you can either::
10#
11# export MYSQL_PASS=anothersecret
12# ./stack.sh
13#
14# or run on a single line ``MYSQL_PASS=simple ./stack.sh``
15
16# This script exits on an error so that errors don't compound and you see
17# only the first error that occured.
Jesse Andrewsba23cc72011-09-11 03:22:13 -070018set -o errexit
19
Jesse Andrewsd74257d2011-09-13 01:24:50 -070020# Print the commands being run so that we can see the command that triggers
21# an error. It is also useful for following allowing as the install occurs.
Jesse Andrewsba23cc72011-09-11 03:22:13 -070022set -o xtrace
23
Jesse Andrewsd74257d2011-09-13 01:24:50 -070024# Important paths: ``DIR`` is where we are executing from and ``DEST`` is
25# where we are installing openstack.
Jesse Andrewsba23cc72011-09-11 03:22:13 -070026DIR=`pwd`
27DEST=/opt
Jesse Andrewsba23cc72011-09-11 03:22:13 -070028
Jesse Andrews6f3baaf2011-09-12 11:59:38 -070029# Set the destination directories for openstack projects
Jesse Andrewsba23cc72011-09-11 03:22:13 -070030NOVA_DIR=$DEST/nova
31DASH_DIR=$DEST/dash
32GLANCE_DIR=$DEST/glance
33KEYSTONE_DIR=$DEST/keystone
34NOVACLIENT_DIR=$DEST/python-novaclient
35API_DIR=$DEST/openstackx
36NOVNC_DIR=$DEST/noVNC
37
Jesse Andrewsd74257d2011-09-13 01:24:50 -070038# Use the first IP unless an explicit is set by ``HOST_IP`` environment variable
Jesse Andrewsba23cc72011-09-11 03:22:13 -070039if [ ! -n "$HOST_IP" ]; then
40 HOST_IP=`LC_ALL=C ifconfig | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
41fi
42
Jesse Andrewsd74257d2011-09-13 01:24:50 -070043# Nova network configuration
Jesse Andrewsba23cc72011-09-11 03:22:13 -070044INTERFACE=${INTERFACE:-eth0}
45FLOATING_RANGE=${FLOATING_RANGE:-10.6.0.0/27}
46FIXED_RANGE=${FIXED_RANGE:-10.0.0.0/24}
Jesse Andrewsba23cc72011-09-11 03:22:13 -070047NET_MAN=${NET_MAN:-VlanManager}
Jesse Andrews30f68e92011-09-13 00:59:54 -070048
Jesse Andrewsd74257d2011-09-13 01:24:50 -070049# If you are using FlatDHCP on multiple hosts, set the ``FLAT_INTERFACE``
50# variable but make sure that the interface doesn't already have an
51# ip or you risk breaking things.
Jesse Andrewsba23cc72011-09-11 03:22:13 -070052# FLAT_INTERFACE=eth0
53
Jesse Andrewsd74257d2011-09-13 01:24:50 -070054# Nova hypervisor configuration
55LIBVIRT_TYPE=${LIBVIRT_TYPE:-qemu}
56
57
Jesse Andrews2caf8fd2011-09-12 16:15:11 -070058# TODO: switch to mysql for all services
Jesse Andrews1c1d1502011-09-12 19:29:56 -070059MYSQL_PASS=${MYSQL_PASS:-nova}
60SQL_CONN=${SQL_CONN:-mysql://root:$MYSQL_PASS@localhost/nova}
61# TODO: set rabbitmq conn string explicitly as well
Jesse Andrewsba23cc72011-09-11 03:22:13 -070062
Jesse Andrews30f68e92011-09-13 00:59:54 -070063# Install Packages
Jesse Andrewsd74257d2011-09-13 01:24:50 -070064# ================
Jesse Andrews30f68e92011-09-13 00:59:54 -070065#
66# Openstack uses a fair number of other projects.
67
Jesse Andrewsd74257d2011-09-13 01:24:50 -070068# Seed configuration with mysql password so that apt-get install doesn't
69# prompt us for a password upon install.
Jesse Andrews18d350d2011-09-12 21:46:12 -070070cat <<MYSQL_PRESEED | sudo debconf-set-selections
Jesse Andrews1c1d1502011-09-12 19:29:56 -070071mysql-server-5.1 mysql-server/root_password password $MYSQL_PASS
72mysql-server-5.1 mysql-server/root_password_again password $MYSQL_PASS
73mysql-server-5.1 mysql-server/start_on_boot boolean true
74MYSQL_PRESEED
Jesse Andrews2caf8fd2011-09-12 16:15:11 -070075
Jesse Andrews75a37652011-09-12 17:09:08 -070076# install apt requirements
Jesse Andrews18d350d2011-09-12 21:46:12 -070077sudo apt-get install -y -q `cat $DIR/apts/* | cut -d\# -f1`
Jesse Andrewsba23cc72011-09-11 03:22:13 -070078
Jesse Andrews75a37652011-09-12 17:09:08 -070079# install python requirements
Anthony Young1bbd9e02011-09-12 23:59:19 -070080sudo PIP_DOWNLOAD_CACHE=/var/cache/pip pip install `cat $DIR/pips/*`
Jesse Andrewsba23cc72011-09-11 03:22:13 -070081
Jesse Andrews61632572011-09-12 17:40:00 -070082# git clone only if directory doesn't exist already
83function git_clone {
84 if [ ! -d $2 ]; then
85 git clone $1 $2
86 fi
87}
88
Jesse Andrews75a37652011-09-12 17:09:08 -070089# compute service
Jesse Andrews61632572011-09-12 17:40:00 -070090git_clone https://github.com/cloudbuilders/nova.git $NOVA_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070091# image catalog service
Jesse Andrews61632572011-09-12 17:40:00 -070092git_clone https://github.com/cloudbuilders/glance.git $GLANCE_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070093# unified auth system (manages accounts/tokens)
Jesse Andrews61632572011-09-12 17:40:00 -070094git_clone https://github.com/cloudbuilders/keystone.git $KEYSTONE_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070095# a websockets/html5 or flash powered VNC console for vm instances
Jesse Andrews61632572011-09-12 17:40:00 -070096git_clone https://github.com/cloudbuilders/noVNC.git $NOVNC_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070097# django powered web control panel for openstack
Jesse Andrews61632572011-09-12 17:40:00 -070098git_clone https://github.com/cloudbuilders/openstack-dashboard.git $DASH_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070099# python client library to nova that dashboard (and others) use
Jesse Andrews61632572011-09-12 17:40:00 -0700100git_clone https://github.com/cloudbuilders/python-novaclient.git $NOVACLIENT_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -0700101# openstackx is a collection of extensions to openstack.compute & nova
102# that is *deprecated*. The code is being moved into python-novaclient & nova.
Jesse Andrews61632572011-09-12 17:40:00 -0700103git_clone https://github.com/cloudbuilders/openstackx.git $API_DIR
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700104
Jesse Andrews30f68e92011-09-13 00:59:54 -0700105# Initialization
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700106# ==============
Jesse Andrews30f68e92011-09-13 00:59:54 -0700107
Jesse Andrews75a37652011-09-12 17:09:08 -0700108# setup our checkouts so they are installed into python path
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700109# allowing ``import nova`` or ``import glance.client``
Jesse Andrews18d350d2011-09-12 21:46:12 -0700110cd $NOVACLIENT_DIR; sudo python setup.py develop
111cd $KEYSTONE_DIR; sudo python setup.py develop
112cd $GLANCE_DIR; sudo python setup.py develop
113cd $API_DIR; sudo python setup.py develop
114cd $DASH_DIR/django-openstack; sudo python setup.py develop
115cd $DASH_DIR/openstack-dashboard; sudo python setup.py develop
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700116
Jesse Andrews75a37652011-09-12 17:09:08 -0700117# attempt to load modules: kvm (hardware virt) and nbd (network block
118# device - used to manage qcow images)
Jesse Andrews18d350d2011-09-12 21:46:12 -0700119sudo modprobe nbd || true
120sudo modprobe kvm || true
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700121# user needs to be member of libvirtd group for nova-compute to use libvirt
122sudo usermod -a -G libvirtd `whoami`
Jesse Andrews75a37652011-09-12 17:09:08 -0700123# if kvm wasn't running before we need to restart libvirt to enable it
Jesse Andrews18d350d2011-09-12 21:46:12 -0700124sudo /etc/init.d/libvirt-bin restart
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700125
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700126# FIXME(ja): should LIBVIRT_TYPE be kvm if kvm module is loaded?
127
Jesse Andrews75a37652011-09-12 17:09:08 -0700128# setup nova instance directory
129mkdir -p $NOVA_DIR/instances
Jesse Andrews6f3baaf2011-09-12 11:59:38 -0700130
Jesse Andrews75a37652011-09-12 17:09:08 -0700131# if there is a partition labeled nova-instances use it (ext filesystems
132# can be labeled via e2label)
Jesse Andrews834531c2011-09-12 19:37:57 -0700133# FIXME: if already mounted this blows up...
Jesse Andrews75a37652011-09-12 17:09:08 -0700134if [ -L /dev/disk/by-label/nova-instances ]; then
Jesse Andrews18d350d2011-09-12 21:46:12 -0700135 sudo mount -L nova-instances $NOVA_DIR/instances
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700136 sudo chown -R `whoami` $NOVA_DIR/instances
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700137fi
138
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700139# Dashboard
140# ---------
141#
142# Setup the django application to serve via apache/wsgi
Jesse Andrews75a37652011-09-12 17:09:08 -0700143
144# Dash currently imports quantum even if you aren't using it. Instead
145# of installing quantum we can create a simple module that will pass the
146# initial imports
Jesse Andrews834531c2011-09-12 19:37:57 -0700147mkdir $DASH_DIR/openstack-dashboard/quantum || true
Jesse Andrews75a37652011-09-12 17:09:08 -0700148touch $DASH_DIR/openstack-dashboard/quantum/__init__.py
149touch $DASH_DIR/openstack-dashboard/quantum/client.py
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700150
Jesse Andrews75a37652011-09-12 17:09:08 -0700151cd $DASH_DIR/openstack-dashboard
152cp local/local_settings.py.example local/local_settings.py
153dashboard/manage.py syncdb
154
Jesse Andrews30f68e92011-09-13 00:59:54 -0700155# setup apache
Jesse Andrews75a37652011-09-12 17:09:08 -0700156# create an empty directory to use as our
157mkdir $DASH_DIR/.blackhole
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700158
Jesse Andrews75a37652011-09-12 17:09:08 -0700159# FIXME(ja): can't figure out how to make $DASH_DIR work in sed, also install to available/a2e it
Jesse Andrews18d350d2011-09-12 21:46:12 -0700160cat $DIR/files/000-default.template | sed 's/%DASH_DIR%/\/opt\/dash/g' > /tmp/000-default
161sudo mv /tmp/000-default /etc/apache2/sites-enabled
162
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700163# ``python setup.py develop`` left some files owned by root in $DASH_DIR and
Jesse Andrews18d350d2011-09-12 21:46:12 -0700164# others by the original owner. We need to change the owner to apache so
165# dashboard can run
166sudo chown -R www-data:www-data $DASH_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -0700167
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700168# Glance
169# ------
170
Jesse Andrews9053d6a2011-09-12 22:13:11 -0700171sudo mkdir -p /var/log/glance
172sudo chown `whoami` /var/log/glance
Jesse Andrews75a37652011-09-12 17:09:08 -0700173
Jesse Andrews75a37652011-09-12 17:09:08 -0700174# add useful screenrc
175cp $DIR/files/screenrc ~/.screenrc
176
177# TODO: update current user to allow sudo for all commands in files/sudo/*
178
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700179# Nova
180# ----
181
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700182NL=`echo -ne '\015'`
183
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700184
185function add_nova_flag {
186 echo "$1" >> $NOVA_DIR/bin/nova.conf
187}
188
Jesse Andrews75a37652011-09-12 17:09:08 -0700189# (re)create nova.conf
190rm -f $NOVA_DIR/bin/nova.conf
191add_nova_flag "--verbose"
192add_nova_flag "--nodaemon"
193add_nova_flag "--dhcpbridge_flagfile=$NOVA_DIR/bin/nova.conf"
194add_nova_flag "--network_manager=nova.network.manager.$NET_MAN"
195add_nova_flag "--my_ip=$HOST_IP"
196add_nova_flag "--public_interface=$INTERFACE"
197add_nova_flag "--vlan_interface=$INTERFACE"
198add_nova_flag "--sql_connection=$SQL_CONN"
199add_nova_flag "--libvirt_type=$LIBVIRT_TYPE"
200add_nova_flag "--osapi_extensions_path=$API_DIR/extensions"
201add_nova_flag "--vncproxy_url=http://$HOST_IP:6080"
202add_nova_flag "--vncproxy_wwwroot=$NOVNC_DIR/noVNC/noVNC"
203add_nova_flag "--api_paste_config=$KEYSTONE_DIR/examples/paste/nova-api-paste.ini"
204add_nova_flag "--image_service=nova.image.glance.GlanceImageService"
205if [ -n "$FLAT_INTERFACE" ]; then
206 add_nova_flag "--flat_interface=$FLAT_INTERFACE"
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700207fi
208
Jesse Andrews75a37652011-09-12 17:09:08 -0700209# create a new named screen to store things in
210screen -d -m -S nova -t nova
211sleep 1
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700212
Jesse Andrews75a37652011-09-12 17:09:08 -0700213# Clean out the instances directory
214rm -rf $NOVA_DIR/instances/*
215
216# delete traces of nova networks from prior runs
217killall dnsmasq || true
218rm -rf $NOVA_DIR/networks
219mkdir -p $NOVA_DIR/networks
220
221# (re)create nova database
Jesse Andrews18d350d2011-09-12 21:46:12 -0700222mysql -uroot -p$MYSQL_PASS -e 'DROP DATABASE nova;' || true
223mysql -uroot -p$MYSQL_PASS -e 'CREATE DATABASE nova;'
Jesse Andrews75a37652011-09-12 17:09:08 -0700224$NOVA_DIR/bin/nova-manage db sync
225
226# initialize keystone with default users/endpoints
Jesse Andrews75a37652011-09-12 17:09:08 -0700227rm -f /opt/keystone/keystone.db
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700228# FIXME keystone creates a keystone.log wherever you run it from (bugify)
229cd /tmp
Jesse Andrews73e27b82011-09-12 17:55:00 -0700230BIN_DIR=$KEYSTONE_DIR/bin bash $DIR/files/keystone_data.sh
Jesse Andrews75a37652011-09-12 17:09:08 -0700231
232# create a small network
233$NOVA_DIR/bin/nova-manage network create private $FIXED_RANGE 1 32
234
235# create some floating ips
236$NOVA_DIR/bin/nova-manage floating create $FLOATING_RANGE
237
238# delete existing glance images/database. Glance will recreate the db
239# when it is ran.
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700240# FIXME: configure glance not to shove files in /var/lib/glance?
241sudo mkdir -p /var/lib/glance
242sudo chown -R `whoami` /var/lib/glance
243rm -rf /var/lib/glance/images/*
Jesse Andrews75a37652011-09-12 17:09:08 -0700244rm -f $GLANCE_DIR/glance.sqlite
245
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700246# Launch Services
247# ===============
Jesse Andrews30f68e92011-09-13 00:59:54 -0700248
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700249# nova api crashes if we start it with a regular screen command,
250# so send the start command by forcing text into the window.
251function screen_it {
252 screen -S nova -X screen -t $1
253 screen -S nova -p $1 -X stuff "$2$NL"
254}
255
Jesse Andrews75a37652011-09-12 17:09:08 -0700256screen_it g-api "cd $GLANCE_DIR; bin/glance-api --config-file=etc/glance-api.conf"
257screen_it g-reg "cd $GLANCE_DIR; bin/glance-registry --config-file=etc/glance-registry.conf"
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700258# keystone drops a keystone.log where if it is run, so change the path to
259# where it can write
260screen_it key "cd /tmp; $KEYSTONE_DIR/bin/keystone --config-file $KEYSTONE_DIR/etc/keystone.conf"
Jesse Andrews55508d62011-09-12 19:00:28 -0700261screen_it n-api "$NOVA_DIR/bin/nova-api"
262screen_it n-cpu "$NOVA_DIR/bin/nova-compute"
263screen_it n-net "$NOVA_DIR/bin/nova-network"
264screen_it n-sch "$NOVA_DIR/bin/nova-scheduler"
265screen_it n-vnc "$NOVA_DIR/bin/nova-vncproxy"
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700266screen_it dash "sudo /etc/init.d/apache2 restart; tail -f /var/log/apache2/error.log"
Jesse Andrews75a37652011-09-12 17:09:08 -0700267
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700268# Install Images
269# ==============
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700270
Jesse Andrews30f68e92011-09-13 00:59:54 -0700271# Downloads a tty image (ami/aki/ari style), then extracts it. Upon extraction
272# we upload to glance with the glance cli tool.
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700273
274mkdir -p $DEST/images
275cd $DEST/images
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700276if [ ! -f $DEST/tty.tgz ]; then
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700277 wget -c http://images.ansolabs.com/tty.tgz -O $DEST/tty.tgz
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700278fi
279
280# extract ami-tty/image, aki-tty/image & ari-tty/image
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700281tar -zxf $DEST/tty.tgz
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700282
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700283# add images to glance
284# FIXME: kernel/ramdisk is hardcoded - use return result from add
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700285glance add name="tty-kernel" is_public=true container_format=aki disk_format=aki < aki-tty/image
286glance add name="tty-ramdisk" is_public=true container_format=ari disk_format=ari < ari-tty/image
287glance add name="tty" is_public=true container_format=ami disk_format=ami kernel_id=1 ramdisk_id=2 < ami-tty/image
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700288