blob: 7eadf26ccc917d3512f3ec2987c274ea5f51e432 [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 Andrewsdfcd2002011-09-13 13:17:22 -0700127## FIXME(ja): should LIBVIRT_TYPE be kvm if kvm module is loaded?
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700128
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700129# add useful screenrc
130cp $DIR/files/screenrc ~/.screenrc
Jesse Andrews6f3baaf2011-09-12 11:59:38 -0700131
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700132# TODO: update current user to allow sudo for all commands in files/sudo/*
133
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700134
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700135# Dashboard
136# ---------
137#
138# Setup the django application to serve via apache/wsgi
Jesse Andrews75a37652011-09-12 17:09:08 -0700139
140# Dash currently imports quantum even if you aren't using it. Instead
141# of installing quantum we can create a simple module that will pass the
142# initial imports
Jesse Andrews834531c2011-09-12 19:37:57 -0700143mkdir $DASH_DIR/openstack-dashboard/quantum || true
Jesse Andrews75a37652011-09-12 17:09:08 -0700144touch $DASH_DIR/openstack-dashboard/quantum/__init__.py
145touch $DASH_DIR/openstack-dashboard/quantum/client.py
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700146
Jesse Andrews75a37652011-09-12 17:09:08 -0700147cd $DASH_DIR/openstack-dashboard
148cp local/local_settings.py.example local/local_settings.py
149dashboard/manage.py syncdb
150
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700151# create an empty directory that apache uses as docroot
Jesse Andrews75a37652011-09-12 17:09:08 -0700152mkdir $DASH_DIR/.blackhole
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700153
Anthony Young76d5dc72011-09-13 17:00:00 -0700154## Configure apache's 000-default to run dashboard
155sudo cp $DIR/files/000-default.template /etc/apache2/sites-enabled/000-default
Anthony Young4da66862011-09-13 17:08:12 -0700156sudo sed -e "s,%DASH_DIR%,$DASH_DIR,g" -i /etc/apache2/sites-enabled/000-default
Jesse Andrews18d350d2011-09-12 21:46:12 -0700157
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700158# ``python setup.py develop`` left some files owned by root in ``DASH_DIR`` and
Jesse Andrews18d350d2011-09-12 21:46:12 -0700159# others by the original owner. We need to change the owner to apache so
160# dashboard can run
161sudo chown -R www-data:www-data $DASH_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -0700162
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700163
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700164# Glance
165# ------
166
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700167# Glance uses ``/var/lib/glance`` and ``/var/log/glance`` by default, so
168# we need to insure that our user has permissions to use them.
Jesse Andrews9053d6a2011-09-12 22:13:11 -0700169sudo mkdir -p /var/log/glance
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700170sudo chown -R `whoami` /var/log/glance
171sudo mkdir -p /var/lib/glance
172sudo chown -R `whoami` /var/lib/glance
Jesse Andrews75a37652011-09-12 17:09:08 -0700173
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700174# Delete existing images/database as glance will recreate the db on startup
175rm -rf /var/lib/glance/images/*
Anthony Youngb6838a12011-09-13 17:13:32 -0700176# (re)create glance database
177mysql -uroot -p$MYSQL_PASS -e 'DROP DATABASE glance;' || true
178mysql -uroot -p$MYSQL_PASS -e 'CREATE DATABASE glance;'
179# Copy over our glance-registry.conf
180cp $DIR/files/glance-registry.conf $GLANCE_DIR/etc/glance-registry.conf
Jesse Andrews75a37652011-09-12 17:09:08 -0700181
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700182# Nova
183# ----
184
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700185function add_nova_flag {
186 echo "$1" >> $NOVA_DIR/bin/nova.conf
187}
188
Jesse Andrews75a37652011-09-12 17:09:08 -0700189# (re)create nova.conf
190rm -f $NOVA_DIR/bin/nova.conf
191add_nova_flag "--verbose"
192add_nova_flag "--nodaemon"
193add_nova_flag "--dhcpbridge_flagfile=$NOVA_DIR/bin/nova.conf"
194add_nova_flag "--network_manager=nova.network.manager.$NET_MAN"
195add_nova_flag "--my_ip=$HOST_IP"
196add_nova_flag "--public_interface=$INTERFACE"
197add_nova_flag "--vlan_interface=$INTERFACE"
198add_nova_flag "--sql_connection=$SQL_CONN"
199add_nova_flag "--libvirt_type=$LIBVIRT_TYPE"
200add_nova_flag "--osapi_extensions_path=$API_DIR/extensions"
201add_nova_flag "--vncproxy_url=http://$HOST_IP:6080"
Anthony Young1f81db62011-09-13 03:35:00 -0700202add_nova_flag "--vncproxy_wwwroot=$NOVNC_DIR/"
Jesse Andrews75a37652011-09-12 17:09:08 -0700203add_nova_flag "--api_paste_config=$KEYSTONE_DIR/examples/paste/nova-api-paste.ini"
204add_nova_flag "--image_service=nova.image.glance.GlanceImageService"
205if [ -n "$FLAT_INTERFACE" ]; then
206 add_nova_flag "--flat_interface=$FLAT_INTERFACE"
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700207fi
208
Jesse Andrews75a37652011-09-12 17:09:08 -0700209# create a new named screen to store things in
210screen -d -m -S nova -t nova
211sleep 1
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700212
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700213# setup nova instance directory
214mkdir -p $NOVA_DIR/instances
215
216# if there is a partition labeled nova-instances use it (ext filesystems
217# can be labeled via e2label)
218## FIXME: if already mounted this blows up...
219if [ -L /dev/disk/by-label/nova-instances ]; then
220 sudo mount -L nova-instances $NOVA_DIR/instances
221 sudo chown -R `whoami` $NOVA_DIR/instances
222fi
223
Jesse Andrews75a37652011-09-12 17:09:08 -0700224# Clean out the instances directory
225rm -rf $NOVA_DIR/instances/*
226
227# delete traces of nova networks from prior runs
228killall dnsmasq || true
229rm -rf $NOVA_DIR/networks
230mkdir -p $NOVA_DIR/networks
231
232# (re)create nova database
Jesse Andrews18d350d2011-09-12 21:46:12 -0700233mysql -uroot -p$MYSQL_PASS -e 'DROP DATABASE nova;' || true
234mysql -uroot -p$MYSQL_PASS -e 'CREATE DATABASE nova;'
Jesse Andrewse8d9cd82011-09-13 15:16:26 -0700235$NOVA_DIR/bin/nova-manage db sync
236
237# create a small network
238$NOVA_DIR/bin/nova-manage network create private $FIXED_RANGE 1 32
239
240# create some floating ips
241$NOVA_DIR/bin/nova-manage floating create $FLOATING_RANGE
242
243# Keystone
244# --------
245
246# (re)create keystone database
Anthony Young3a093122011-09-13 19:01:45 +0000247mysql -uroot -p$MYSQL_PASS -e 'DROP DATABASE keystone;' || true
248mysql -uroot -p$MYSQL_PASS -e 'CREATE DATABASE keystone;'
Jesse Andrews75a37652011-09-12 17:09:08 -0700249
Anthony Young3a093122011-09-13 19:01:45 +0000250# FIXME (anthony) keystone should use keystone.conf.example
251KEYSTONE_CONF=$KEYSTONE_DIR/etc/keystone.conf
252cp $DIR/files/keystone.conf $KEYSTONE_CONF
253
Jesse Andrews75a37652011-09-12 17:09:08 -0700254# initialize keystone with default users/endpoints
Jesse Andrews73e27b82011-09-12 17:55:00 -0700255BIN_DIR=$KEYSTONE_DIR/bin bash $DIR/files/keystone_data.sh
Jesse Andrews75a37652011-09-12 17:09:08 -0700256
Jesse Andrews75a37652011-09-12 17:09:08 -0700257
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700258# Launch Services
259# ===============
Jesse Andrews30f68e92011-09-13 00:59:54 -0700260
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700261# nova api crashes if we start it with a regular screen command,
262# so send the start command by forcing text into the window.
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700263# Only run the services specified in ``ENABLED_SERVICES``
264
265NL=`echo -ne '\015'`
266
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700267function screen_it {
Anthony Young292e46d2011-09-13 11:28:56 -0700268 if [[ "$ENABLED_SERVICES" =~ "$1" ]]; then
269 screen -S nova -X screen -t $1
270 screen -S nova -p $1 -X stuff "$2$NL"
271 fi
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700272}
273
Jesse Andrews75a37652011-09-12 17:09:08 -0700274screen_it g-api "cd $GLANCE_DIR; bin/glance-api --config-file=etc/glance-api.conf"
275screen_it g-reg "cd $GLANCE_DIR; bin/glance-registry --config-file=etc/glance-registry.conf"
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700276# keystone drops a keystone.log where if it is run, so change the path to
277# where it can write
Anthony Young3a093122011-09-13 19:01:45 +0000278screen_it key "cd /tmp; $KEYSTONE_DIR/bin/keystone --config-file $KEYSTONE_CONF"
Jesse Andrews55508d62011-09-12 19:00:28 -0700279screen_it n-api "$NOVA_DIR/bin/nova-api"
280screen_it n-cpu "$NOVA_DIR/bin/nova-compute"
281screen_it n-net "$NOVA_DIR/bin/nova-network"
282screen_it n-sch "$NOVA_DIR/bin/nova-scheduler"
Anthony Young1f81db62011-09-13 03:35:00 -0700283# nova-vncproxy binds a privileged port, and so needs sudo
284screen_it n-vnc "sudo $NOVA_DIR/bin/nova-vncproxy"
Anthony Young8fbba912011-09-13 09:20:58 -0700285screen_it dash "sudo /etc/init.d/apache2 restart; sudo tail -f /var/log/apache2/error.log"
Jesse Andrews75a37652011-09-12 17:09:08 -0700286
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700287# Install Images
288# ==============
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700289
Jesse Andrews30f68e92011-09-13 00:59:54 -0700290# Downloads a tty image (ami/aki/ari style), then extracts it. Upon extraction
291# we upload to glance with the glance cli tool.
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700292
293mkdir -p $DEST/images
294cd $DEST/images
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700295if [ ! -f $DEST/tty.tgz ]; then
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700296 wget -c http://images.ansolabs.com/tty.tgz -O $DEST/tty.tgz
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700297fi
298
299# extract ami-tty/image, aki-tty/image & ari-tty/image
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700300tar -zxf $DEST/tty.tgz
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700301
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700302# add images to glance
303# FIXME: kernel/ramdisk is hardcoded - use return result from add
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700304glance add name="tty-kernel" is_public=true container_format=aki disk_format=aki < aki-tty/image
305glance add name="tty-ramdisk" is_public=true container_format=ari disk_format=ari < ari-tty/image
306glance 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 -0700307