blob: 2e97ef0e27fd449f3a94ff1e5d0eeb1e6e497a99 [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
Dean Troyer0017c8f2011-09-13 15:37:50 -050037MUNIN_DIR=$DEST/openstack-munin
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
Dean Troyer2a15a7c2011-09-13 13:22:14 -050041 HOST_IP=`LC_ALL=C /sbin/ifconfig | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
Jesse Andrewsba23cc72011-09-11 03:22:13 -070042fi
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
Dean Troyer0017c8f2011-09-13 15:37:50 -0500105# openstack-munin is a collection of munin plugins for monitoring the stack
106git_clone https://github.com/cloudbuilders/openstack-munin.git $MUNIN_DIR
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700107
Jesse Andrews30f68e92011-09-13 00:59:54 -0700108# Initialization
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700109# ==============
Jesse Andrews30f68e92011-09-13 00:59:54 -0700110
Jesse Andrews75a37652011-09-12 17:09:08 -0700111# setup our checkouts so they are installed into python path
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700112# allowing ``import nova`` or ``import glance.client``
Dean Troyer0017c8f2011-09-13 15:37:50 -0500113cd $NOVA_DIR; sudo python setup.py develop
Jesse Andrews18d350d2011-09-12 21:46:12 -0700114cd $NOVACLIENT_DIR; sudo python setup.py develop
115cd $KEYSTONE_DIR; sudo python setup.py develop
116cd $GLANCE_DIR; sudo python setup.py develop
117cd $API_DIR; sudo python setup.py develop
118cd $DASH_DIR/django-openstack; sudo python setup.py develop
119cd $DASH_DIR/openstack-dashboard; sudo python setup.py develop
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700120
Jesse Andrews75a37652011-09-12 17:09:08 -0700121# attempt to load modules: kvm (hardware virt) and nbd (network block
122# device - used to manage qcow images)
Jesse Andrews18d350d2011-09-12 21:46:12 -0700123sudo modprobe nbd || true
124sudo modprobe kvm || true
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700125# user needs to be member of libvirtd group for nova-compute to use libvirt
126sudo usermod -a -G libvirtd `whoami`
Jesse Andrews75a37652011-09-12 17:09:08 -0700127# if kvm wasn't running before we need to restart libvirt to enable it
Jesse Andrews18d350d2011-09-12 21:46:12 -0700128sudo /etc/init.d/libvirt-bin restart
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700129
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700130# FIXME(ja): should LIBVIRT_TYPE be kvm if kvm module is loaded?
131
Jesse Andrews75a37652011-09-12 17:09:08 -0700132# setup nova instance directory
133mkdir -p $NOVA_DIR/instances
Jesse Andrews6f3baaf2011-09-12 11:59:38 -0700134
Jesse Andrews75a37652011-09-12 17:09:08 -0700135# if there is a partition labeled nova-instances use it (ext filesystems
136# can be labeled via e2label)
Jesse Andrews834531c2011-09-12 19:37:57 -0700137# FIXME: if already mounted this blows up...
Jesse Andrews75a37652011-09-12 17:09:08 -0700138if [ -L /dev/disk/by-label/nova-instances ]; then
Jesse Andrews18d350d2011-09-12 21:46:12 -0700139 sudo mount -L nova-instances $NOVA_DIR/instances
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700140 sudo chown -R `whoami` $NOVA_DIR/instances
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700141fi
142
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700143# Dashboard
144# ---------
145#
146# Setup the django application to serve via apache/wsgi
Jesse Andrews75a37652011-09-12 17:09:08 -0700147
148# Dash currently imports quantum even if you aren't using it. Instead
149# of installing quantum we can create a simple module that will pass the
150# initial imports
Jesse Andrews834531c2011-09-12 19:37:57 -0700151mkdir $DASH_DIR/openstack-dashboard/quantum || true
Dean Troyer2a15a7c2011-09-13 13:22:14 -0500152touch $DASH_DIR/openstack-dashboard/quantum/__init__.py || true
153touch $DASH_DIR/openstack-dashboard/quantum/client.py || true
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700154
Jesse Andrews75a37652011-09-12 17:09:08 -0700155cd $DASH_DIR/openstack-dashboard
Dean Troyer2a15a7c2011-09-13 13:22:14 -0500156[ ! -r local/local_settings.py ] && cp local/local_settings.py.example local/local_settings.py
Jesse Andrews75a37652011-09-12 17:09:08 -0700157dashboard/manage.py syncdb
158
Jesse Andrews30f68e92011-09-13 00:59:54 -0700159# setup apache
Jesse Andrews75a37652011-09-12 17:09:08 -0700160# create an empty directory to use as our
Dean Troyer2a15a7c2011-09-13 13:22:14 -0500161mkdir -p $DASH_DIR/.blackhole
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700162
Jesse Andrews75a37652011-09-12 17:09:08 -0700163# 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 -0700164cat $DIR/files/000-default.template | sed 's/%DASH_DIR%/\/opt\/dash/g' > /tmp/000-default
165sudo mv /tmp/000-default /etc/apache2/sites-enabled
166
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700167# ``python setup.py develop`` left some files owned by root in $DASH_DIR and
Jesse Andrews18d350d2011-09-12 21:46:12 -0700168# others by the original owner. We need to change the owner to apache so
169# dashboard can run
170sudo chown -R www-data:www-data $DASH_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -0700171
Dean Troyer0017c8f2011-09-13 15:37:50 -0500172# Munin
173# -----
174
175# allow connections from other hosts
176sudo sed -i -e '/Allow from localhost/s/localhost.*$/all/' /etc/munin/apache.conf
177
178cat >/tmp/nova <<EOF
179[keystone_*]
Dean Troyer925df4c2011-09-14 10:20:57 -0500180user `whoami`
Dean Troyer0017c8f2011-09-13 15:37:50 -0500181
182[nova_*]
Dean Troyer925df4c2011-09-14 10:20:57 -0500183user `whoami`
Dean Troyer0017c8f2011-09-13 15:37:50 -0500184EOF
185sudo mv /tmp/nova /etc/munin/plugin-conf.d/nova
186
187# configure Munin for Nova plugins
188PLUGINS="keystone_stats nova_floating_ips nova_instance_launched nova_instance_ nova_instance_timing nova_services"
189for i in $PLUGINS; do
190 sudo cp -p $MUNIN_DIR/$i /usr/share/munin/plugins
191 sudo ln -sf /usr/share/munin/plugins/$i /etc/munin/plugins
192done
193sudo mv /etc/munin/plugins/nova_instance_ /etc/munin/plugins/nova_instance_launched
194sudo restart munin-node
195
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700196# Glance
197# ------
198
Jesse Andrews9053d6a2011-09-12 22:13:11 -0700199sudo mkdir -p /var/log/glance
200sudo chown `whoami` /var/log/glance
Jesse Andrews75a37652011-09-12 17:09:08 -0700201
Jesse Andrews75a37652011-09-12 17:09:08 -0700202# add useful screenrc
203cp $DIR/files/screenrc ~/.screenrc
204
205# TODO: update current user to allow sudo for all commands in files/sudo/*
206
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700207# Nova
208# ----
209
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700210NL=`echo -ne '\015'`
211
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700212
213function add_nova_flag {
214 echo "$1" >> $NOVA_DIR/bin/nova.conf
215}
216
Jesse Andrews75a37652011-09-12 17:09:08 -0700217# (re)create nova.conf
218rm -f $NOVA_DIR/bin/nova.conf
219add_nova_flag "--verbose"
220add_nova_flag "--nodaemon"
221add_nova_flag "--dhcpbridge_flagfile=$NOVA_DIR/bin/nova.conf"
222add_nova_flag "--network_manager=nova.network.manager.$NET_MAN"
223add_nova_flag "--my_ip=$HOST_IP"
224add_nova_flag "--public_interface=$INTERFACE"
225add_nova_flag "--vlan_interface=$INTERFACE"
226add_nova_flag "--sql_connection=$SQL_CONN"
227add_nova_flag "--libvirt_type=$LIBVIRT_TYPE"
228add_nova_flag "--osapi_extensions_path=$API_DIR/extensions"
229add_nova_flag "--vncproxy_url=http://$HOST_IP:6080"
Anthony Young1f81db62011-09-13 03:35:00 -0700230add_nova_flag "--vncproxy_wwwroot=$NOVNC_DIR/"
Jesse Andrews75a37652011-09-12 17:09:08 -0700231add_nova_flag "--api_paste_config=$KEYSTONE_DIR/examples/paste/nova-api-paste.ini"
232add_nova_flag "--image_service=nova.image.glance.GlanceImageService"
233if [ -n "$FLAT_INTERFACE" ]; then
234 add_nova_flag "--flat_interface=$FLAT_INTERFACE"
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700235fi
236
Jesse Andrews75a37652011-09-12 17:09:08 -0700237# create a new named screen to store things in
238screen -d -m -S nova -t nova
239sleep 1
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700240
Jesse Andrews75a37652011-09-12 17:09:08 -0700241# Clean out the instances directory
242rm -rf $NOVA_DIR/instances/*
243
244# delete traces of nova networks from prior runs
245killall dnsmasq || true
246rm -rf $NOVA_DIR/networks
247mkdir -p $NOVA_DIR/networks
248
249# (re)create nova database
Jesse Andrews18d350d2011-09-12 21:46:12 -0700250mysql -uroot -p$MYSQL_PASS -e 'DROP DATABASE nova;' || true
251mysql -uroot -p$MYSQL_PASS -e 'CREATE DATABASE nova;'
Jesse Andrews75a37652011-09-12 17:09:08 -0700252$NOVA_DIR/bin/nova-manage db sync
253
254# initialize keystone with default users/endpoints
Jesse Andrews75a37652011-09-12 17:09:08 -0700255rm -f /opt/keystone/keystone.db
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700256# FIXME keystone creates a keystone.log wherever you run it from (bugify)
257cd /tmp
Jesse Andrews73e27b82011-09-12 17:55:00 -0700258BIN_DIR=$KEYSTONE_DIR/bin bash $DIR/files/keystone_data.sh
Jesse Andrews75a37652011-09-12 17:09:08 -0700259
260# create a small network
261$NOVA_DIR/bin/nova-manage network create private $FIXED_RANGE 1 32
262
263# create some floating ips
264$NOVA_DIR/bin/nova-manage floating create $FLOATING_RANGE
265
266# delete existing glance images/database. Glance will recreate the db
267# when it is ran.
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700268# FIXME: configure glance not to shove files in /var/lib/glance?
269sudo mkdir -p /var/lib/glance
270sudo chown -R `whoami` /var/lib/glance
271rm -rf /var/lib/glance/images/*
Jesse Andrews75a37652011-09-12 17:09:08 -0700272rm -f $GLANCE_DIR/glance.sqlite
273
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700274# Launch Services
275# ===============
Jesse Andrews30f68e92011-09-13 00:59:54 -0700276
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700277# nova api crashes if we start it with a regular screen command,
278# so send the start command by forcing text into the window.
279function screen_it {
280 screen -S nova -X screen -t $1
281 screen -S nova -p $1 -X stuff "$2$NL"
282}
283
Jesse Andrews75a37652011-09-12 17:09:08 -0700284screen_it g-api "cd $GLANCE_DIR; bin/glance-api --config-file=etc/glance-api.conf"
285screen_it g-reg "cd $GLANCE_DIR; bin/glance-registry --config-file=etc/glance-registry.conf"
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700286# keystone drops a keystone.log where if it is run, so change the path to
287# where it can write
288screen_it key "cd /tmp; $KEYSTONE_DIR/bin/keystone --config-file $KEYSTONE_DIR/etc/keystone.conf"
Jesse Andrews55508d62011-09-12 19:00:28 -0700289screen_it n-api "$NOVA_DIR/bin/nova-api"
290screen_it n-cpu "$NOVA_DIR/bin/nova-compute"
291screen_it n-net "$NOVA_DIR/bin/nova-network"
292screen_it n-sch "$NOVA_DIR/bin/nova-scheduler"
Anthony Young1f81db62011-09-13 03:35:00 -0700293# nova-vncproxy binds a privileged port, and so needs sudo
294screen_it n-vnc "sudo $NOVA_DIR/bin/nova-vncproxy"
Dean Troyer0017c8f2011-09-13 15:37:50 -0500295screen_it dash "sudo /etc/init.d/apache2 restart; sudo tail -f /var/log/apache2/error.log"
Jesse Andrews75a37652011-09-12 17:09:08 -0700296
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700297# Install Images
298# ==============
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700299
Jesse Andrews30f68e92011-09-13 00:59:54 -0700300# Downloads a tty image (ami/aki/ari style), then extracts it. Upon extraction
301# we upload to glance with the glance cli tool.
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700302
303mkdir -p $DEST/images
304cd $DEST/images
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700305if [ ! -f $DEST/tty.tgz ]; then
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700306 wget -c http://images.ansolabs.com/tty.tgz -O $DEST/tty.tgz
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700307fi
308
309# extract ami-tty/image, aki-tty/image & ari-tty/image
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700310tar -zxf $DEST/tty.tgz
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700311
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700312# add images to glance
313# FIXME: kernel/ramdisk is hardcoded - use return result from add
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700314glance add name="tty-kernel" is_public=true container_format=aki disk_format=aki < aki-tty/image
315glance add name="tty-ramdisk" is_public=true container_format=ari disk_format=ari < ari-tty/image
316glance 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 -0700317