blob: 0faa09b58607876f59fbf73850aedc2a4b817882 [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
47cat <<MYSQL_PRESEED | debconf-set-selections
48mysql-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
54apt-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
57pip 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`
84cd $NOVACLIENT_DIR; python setup.py develop
85cd $KEYSTONE_DIR; python setup.py develop
86cd $GLANCE_DIR; python setup.py develop
87cd $API_DIR; python setup.py develop
88cd $DASH_DIR/django-openstack; python setup.py develop
89cd $DASH_DIR/openstack-dashboard; 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)
93modprobe nbd || true
94modprobe kvm || true
95# if kvm wasn't running before we need to restart libvirt to enable it
96/etc/init.d/libvirt-bin restart
Jesse Andrewsba23cc72011-09-11 03:22:13 -070097
Jesse Andrewsbe395c12011-09-12 19:11:30 -070098# FIXME(ja): should LIBVIRT_TYPE be kvm if kvm module is loaded?
99
Jesse Andrews75a37652011-09-12 17:09:08 -0700100# setup nova instance directory
101mkdir -p $NOVA_DIR/instances
Jesse Andrews6f3baaf2011-09-12 11:59:38 -0700102
Jesse Andrews75a37652011-09-12 17:09:08 -0700103# if there is a partition labeled nova-instances use it (ext filesystems
104# can be labeled via e2label)
105if [ -L /dev/disk/by-label/nova-instances ]; then
106 mount -L nova-instances /$NOVA_DIR/instances
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700107fi
108
Jesse Andrews75a37652011-09-12 17:09:08 -0700109# *Dashboard*: setup django application to serve via apache/wsgi
110
111# Dash currently imports quantum even if you aren't using it. Instead
112# of installing quantum we can create a simple module that will pass the
113# initial imports
114mkdir $DASH_DIR/openstack-dashboard/quantum
115touch $DASH_DIR/openstack-dashboard/quantum/__init__.py
116touch $DASH_DIR/openstack-dashboard/quantum/client.py
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700117
Jesse Andrews75a37652011-09-12 17:09:08 -0700118cd $DASH_DIR/openstack-dashboard
119cp local/local_settings.py.example local/local_settings.py
120dashboard/manage.py syncdb
121
122# ## Setup Apache
123# create an empty directory to use as our
124mkdir $DASH_DIR/.blackhole
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700125
Jesse Andrews75a37652011-09-12 17:09:08 -0700126# FIXME(ja): can't figure out how to make $DASH_DIR work in sed, also install to available/a2e it
127cat $DIR/files/000-default.template | sed 's/%DASH_DIR%/\/opt\/dash/g' > /etc/apache2/sites-enabled/000-default
Jesse Andrews75a37652011-09-12 17:09:08 -0700128chown -R www-data:www-data $DASH_DIR
129
130mkdir -p /var/log/glance
131
Jesse Andrews75a37652011-09-12 17:09:08 -0700132# add useful screenrc
133cp $DIR/files/screenrc ~/.screenrc
134
135# TODO: update current user to allow sudo for all commands in files/sudo/*
136
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700137NL=`echo -ne '\015'`
138
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700139
140function add_nova_flag {
141 echo "$1" >> $NOVA_DIR/bin/nova.conf
142}
143
Jesse Andrews75a37652011-09-12 17:09:08 -0700144# (re)create nova.conf
145rm -f $NOVA_DIR/bin/nova.conf
146add_nova_flag "--verbose"
147add_nova_flag "--nodaemon"
148add_nova_flag "--dhcpbridge_flagfile=$NOVA_DIR/bin/nova.conf"
149add_nova_flag "--network_manager=nova.network.manager.$NET_MAN"
150add_nova_flag "--my_ip=$HOST_IP"
151add_nova_flag "--public_interface=$INTERFACE"
152add_nova_flag "--vlan_interface=$INTERFACE"
153add_nova_flag "--sql_connection=$SQL_CONN"
154add_nova_flag "--libvirt_type=$LIBVIRT_TYPE"
155add_nova_flag "--osapi_extensions_path=$API_DIR/extensions"
156add_nova_flag "--vncproxy_url=http://$HOST_IP:6080"
157add_nova_flag "--vncproxy_wwwroot=$NOVNC_DIR/noVNC/noVNC"
158add_nova_flag "--api_paste_config=$KEYSTONE_DIR/examples/paste/nova-api-paste.ini"
159add_nova_flag "--image_service=nova.image.glance.GlanceImageService"
160if [ -n "$FLAT_INTERFACE" ]; then
161 add_nova_flag "--flat_interface=$FLAT_INTERFACE"
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700162fi
163
Jesse Andrews75a37652011-09-12 17:09:08 -0700164# create a new named screen to store things in
165screen -d -m -S nova -t nova
166sleep 1
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700167
Jesse Andrews75a37652011-09-12 17:09:08 -0700168# Clean out the instances directory
169rm -rf $NOVA_DIR/instances/*
170
171# delete traces of nova networks from prior runs
172killall dnsmasq || true
173rm -rf $NOVA_DIR/networks
174mkdir -p $NOVA_DIR/networks
175
176# (re)create nova database
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700177mysql -p$MYSQL_PASS -e 'DROP DATABASE nova;'
178mysql -p$MYSQL_PASS -e 'CREATE DATABASE nova;'
Jesse Andrews75a37652011-09-12 17:09:08 -0700179$NOVA_DIR/bin/nova-manage db sync
180
181# initialize keystone with default users/endpoints
Jesse Andrews75a37652011-09-12 17:09:08 -0700182rm -f /opt/keystone/keystone.db
Jesse Andrews73e27b82011-09-12 17:55:00 -0700183BIN_DIR=$KEYSTONE_DIR/bin bash $DIR/files/keystone_data.sh
Jesse Andrews75a37652011-09-12 17:09:08 -0700184
185# create a small network
186$NOVA_DIR/bin/nova-manage network create private $FIXED_RANGE 1 32
187
188# create some floating ips
189$NOVA_DIR/bin/nova-manage floating create $FLOATING_RANGE
190
191# delete existing glance images/database. Glance will recreate the db
192# when it is ran.
193rm -rf /var/lib/glance/images/*
194rm -f $GLANCE_DIR/glance.sqlite
195
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700196# nova api crashes if we start it with a regular screen command,
197# so send the start command by forcing text into the window.
198function screen_it {
199 screen -S nova -X screen -t $1
200 screen -S nova -p $1 -X stuff "$2$NL"
201}
202
Jesse Andrews75a37652011-09-12 17:09:08 -0700203screen_it g-api "cd $GLANCE_DIR; bin/glance-api --config-file=etc/glance-api.conf"
204screen_it g-reg "cd $GLANCE_DIR; bin/glance-registry --config-file=etc/glance-registry.conf"
Jesse Andrews75a37652011-09-12 17:09:08 -0700205screen_it key "$KEYSTONE_DIR/bin/keystone --config-file $KEYSTONE_DIR/etc/keystone.conf"
Jesse Andrews55508d62011-09-12 19:00:28 -0700206screen_it n-api "$NOVA_DIR/bin/nova-api"
207screen_it n-cpu "$NOVA_DIR/bin/nova-compute"
208screen_it n-net "$NOVA_DIR/bin/nova-network"
209screen_it n-sch "$NOVA_DIR/bin/nova-scheduler"
210screen_it n-vnc "$NOVA_DIR/bin/nova-vncproxy"
Jesse Andrews75a37652011-09-12 17:09:08 -0700211screen_it dash "/etc/init.d/apache2 restart; tail -f /var/log/apache2/error.log"
212
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700213
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700214# ---- download an install images ----
215
216mkdir -p $DEST/images
217cd $DEST/images
218# prepare initial images for loading into glance
219if [ ! -f $DEST/tty.tgz ]; then
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700220 wget -c http://images.ansolabs.com/tty.tgz -O $DEST/tty.tgz
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700221fi
222
223# extract ami-tty/image, aki-tty/image & ari-tty/image
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700224tar -zxf $DEST/tty.tgz
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700225
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700226# add images to glance
227# FIXME: kernel/ramdisk is hardcoded - use return result from add
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700228glance add name="tty-kernel" is_public=true container_format=aki disk_format=aki < aki-tty/image
229glance add name="tty-ramdisk" is_public=true container_format=ari disk_format=ari < ari-tty/image
230glance 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 -0700231