blob: e82933d7dd1d37fdc8bcc869a385f977ee63b2b4 [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)
Jesse Andrews834531c2011-09-12 19:37:57 -0700105# FIXME: if already mounted this blows up...
Jesse Andrews75a37652011-09-12 17:09:08 -0700106if [ -L /dev/disk/by-label/nova-instances ]; then
Jesse Andrews834531c2011-09-12 19:37:57 -0700107 mount -L nova-instances $NOVA_DIR/instances
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700108fi
109
Jesse Andrews75a37652011-09-12 17:09:08 -0700110# *Dashboard*: setup django application to serve via apache/wsgi
111
112# Dash currently imports quantum even if you aren't using it. Instead
113# of installing quantum we can create a simple module that will pass the
114# initial imports
Jesse Andrews834531c2011-09-12 19:37:57 -0700115mkdir $DASH_DIR/openstack-dashboard/quantum || true
Jesse Andrews75a37652011-09-12 17:09:08 -0700116touch $DASH_DIR/openstack-dashboard/quantum/__init__.py
117touch $DASH_DIR/openstack-dashboard/quantum/client.py
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700118
Jesse Andrews75a37652011-09-12 17:09:08 -0700119cd $DASH_DIR/openstack-dashboard
120cp local/local_settings.py.example local/local_settings.py
121dashboard/manage.py syncdb
122
123# ## Setup Apache
124# create an empty directory to use as our
125mkdir $DASH_DIR/.blackhole
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700126
Jesse Andrews75a37652011-09-12 17:09:08 -0700127# FIXME(ja): can't figure out how to make $DASH_DIR work in sed, also install to available/a2e it
128cat $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 -0700129chown -R www-data:www-data $DASH_DIR
130
131mkdir -p /var/log/glance
132
Jesse Andrews75a37652011-09-12 17:09:08 -0700133# add useful screenrc
134cp $DIR/files/screenrc ~/.screenrc
135
136# TODO: update current user to allow sudo for all commands in files/sudo/*
137
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700138NL=`echo -ne '\015'`
139
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700140
141function add_nova_flag {
142 echo "$1" >> $NOVA_DIR/bin/nova.conf
143}
144
Jesse Andrews75a37652011-09-12 17:09:08 -0700145# (re)create nova.conf
146rm -f $NOVA_DIR/bin/nova.conf
147add_nova_flag "--verbose"
148add_nova_flag "--nodaemon"
149add_nova_flag "--dhcpbridge_flagfile=$NOVA_DIR/bin/nova.conf"
150add_nova_flag "--network_manager=nova.network.manager.$NET_MAN"
151add_nova_flag "--my_ip=$HOST_IP"
152add_nova_flag "--public_interface=$INTERFACE"
153add_nova_flag "--vlan_interface=$INTERFACE"
154add_nova_flag "--sql_connection=$SQL_CONN"
155add_nova_flag "--libvirt_type=$LIBVIRT_TYPE"
156add_nova_flag "--osapi_extensions_path=$API_DIR/extensions"
157add_nova_flag "--vncproxy_url=http://$HOST_IP:6080"
158add_nova_flag "--vncproxy_wwwroot=$NOVNC_DIR/noVNC/noVNC"
159add_nova_flag "--api_paste_config=$KEYSTONE_DIR/examples/paste/nova-api-paste.ini"
160add_nova_flag "--image_service=nova.image.glance.GlanceImageService"
161if [ -n "$FLAT_INTERFACE" ]; then
162 add_nova_flag "--flat_interface=$FLAT_INTERFACE"
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700163fi
164
Jesse Andrews75a37652011-09-12 17:09:08 -0700165# create a new named screen to store things in
166screen -d -m -S nova -t nova
167sleep 1
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700168
Jesse Andrews75a37652011-09-12 17:09:08 -0700169# Clean out the instances directory
170rm -rf $NOVA_DIR/instances/*
171
172# delete traces of nova networks from prior runs
173killall dnsmasq || true
174rm -rf $NOVA_DIR/networks
175mkdir -p $NOVA_DIR/networks
176
177# (re)create nova database
Jesse Andrews834531c2011-09-12 19:37:57 -0700178mysql -p$MYSQL_PASS -e 'DROP DATABASE nova;' || true
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700179mysql -p$MYSQL_PASS -e 'CREATE DATABASE nova;'
Jesse Andrews75a37652011-09-12 17:09:08 -0700180$NOVA_DIR/bin/nova-manage db sync
181
182# initialize keystone with default users/endpoints
Jesse Andrews75a37652011-09-12 17:09:08 -0700183rm -f /opt/keystone/keystone.db
Jesse Andrews73e27b82011-09-12 17:55:00 -0700184BIN_DIR=$KEYSTONE_DIR/bin bash $DIR/files/keystone_data.sh
Jesse Andrews75a37652011-09-12 17:09:08 -0700185
186# create a small network
187$NOVA_DIR/bin/nova-manage network create private $FIXED_RANGE 1 32
188
189# create some floating ips
190$NOVA_DIR/bin/nova-manage floating create $FLOATING_RANGE
191
192# delete existing glance images/database. Glance will recreate the db
193# when it is ran.
194rm -rf /var/lib/glance/images/*
195rm -f $GLANCE_DIR/glance.sqlite
196
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700197# nova api crashes if we start it with a regular screen command,
198# so send the start command by forcing text into the window.
199function screen_it {
200 screen -S nova -X screen -t $1
201 screen -S nova -p $1 -X stuff "$2$NL"
202}
203
Jesse Andrews75a37652011-09-12 17:09:08 -0700204screen_it g-api "cd $GLANCE_DIR; bin/glance-api --config-file=etc/glance-api.conf"
205screen_it g-reg "cd $GLANCE_DIR; bin/glance-registry --config-file=etc/glance-registry.conf"
Jesse Andrews75a37652011-09-12 17:09:08 -0700206screen_it key "$KEYSTONE_DIR/bin/keystone --config-file $KEYSTONE_DIR/etc/keystone.conf"
Jesse Andrews55508d62011-09-12 19:00:28 -0700207screen_it n-api "$NOVA_DIR/bin/nova-api"
208screen_it n-cpu "$NOVA_DIR/bin/nova-compute"
209screen_it n-net "$NOVA_DIR/bin/nova-network"
210screen_it n-sch "$NOVA_DIR/bin/nova-scheduler"
211screen_it n-vnc "$NOVA_DIR/bin/nova-vncproxy"
Jesse Andrews75a37652011-09-12 17:09:08 -0700212screen_it dash "/etc/init.d/apache2 restart; tail -f /var/log/apache2/error.log"
213
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700214
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700215# ---- download an install images ----
216
217mkdir -p $DEST/images
218cd $DEST/images
219# prepare initial images for loading into glance
220if [ ! -f $DEST/tty.tgz ]; then
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700221 wget -c http://images.ansolabs.com/tty.tgz -O $DEST/tty.tgz
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700222fi
223
224# extract ami-tty/image, aki-tty/image & ari-tty/image
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700225tar -zxf $DEST/tty.tgz
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700226
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700227# add images to glance
228# FIXME: kernel/ramdisk is hardcoded - use return result from add
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700229glance add name="tty-kernel" is_public=true container_format=aki disk_format=aki < aki-tty/image
230glance add name="tty-ramdisk" is_public=true container_format=ari disk_format=ari < ari-tty/image
231glance 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 -0700232