blob: 0f83fb534352da80773075dffd1fc28ca753a6ad [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
Anthony Youngbdbe6d92011-09-13 09:43:46 -070037ENABLED_SERVICES=g-api,g-reg,key,n-api,n-cpu,n-net,n-sch,n-vnc,dash
Jesse Andrewsba23cc72011-09-11 03:22:13 -070038
Jesse Andrewsd74257d2011-09-13 01:24:50 -070039# Use the first IP unless an explicit is set by ``HOST_IP`` environment variable
Jesse Andrewsba23cc72011-09-11 03:22:13 -070040if [ ! -n "$HOST_IP" ]; then
41 HOST_IP=`LC_ALL=C ifconfig | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
42fi
43
Jesse Andrewsd74257d2011-09-13 01:24:50 -070044# Nova network configuration
Jesse Andrewsba23cc72011-09-11 03:22:13 -070045INTERFACE=${INTERFACE:-eth0}
46FLOATING_RANGE=${FLOATING_RANGE:-10.6.0.0/27}
47FIXED_RANGE=${FIXED_RANGE:-10.0.0.0/24}
Jesse Andrewsba23cc72011-09-11 03:22:13 -070048NET_MAN=${NET_MAN:-VlanManager}
Jesse Andrews30f68e92011-09-13 00:59:54 -070049
Jesse Andrewsd74257d2011-09-13 01:24:50 -070050# If you are using FlatDHCP on multiple hosts, set the ``FLAT_INTERFACE``
51# variable but make sure that the interface doesn't already have an
52# ip or you risk breaking things.
Jesse Andrewsba23cc72011-09-11 03:22:13 -070053# FLAT_INTERFACE=eth0
54
Jesse Andrewsd74257d2011-09-13 01:24:50 -070055# Nova hypervisor configuration
56LIBVIRT_TYPE=${LIBVIRT_TYPE:-qemu}
57
58
Jesse Andrews2caf8fd2011-09-12 16:15:11 -070059# TODO: switch to mysql for all services
Jesse Andrews1c1d1502011-09-12 19:29:56 -070060MYSQL_PASS=${MYSQL_PASS:-nova}
61SQL_CONN=${SQL_CONN:-mysql://root:$MYSQL_PASS@localhost/nova}
62# TODO: set rabbitmq conn string explicitly as well
Jesse Andrewsba23cc72011-09-11 03:22:13 -070063
Jesse Andrews30f68e92011-09-13 00:59:54 -070064# Install Packages
Jesse Andrewsd74257d2011-09-13 01:24:50 -070065# ================
Jesse Andrews30f68e92011-09-13 00:59:54 -070066#
67# Openstack uses a fair number of other projects.
68
Jesse Andrewsd74257d2011-09-13 01:24:50 -070069# Seed configuration with mysql password so that apt-get install doesn't
70# prompt us for a password upon install.
Jesse Andrews18d350d2011-09-12 21:46:12 -070071cat <<MYSQL_PRESEED | sudo debconf-set-selections
Jesse Andrews1c1d1502011-09-12 19:29:56 -070072mysql-server-5.1 mysql-server/root_password password $MYSQL_PASS
73mysql-server-5.1 mysql-server/root_password_again password $MYSQL_PASS
74mysql-server-5.1 mysql-server/start_on_boot boolean true
75MYSQL_PRESEED
Jesse Andrews2caf8fd2011-09-12 16:15:11 -070076
Jesse Andrews75a37652011-09-12 17:09:08 -070077# install apt requirements
Jesse Andrews18d350d2011-09-12 21:46:12 -070078sudo apt-get install -y -q `cat $DIR/apts/* | cut -d\# -f1`
Jesse Andrewsba23cc72011-09-11 03:22:13 -070079
Jesse Andrews75a37652011-09-12 17:09:08 -070080# install python requirements
Anthony Young1bbd9e02011-09-12 23:59:19 -070081sudo PIP_DOWNLOAD_CACHE=/var/cache/pip pip install `cat $DIR/pips/*`
Jesse Andrewsba23cc72011-09-11 03:22:13 -070082
Jesse Andrews61632572011-09-12 17:40:00 -070083# git clone only if directory doesn't exist already
84function git_clone {
85 if [ ! -d $2 ]; then
86 git clone $1 $2
87 fi
88}
89
Jesse Andrews75a37652011-09-12 17:09:08 -070090# compute service
Jesse Andrews61632572011-09-12 17:40:00 -070091git_clone https://github.com/cloudbuilders/nova.git $NOVA_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070092# image catalog service
Jesse Andrews61632572011-09-12 17:40:00 -070093git_clone https://github.com/cloudbuilders/glance.git $GLANCE_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070094# unified auth system (manages accounts/tokens)
Jesse Andrews61632572011-09-12 17:40:00 -070095git_clone https://github.com/cloudbuilders/keystone.git $KEYSTONE_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070096# a websockets/html5 or flash powered VNC console for vm instances
Jesse Andrews61632572011-09-12 17:40:00 -070097git_clone https://github.com/cloudbuilders/noVNC.git $NOVNC_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070098# django powered web control panel for openstack
Jesse Andrews61632572011-09-12 17:40:00 -070099git_clone https://github.com/cloudbuilders/openstack-dashboard.git $DASH_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -0700100# python client library to nova that dashboard (and others) use
Jesse Andrews61632572011-09-12 17:40:00 -0700101git_clone https://github.com/cloudbuilders/python-novaclient.git $NOVACLIENT_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -0700102# openstackx is a collection of extensions to openstack.compute & nova
103# that is *deprecated*. The code is being moved into python-novaclient & nova.
Jesse Andrews61632572011-09-12 17:40:00 -0700104git_clone https://github.com/cloudbuilders/openstackx.git $API_DIR
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700105
Jesse Andrews30f68e92011-09-13 00:59:54 -0700106# Initialization
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700107# ==============
Jesse Andrews30f68e92011-09-13 00:59:54 -0700108
Jesse Andrews75a37652011-09-12 17:09:08 -0700109# setup our checkouts so they are installed into python path
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700110# allowing ``import nova`` or ``import glance.client``
Jesse Andrews18d350d2011-09-12 21:46:12 -0700111cd $NOVACLIENT_DIR; sudo python setup.py develop
112cd $KEYSTONE_DIR; sudo python setup.py develop
113cd $GLANCE_DIR; sudo python setup.py develop
114cd $API_DIR; sudo python setup.py develop
115cd $DASH_DIR/django-openstack; sudo python setup.py develop
116cd $DASH_DIR/openstack-dashboard; sudo python setup.py develop
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700117
Jesse Andrews75a37652011-09-12 17:09:08 -0700118# attempt to load modules: kvm (hardware virt) and nbd (network block
119# device - used to manage qcow images)
Jesse Andrews18d350d2011-09-12 21:46:12 -0700120sudo modprobe nbd || true
121sudo modprobe kvm || true
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700122# user needs to be member of libvirtd group for nova-compute to use libvirt
123sudo usermod -a -G libvirtd `whoami`
Jesse Andrews75a37652011-09-12 17:09:08 -0700124# if kvm wasn't running before we need to restart libvirt to enable it
Jesse Andrews18d350d2011-09-12 21:46:12 -0700125sudo /etc/init.d/libvirt-bin restart
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700126
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700127## FIXME(ja): should LIBVIRT_TYPE be kvm if kvm module is loaded?
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700128
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700129# add useful screenrc
130cp $DIR/files/screenrc ~/.screenrc
Jesse Andrews6f3baaf2011-09-12 11:59:38 -0700131
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700132# TODO: update current user to allow sudo for all commands in files/sudo/*
133
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700134
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700135# Dashboard
136# ---------
137#
138# Setup the django application to serve via apache/wsgi
Jesse Andrews75a37652011-09-12 17:09:08 -0700139
140# Dash currently imports quantum even if you aren't using it. Instead
141# of installing quantum we can create a simple module that will pass the
142# initial imports
Jesse Andrews834531c2011-09-12 19:37:57 -0700143mkdir $DASH_DIR/openstack-dashboard/quantum || true
Jesse Andrews75a37652011-09-12 17:09:08 -0700144touch $DASH_DIR/openstack-dashboard/quantum/__init__.py
145touch $DASH_DIR/openstack-dashboard/quantum/client.py
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700146
Jesse Andrews75a37652011-09-12 17:09:08 -0700147cd $DASH_DIR/openstack-dashboard
148cp local/local_settings.py.example local/local_settings.py
149dashboard/manage.py syncdb
150
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700151# create an empty directory that apache uses as docroot
Jesse Andrews75a37652011-09-12 17:09:08 -0700152mkdir $DASH_DIR/.blackhole
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700153
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700154## 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 -0700155cat $DIR/files/000-default.template | sed 's/%DASH_DIR%/\/opt\/dash/g' > /tmp/000-default
156sudo mv /tmp/000-default /etc/apache2/sites-enabled
157
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700158# ``python setup.py develop`` left some files owned by root in ``DASH_DIR`` and
Jesse Andrews18d350d2011-09-12 21:46:12 -0700159# others by the original owner. We need to change the owner to apache so
160# dashboard can run
161sudo chown -R www-data:www-data $DASH_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -0700162
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700163
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700164# Glance
165# ------
166
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700167# Glance uses ``/var/lib/glance`` and ``/var/log/glance`` by default, so
168# we need to insure that our user has permissions to use them.
Jesse Andrews9053d6a2011-09-12 22:13:11 -0700169sudo mkdir -p /var/log/glance
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700170sudo chown -R `whoami` /var/log/glance
171sudo mkdir -p /var/lib/glance
172sudo chown -R `whoami` /var/lib/glance
Jesse Andrews75a37652011-09-12 17:09:08 -0700173
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700174# Delete existing images/database as glance will recreate the db on startup
175rm -rf /var/lib/glance/images/*
176rm -f $GLANCE_DIR/glance.sqlite
Jesse Andrews75a37652011-09-12 17:09:08 -0700177
Jesse Andrews75a37652011-09-12 17:09:08 -0700178
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700179# Nova
180# ----
181
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700182function add_nova_flag {
183 echo "$1" >> $NOVA_DIR/bin/nova.conf
184}
185
Jesse Andrews75a37652011-09-12 17:09:08 -0700186# (re)create nova.conf
187rm -f $NOVA_DIR/bin/nova.conf
188add_nova_flag "--verbose"
189add_nova_flag "--nodaemon"
190add_nova_flag "--dhcpbridge_flagfile=$NOVA_DIR/bin/nova.conf"
191add_nova_flag "--network_manager=nova.network.manager.$NET_MAN"
192add_nova_flag "--my_ip=$HOST_IP"
193add_nova_flag "--public_interface=$INTERFACE"
194add_nova_flag "--vlan_interface=$INTERFACE"
195add_nova_flag "--sql_connection=$SQL_CONN"
196add_nova_flag "--libvirt_type=$LIBVIRT_TYPE"
197add_nova_flag "--osapi_extensions_path=$API_DIR/extensions"
198add_nova_flag "--vncproxy_url=http://$HOST_IP:6080"
Anthony Young1f81db62011-09-13 03:35:00 -0700199add_nova_flag "--vncproxy_wwwroot=$NOVNC_DIR/"
Jesse Andrews75a37652011-09-12 17:09:08 -0700200add_nova_flag "--api_paste_config=$KEYSTONE_DIR/examples/paste/nova-api-paste.ini"
201add_nova_flag "--image_service=nova.image.glance.GlanceImageService"
202if [ -n "$FLAT_INTERFACE" ]; then
203 add_nova_flag "--flat_interface=$FLAT_INTERFACE"
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700204fi
205
Jesse Andrews75a37652011-09-12 17:09:08 -0700206# create a new named screen to store things in
207screen -d -m -S nova -t nova
208sleep 1
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700209
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700210# setup nova instance directory
211mkdir -p $NOVA_DIR/instances
212
213# if there is a partition labeled nova-instances use it (ext filesystems
214# can be labeled via e2label)
215## FIXME: if already mounted this blows up...
216if [ -L /dev/disk/by-label/nova-instances ]; then
217 sudo mount -L nova-instances $NOVA_DIR/instances
218 sudo chown -R `whoami` $NOVA_DIR/instances
219fi
220
Jesse Andrews75a37652011-09-12 17:09:08 -0700221# Clean out the instances directory
222rm -rf $NOVA_DIR/instances/*
223
224# delete traces of nova networks from prior runs
225killall dnsmasq || true
226rm -rf $NOVA_DIR/networks
227mkdir -p $NOVA_DIR/networks
228
229# (re)create nova database
Jesse Andrews18d350d2011-09-12 21:46:12 -0700230mysql -uroot -p$MYSQL_PASS -e 'DROP DATABASE nova;' || true
231mysql -uroot -p$MYSQL_PASS -e 'CREATE DATABASE nova;'
Anthony Young3a093122011-09-13 19:01:45 +0000232mysql -uroot -p$MYSQL_PASS -e 'DROP DATABASE keystone;' || true
233mysql -uroot -p$MYSQL_PASS -e 'CREATE DATABASE keystone;'
Jesse Andrews75a37652011-09-12 17:09:08 -0700234$NOVA_DIR/bin/nova-manage db sync
235
Anthony Young3a093122011-09-13 19:01:45 +0000236# FIXME (anthony) keystone should use keystone.conf.example
237KEYSTONE_CONF=$KEYSTONE_DIR/etc/keystone.conf
238cp $DIR/files/keystone.conf $KEYSTONE_CONF
239
Jesse Andrews75a37652011-09-12 17:09:08 -0700240# initialize keystone with default users/endpoints
Jesse Andrews73e27b82011-09-12 17:55:00 -0700241BIN_DIR=$KEYSTONE_DIR/bin bash $DIR/files/keystone_data.sh
Jesse Andrews75a37652011-09-12 17:09:08 -0700242
243# create a small network
244$NOVA_DIR/bin/nova-manage network create private $FIXED_RANGE 1 32
245
246# create some floating ips
247$NOVA_DIR/bin/nova-manage floating create $FLOATING_RANGE
248
Jesse Andrews75a37652011-09-12 17:09:08 -0700249
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700250# Launch Services
251# ===============
Jesse Andrews30f68e92011-09-13 00:59:54 -0700252
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700253# nova api crashes if we start it with a regular screen command,
254# so send the start command by forcing text into the window.
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700255# Only run the services specified in ``ENABLED_SERVICES``
256
257NL=`echo -ne '\015'`
258
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700259function screen_it {
Anthony Young292e46d2011-09-13 11:28:56 -0700260 if [[ "$ENABLED_SERVICES" =~ "$1" ]]; then
261 screen -S nova -X screen -t $1
262 screen -S nova -p $1 -X stuff "$2$NL"
263 fi
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700264}
265
Jesse Andrews75a37652011-09-12 17:09:08 -0700266screen_it g-api "cd $GLANCE_DIR; bin/glance-api --config-file=etc/glance-api.conf"
267screen_it g-reg "cd $GLANCE_DIR; bin/glance-registry --config-file=etc/glance-registry.conf"
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700268# keystone drops a keystone.log where if it is run, so change the path to
269# where it can write
Anthony Young3a093122011-09-13 19:01:45 +0000270screen_it key "cd /tmp; $KEYSTONE_DIR/bin/keystone --config-file $KEYSTONE_CONF"
Jesse Andrews55508d62011-09-12 19:00:28 -0700271screen_it n-api "$NOVA_DIR/bin/nova-api"
272screen_it n-cpu "$NOVA_DIR/bin/nova-compute"
273screen_it n-net "$NOVA_DIR/bin/nova-network"
274screen_it n-sch "$NOVA_DIR/bin/nova-scheduler"
Anthony Young1f81db62011-09-13 03:35:00 -0700275# nova-vncproxy binds a privileged port, and so needs sudo
276screen_it n-vnc "sudo $NOVA_DIR/bin/nova-vncproxy"
Anthony Young8fbba912011-09-13 09:20:58 -0700277screen_it dash "sudo /etc/init.d/apache2 restart; sudo tail -f /var/log/apache2/error.log"
Jesse Andrews75a37652011-09-12 17:09:08 -0700278
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700279# Install Images
280# ==============
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700281
Jesse Andrews30f68e92011-09-13 00:59:54 -0700282# Downloads a tty image (ami/aki/ari style), then extracts it. Upon extraction
283# we upload to glance with the glance cli tool.
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700284
285mkdir -p $DEST/images
286cd $DEST/images
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700287if [ ! -f $DEST/tty.tgz ]; then
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700288 wget -c http://images.ansolabs.com/tty.tgz -O $DEST/tty.tgz
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700289fi
290
291# extract ami-tty/image, aki-tty/image & ari-tty/image
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700292tar -zxf $DEST/tty.tgz
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700293
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700294# add images to glance
295# FIXME: kernel/ramdisk is hardcoded - use return result from add
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700296glance add name="tty-kernel" is_public=true container_format=aki disk_format=aki < aki-tty/image
297glance add name="tty-ramdisk" is_public=true container_format=ari disk_format=ari < ari-tty/image
298glance 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 -0700299