blob: f537f9e30da380ae56038689281d10749c5b2bc6 [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 Andrewsbe395c12011-09-12 19:11:30 -07005# FIXME: commands should be: stack.sh should allow specifying a subset of services
6
Jesse Andrewsba23cc72011-09-11 03:22:13 -07007# Quit script on error
8set -o errexit
9
10# Log commands as they are run for debugging
11set -o xtrace
12
13DIR=`pwd`
14DEST=/opt
Jesse Andrewsba23cc72011-09-11 03:22:13 -070015
Jesse Andrews6f3baaf2011-09-12 11:59:38 -070016# Set the destination directories for openstack projects
Jesse Andrewsba23cc72011-09-11 03:22:13 -070017NOVA_DIR=$DEST/nova
18DASH_DIR=$DEST/dash
19GLANCE_DIR=$DEST/glance
20KEYSTONE_DIR=$DEST/keystone
21NOVACLIENT_DIR=$DEST/python-novaclient
22API_DIR=$DEST/openstackx
23NOVNC_DIR=$DEST/noVNC
24
25# Use the first IP unless an explicit is set by a HOST_IP environment variable
26if [ ! -n "$HOST_IP" ]; then
27 HOST_IP=`LC_ALL=C ifconfig | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
28fi
29
Jesse Andrewsbe395c12011-09-12 19:11:30 -070030# NOVA network / hypervisor configuration
Jesse Andrewsba23cc72011-09-11 03:22:13 -070031INTERFACE=${INTERFACE:-eth0}
32FLOATING_RANGE=${FLOATING_RANGE:-10.6.0.0/27}
33FIXED_RANGE=${FIXED_RANGE:-10.0.0.0/24}
34LIBVIRT_TYPE=${LIBVIRT_TYPE:-qemu}
35NET_MAN=${NET_MAN:-VlanManager}
36# NOTE(vish): If you are using FlatDHCP on multiple hosts, set the interface
37# below but make sure that the interface doesn't already have an
38# ip or you risk breaking things.
39# FLAT_INTERFACE=eth0
40
Jesse Andrews2caf8fd2011-09-12 16:15:11 -070041# TODO: switch to mysql for all services
Jesse Andrews1c1d1502011-09-12 19:29:56 -070042MYSQL_PASS=${MYSQL_PASS:-nova}
43SQL_CONN=${SQL_CONN:-mysql://root:$MYSQL_PASS@localhost/nova}
44# TODO: set rabbitmq conn string explicitly as well
Jesse Andrewsba23cc72011-09-11 03:22:13 -070045
Jesse Andrews1c1d1502011-09-12 19:29:56 -070046# seed configuration with mysql password
Jesse Andrews18d350d2011-09-12 21:46:12 -070047cat <<MYSQL_PRESEED | sudo debconf-set-selections
Jesse Andrews1c1d1502011-09-12 19:29:56 -070048mysql-server-5.1 mysql-server/root_password password $MYSQL_PASS
49mysql-server-5.1 mysql-server/root_password_again password $MYSQL_PASS
50mysql-server-5.1 mysql-server/start_on_boot boolean true
51MYSQL_PRESEED
Jesse Andrews2caf8fd2011-09-12 16:15:11 -070052
Jesse Andrews75a37652011-09-12 17:09:08 -070053# install apt requirements
Jesse Andrews18d350d2011-09-12 21:46:12 -070054sudo apt-get install -y -q `cat $DIR/apts/* | cut -d\# -f1`
Jesse Andrewsba23cc72011-09-11 03:22:13 -070055
Jesse Andrews75a37652011-09-12 17:09:08 -070056# install python requirements
Anthony Young1bbd9e02011-09-12 23:59:19 -070057sudo PIP_DOWNLOAD_CACHE=/var/cache/pip pip install `cat $DIR/pips/*`
Jesse Andrewsba23cc72011-09-11 03:22:13 -070058
Jesse Andrews61632572011-09-12 17:40:00 -070059# git clone only if directory doesn't exist already
60function git_clone {
61 if [ ! -d $2 ]; then
62 git clone $1 $2
63 fi
64}
65
Jesse Andrews75a37652011-09-12 17:09:08 -070066# compute service
Jesse Andrews61632572011-09-12 17:40:00 -070067git_clone https://github.com/cloudbuilders/nova.git $NOVA_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070068# image catalog service
Jesse Andrews61632572011-09-12 17:40:00 -070069git_clone https://github.com/cloudbuilders/glance.git $GLANCE_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070070# unified auth system (manages accounts/tokens)
Jesse Andrews61632572011-09-12 17:40:00 -070071git_clone https://github.com/cloudbuilders/keystone.git $KEYSTONE_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070072# a websockets/html5 or flash powered VNC console for vm instances
Jesse Andrews61632572011-09-12 17:40:00 -070073git_clone https://github.com/cloudbuilders/noVNC.git $NOVNC_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070074# django powered web control panel for openstack
Jesse Andrews61632572011-09-12 17:40:00 -070075git_clone https://github.com/cloudbuilders/openstack-dashboard.git $DASH_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070076# python client library to nova that dashboard (and others) use
Jesse Andrews61632572011-09-12 17:40:00 -070077git_clone https://github.com/cloudbuilders/python-novaclient.git $NOVACLIENT_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070078# openstackx is a collection of extensions to openstack.compute & nova
79# that is *deprecated*. The code is being moved into python-novaclient & nova.
Jesse Andrews61632572011-09-12 17:40:00 -070080git_clone https://github.com/cloudbuilders/openstackx.git $API_DIR
Jesse Andrewsba23cc72011-09-11 03:22:13 -070081
Jesse Andrews75a37652011-09-12 17:09:08 -070082# setup our checkouts so they are installed into python path
83# allowing `import nova` or `import glance.client`
Jesse Andrews18d350d2011-09-12 21:46:12 -070084cd $NOVACLIENT_DIR; sudo python setup.py develop
85cd $KEYSTONE_DIR; sudo python setup.py develop
86cd $GLANCE_DIR; sudo python setup.py develop
87cd $API_DIR; sudo python setup.py develop
88cd $DASH_DIR/django-openstack; sudo python setup.py develop
89cd $DASH_DIR/openstack-dashboard; sudo python setup.py develop
Jesse Andrewsba23cc72011-09-11 03:22:13 -070090
Jesse Andrews75a37652011-09-12 17:09:08 -070091# attempt to load modules: kvm (hardware virt) and nbd (network block
92# device - used to manage qcow images)
Jesse Andrews18d350d2011-09-12 21:46:12 -070093sudo modprobe nbd || true
94sudo modprobe kvm || true
Jesse Andrews4d6cb142011-09-12 23:48:30 -070095# user needs to be member of libvirtd group for nova-compute to use libvirt
96sudo usermod -a -G libvirtd `whoami`
Jesse Andrews75a37652011-09-12 17:09:08 -070097# if kvm wasn't running before we need to restart libvirt to enable it
Jesse Andrews18d350d2011-09-12 21:46:12 -070098sudo /etc/init.d/libvirt-bin restart
Jesse Andrewsba23cc72011-09-11 03:22:13 -070099
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700100# FIXME(ja): should LIBVIRT_TYPE be kvm if kvm module is loaded?
101
Jesse Andrews75a37652011-09-12 17:09:08 -0700102# setup nova instance directory
103mkdir -p $NOVA_DIR/instances
Jesse Andrews6f3baaf2011-09-12 11:59:38 -0700104
Jesse Andrews75a37652011-09-12 17:09:08 -0700105# if there is a partition labeled nova-instances use it (ext filesystems
106# can be labeled via e2label)
Jesse Andrews834531c2011-09-12 19:37:57 -0700107# FIXME: if already mounted this blows up...
Jesse Andrews75a37652011-09-12 17:09:08 -0700108if [ -L /dev/disk/by-label/nova-instances ]; then
Jesse Andrews18d350d2011-09-12 21:46:12 -0700109 sudo mount -L nova-instances $NOVA_DIR/instances
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700110 sudo chown -R `whoami` $NOVA_DIR/instances
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700111fi
112
Jesse Andrews75a37652011-09-12 17:09:08 -0700113# *Dashboard*: setup django application to serve via apache/wsgi
114
115# Dash currently imports quantum even if you aren't using it. Instead
116# of installing quantum we can create a simple module that will pass the
117# initial imports
Jesse Andrews834531c2011-09-12 19:37:57 -0700118mkdir $DASH_DIR/openstack-dashboard/quantum || true
Jesse Andrews75a37652011-09-12 17:09:08 -0700119touch $DASH_DIR/openstack-dashboard/quantum/__init__.py
120touch $DASH_DIR/openstack-dashboard/quantum/client.py
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700121
Jesse Andrews75a37652011-09-12 17:09:08 -0700122cd $DASH_DIR/openstack-dashboard
123cp local/local_settings.py.example local/local_settings.py
124dashboard/manage.py syncdb
125
Jesse Andrews18d350d2011-09-12 21:46:12 -0700126# ---- Setup Apache ----
Jesse Andrews75a37652011-09-12 17:09:08 -0700127# create an empty directory to use as our
128mkdir $DASH_DIR/.blackhole
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700129
Jesse Andrews75a37652011-09-12 17:09:08 -0700130# 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 -0700131cat $DIR/files/000-default.template | sed 's/%DASH_DIR%/\/opt\/dash/g' > /tmp/000-default
132sudo mv /tmp/000-default /etc/apache2/sites-enabled
133
134# `python setup.py develop` left some files owned by root in $DASH_DIR and
135# others by the original owner. We need to change the owner to apache so
136# dashboard can run
137sudo chown -R www-data:www-data $DASH_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -0700138
Jesse Andrews9053d6a2011-09-12 22:13:11 -0700139sudo mkdir -p /var/log/glance
140sudo chown `whoami` /var/log/glance
Jesse Andrews75a37652011-09-12 17:09:08 -0700141
Jesse Andrews75a37652011-09-12 17:09:08 -0700142# add useful screenrc
143cp $DIR/files/screenrc ~/.screenrc
144
145# TODO: update current user to allow sudo for all commands in files/sudo/*
146
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700147NL=`echo -ne '\015'`
148
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700149
150function add_nova_flag {
151 echo "$1" >> $NOVA_DIR/bin/nova.conf
152}
153
Jesse Andrews75a37652011-09-12 17:09:08 -0700154# (re)create nova.conf
155rm -f $NOVA_DIR/bin/nova.conf
156add_nova_flag "--verbose"
157add_nova_flag "--nodaemon"
158add_nova_flag "--dhcpbridge_flagfile=$NOVA_DIR/bin/nova.conf"
159add_nova_flag "--network_manager=nova.network.manager.$NET_MAN"
160add_nova_flag "--my_ip=$HOST_IP"
161add_nova_flag "--public_interface=$INTERFACE"
162add_nova_flag "--vlan_interface=$INTERFACE"
163add_nova_flag "--sql_connection=$SQL_CONN"
164add_nova_flag "--libvirt_type=$LIBVIRT_TYPE"
165add_nova_flag "--osapi_extensions_path=$API_DIR/extensions"
166add_nova_flag "--vncproxy_url=http://$HOST_IP:6080"
167add_nova_flag "--vncproxy_wwwroot=$NOVNC_DIR/noVNC/noVNC"
168add_nova_flag "--api_paste_config=$KEYSTONE_DIR/examples/paste/nova-api-paste.ini"
169add_nova_flag "--image_service=nova.image.glance.GlanceImageService"
170if [ -n "$FLAT_INTERFACE" ]; then
171 add_nova_flag "--flat_interface=$FLAT_INTERFACE"
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700172fi
173
Jesse Andrews75a37652011-09-12 17:09:08 -0700174# create a new named screen to store things in
175screen -d -m -S nova -t nova
176sleep 1
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700177
Jesse Andrews75a37652011-09-12 17:09:08 -0700178# Clean out the instances directory
179rm -rf $NOVA_DIR/instances/*
180
181# delete traces of nova networks from prior runs
182killall dnsmasq || true
183rm -rf $NOVA_DIR/networks
184mkdir -p $NOVA_DIR/networks
185
186# (re)create nova database
Jesse Andrews18d350d2011-09-12 21:46:12 -0700187mysql -uroot -p$MYSQL_PASS -e 'DROP DATABASE nova;' || true
188mysql -uroot -p$MYSQL_PASS -e 'CREATE DATABASE nova;'
Jesse Andrews75a37652011-09-12 17:09:08 -0700189$NOVA_DIR/bin/nova-manage db sync
190
191# initialize keystone with default users/endpoints
Jesse Andrews75a37652011-09-12 17:09:08 -0700192rm -f /opt/keystone/keystone.db
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700193# FIXME keystone creates a keystone.log wherever you run it from (bugify)
194cd /tmp
Jesse Andrews73e27b82011-09-12 17:55:00 -0700195BIN_DIR=$KEYSTONE_DIR/bin bash $DIR/files/keystone_data.sh
Jesse Andrews75a37652011-09-12 17:09:08 -0700196
197# create a small network
198$NOVA_DIR/bin/nova-manage network create private $FIXED_RANGE 1 32
199
200# create some floating ips
201$NOVA_DIR/bin/nova-manage floating create $FLOATING_RANGE
202
203# delete existing glance images/database. Glance will recreate the db
204# when it is ran.
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700205# FIXME: configure glance not to shove files in /var/lib/glance?
206sudo mkdir -p /var/lib/glance
207sudo chown -R `whoami` /var/lib/glance
208rm -rf /var/lib/glance/images/*
Jesse Andrews75a37652011-09-12 17:09:08 -0700209rm -f $GLANCE_DIR/glance.sqlite
210
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700211# nova api crashes if we start it with a regular screen command,
212# so send the start command by forcing text into the window.
213function screen_it {
214 screen -S nova -X screen -t $1
215 screen -S nova -p $1 -X stuff "$2$NL"
216}
217
Jesse Andrews75a37652011-09-12 17:09:08 -0700218screen_it g-api "cd $GLANCE_DIR; bin/glance-api --config-file=etc/glance-api.conf"
219screen_it g-reg "cd $GLANCE_DIR; bin/glance-registry --config-file=etc/glance-registry.conf"
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700220# keystone drops a keystone.log where if it is run, so change the path to
221# where it can write
222screen_it key "cd /tmp; $KEYSTONE_DIR/bin/keystone --config-file $KEYSTONE_DIR/etc/keystone.conf"
Jesse Andrews55508d62011-09-12 19:00:28 -0700223screen_it n-api "$NOVA_DIR/bin/nova-api"
224screen_it n-cpu "$NOVA_DIR/bin/nova-compute"
225screen_it n-net "$NOVA_DIR/bin/nova-network"
226screen_it n-sch "$NOVA_DIR/bin/nova-scheduler"
227screen_it n-vnc "$NOVA_DIR/bin/nova-vncproxy"
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700228screen_it dash "sudo /etc/init.d/apache2 restart; tail -f /var/log/apache2/error.log"
Jesse Andrews75a37652011-09-12 17:09:08 -0700229
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700230
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700231# ---- download an install images ----
232
233mkdir -p $DEST/images
234cd $DEST/images
235# prepare initial images for loading into glance
236if [ ! -f $DEST/tty.tgz ]; then
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700237 wget -c http://images.ansolabs.com/tty.tgz -O $DEST/tty.tgz
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700238fi
239
240# extract ami-tty/image, aki-tty/image & ari-tty/image
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700241tar -zxf $DEST/tty.tgz
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700242
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700243# add images to glance
244# FIXME: kernel/ramdisk is hardcoded - use return result from add
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700245glance add name="tty-kernel" is_public=true container_format=aki disk_format=aki < aki-tty/image
246glance add name="tty-ramdisk" is_public=true container_format=ari disk_format=ari < ari-tty/image
247glance 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 -0700248