blob: 8e871de7faf33cd63230d23308376d43fe50641a [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 Andrewsbe395c12011-09-12 19:11:30 -0700127# FIXME(ja): should LIBVIRT_TYPE be kvm if kvm module is loaded?
128
Jesse Andrews75a37652011-09-12 17:09:08 -0700129# setup nova instance directory
130mkdir -p $NOVA_DIR/instances
Jesse Andrews6f3baaf2011-09-12 11:59:38 -0700131
Jesse Andrews75a37652011-09-12 17:09:08 -0700132# if there is a partition labeled nova-instances use it (ext filesystems
133# can be labeled via e2label)
Jesse Andrews834531c2011-09-12 19:37:57 -0700134# FIXME: if already mounted this blows up...
Jesse Andrews75a37652011-09-12 17:09:08 -0700135if [ -L /dev/disk/by-label/nova-instances ]; then
Jesse Andrews18d350d2011-09-12 21:46:12 -0700136 sudo mount -L nova-instances $NOVA_DIR/instances
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700137 sudo chown -R `whoami` $NOVA_DIR/instances
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700138fi
139
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700140# Dashboard
141# ---------
142#
143# Setup the django application to serve via apache/wsgi
Jesse Andrews75a37652011-09-12 17:09:08 -0700144
145# Dash currently imports quantum even if you aren't using it. Instead
146# of installing quantum we can create a simple module that will pass the
147# initial imports
Jesse Andrews834531c2011-09-12 19:37:57 -0700148mkdir $DASH_DIR/openstack-dashboard/quantum || true
Jesse Andrews75a37652011-09-12 17:09:08 -0700149touch $DASH_DIR/openstack-dashboard/quantum/__init__.py
150touch $DASH_DIR/openstack-dashboard/quantum/client.py
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700151
Jesse Andrews75a37652011-09-12 17:09:08 -0700152cd $DASH_DIR/openstack-dashboard
153cp local/local_settings.py.example local/local_settings.py
154dashboard/manage.py syncdb
155
Jesse Andrews30f68e92011-09-13 00:59:54 -0700156# setup apache
Jesse Andrews75a37652011-09-12 17:09:08 -0700157# create an empty directory to use as our
158mkdir $DASH_DIR/.blackhole
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700159
Jesse Andrews75a37652011-09-12 17:09:08 -0700160# 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 -0700161cat $DIR/files/000-default.template | sed 's/%DASH_DIR%/\/opt\/dash/g' > /tmp/000-default
162sudo mv /tmp/000-default /etc/apache2/sites-enabled
163
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700164# ``python setup.py develop`` left some files owned by root in $DASH_DIR and
Jesse Andrews18d350d2011-09-12 21:46:12 -0700165# others by the original owner. We need to change the owner to apache so
166# dashboard can run
167sudo chown -R www-data:www-data $DASH_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -0700168
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700169# Glance
170# ------
171
Jesse Andrews9053d6a2011-09-12 22:13:11 -0700172sudo mkdir -p /var/log/glance
173sudo chown `whoami` /var/log/glance
Jesse Andrews75a37652011-09-12 17:09:08 -0700174
Jesse Andrews75a37652011-09-12 17:09:08 -0700175# add useful screenrc
176cp $DIR/files/screenrc ~/.screenrc
177
178# TODO: update current user to allow sudo for all commands in files/sudo/*
179
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700180# Nova
181# ----
182
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700183NL=`echo -ne '\015'`
184
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700185
186function add_nova_flag {
187 echo "$1" >> $NOVA_DIR/bin/nova.conf
188}
189
Jesse Andrews75a37652011-09-12 17:09:08 -0700190# (re)create nova.conf
191rm -f $NOVA_DIR/bin/nova.conf
192add_nova_flag "--verbose"
193add_nova_flag "--nodaemon"
194add_nova_flag "--dhcpbridge_flagfile=$NOVA_DIR/bin/nova.conf"
195add_nova_flag "--network_manager=nova.network.manager.$NET_MAN"
196add_nova_flag "--my_ip=$HOST_IP"
197add_nova_flag "--public_interface=$INTERFACE"
198add_nova_flag "--vlan_interface=$INTERFACE"
199add_nova_flag "--sql_connection=$SQL_CONN"
200add_nova_flag "--libvirt_type=$LIBVIRT_TYPE"
201add_nova_flag "--osapi_extensions_path=$API_DIR/extensions"
202add_nova_flag "--vncproxy_url=http://$HOST_IP:6080"
Anthony Young1f81db62011-09-13 03:35:00 -0700203add_nova_flag "--vncproxy_wwwroot=$NOVNC_DIR/"
Jesse Andrews75a37652011-09-12 17:09:08 -0700204add_nova_flag "--api_paste_config=$KEYSTONE_DIR/examples/paste/nova-api-paste.ini"
205add_nova_flag "--image_service=nova.image.glance.GlanceImageService"
206if [ -n "$FLAT_INTERFACE" ]; then
207 add_nova_flag "--flat_interface=$FLAT_INTERFACE"
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700208fi
209
Jesse Andrews75a37652011-09-12 17:09:08 -0700210# create a new named screen to store things in
211screen -d -m -S nova -t nova
212sleep 1
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700213
Jesse Andrews75a37652011-09-12 17:09:08 -0700214# Clean out the instances directory
215rm -rf $NOVA_DIR/instances/*
216
217# delete traces of nova networks from prior runs
218killall dnsmasq || true
219rm -rf $NOVA_DIR/networks
220mkdir -p $NOVA_DIR/networks
221
222# (re)create nova database
Jesse Andrews18d350d2011-09-12 21:46:12 -0700223mysql -uroot -p$MYSQL_PASS -e 'DROP DATABASE nova;' || true
224mysql -uroot -p$MYSQL_PASS -e 'CREATE DATABASE nova;'
Jesse Andrews75a37652011-09-12 17:09:08 -0700225$NOVA_DIR/bin/nova-manage db sync
226
227# initialize keystone with default users/endpoints
Jesse Andrews75a37652011-09-12 17:09:08 -0700228rm -f /opt/keystone/keystone.db
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700229# FIXME keystone creates a keystone.log wherever you run it from (bugify)
230cd /tmp
Jesse Andrews73e27b82011-09-12 17:55:00 -0700231BIN_DIR=$KEYSTONE_DIR/bin bash $DIR/files/keystone_data.sh
Jesse Andrews75a37652011-09-12 17:09:08 -0700232
233# create a small network
234$NOVA_DIR/bin/nova-manage network create private $FIXED_RANGE 1 32
235
236# create some floating ips
237$NOVA_DIR/bin/nova-manage floating create $FLOATING_RANGE
238
239# delete existing glance images/database. Glance will recreate the db
240# when it is ran.
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700241# FIXME: configure glance not to shove files in /var/lib/glance?
242sudo mkdir -p /var/lib/glance
243sudo chown -R `whoami` /var/lib/glance
244rm -rf /var/lib/glance/images/*
Jesse Andrews75a37652011-09-12 17:09:08 -0700245rm -f $GLANCE_DIR/glance.sqlite
246
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700247# Launch Services
248# ===============
Jesse Andrews30f68e92011-09-13 00:59:54 -0700249
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700250# nova api crashes if we start it with a regular screen command,
251# so send the start command by forcing text into the window.
252function screen_it {
Anthony Young292e46d2011-09-13 11:28:56 -0700253 # only run the services specified in $ENABLED_SERVICES
254 if [[ "$ENABLED_SERVICES" =~ "$1" ]]; then
255 screen -S nova -X screen -t $1
256 screen -S nova -p $1 -X stuff "$2$NL"
257 fi
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700258}
259
Jesse Andrews75a37652011-09-12 17:09:08 -0700260screen_it g-api "cd $GLANCE_DIR; bin/glance-api --config-file=etc/glance-api.conf"
261screen_it g-reg "cd $GLANCE_DIR; bin/glance-registry --config-file=etc/glance-registry.conf"
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700262# keystone drops a keystone.log where if it is run, so change the path to
263# where it can write
264screen_it key "cd /tmp; $KEYSTONE_DIR/bin/keystone --config-file $KEYSTONE_DIR/etc/keystone.conf"
Jesse Andrews55508d62011-09-12 19:00:28 -0700265screen_it n-api "$NOVA_DIR/bin/nova-api"
266screen_it n-cpu "$NOVA_DIR/bin/nova-compute"
267screen_it n-net "$NOVA_DIR/bin/nova-network"
268screen_it n-sch "$NOVA_DIR/bin/nova-scheduler"
Anthony Young1f81db62011-09-13 03:35:00 -0700269# nova-vncproxy binds a privileged port, and so needs sudo
270screen_it n-vnc "sudo $NOVA_DIR/bin/nova-vncproxy"
Anthony Young8fbba912011-09-13 09:20:58 -0700271screen_it dash "sudo /etc/init.d/apache2 restart; sudo tail -f /var/log/apache2/error.log"
Jesse Andrews75a37652011-09-12 17:09:08 -0700272
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700273# Install Images
274# ==============
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700275
Jesse Andrews30f68e92011-09-13 00:59:54 -0700276# Downloads a tty image (ami/aki/ari style), then extracts it. Upon extraction
277# we upload to glance with the glance cli tool.
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700278
279mkdir -p $DEST/images
280cd $DEST/images
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700281if [ ! -f $DEST/tty.tgz ]; then
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700282 wget -c http://images.ansolabs.com/tty.tgz -O $DEST/tty.tgz
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700283fi
284
285# extract ami-tty/image, aki-tty/image & ari-tty/image
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700286tar -zxf $DEST/tty.tgz
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700287
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700288# add images to glance
289# FIXME: kernel/ramdisk is hardcoded - use return result from add
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700290glance add name="tty-kernel" is_public=true container_format=aki disk_format=aki < aki-tty/image
291glance add name="tty-ramdisk" is_public=true container_format=ari disk_format=ari < ari-tty/image
292glance 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 -0700293