blob: 4d54c3d9c0bced9d55d185e8bc5e109fb1d269c5 [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``
Anthony Young963d2eb2011-09-13 17:29:02 -070015# or simply ``./stack.sh``
Jesse Andrewsd74257d2011-09-13 01:24:50 -070016
17# This script exits on an error so that errors don't compound and you see
18# only the first error that occured.
Jesse Andrewsba23cc72011-09-11 03:22:13 -070019set -o errexit
20
Jesse Andrewsd74257d2011-09-13 01:24:50 -070021# Print the commands being run so that we can see the command that triggers
22# an error. It is also useful for following allowing as the install occurs.
Jesse Andrewsba23cc72011-09-11 03:22:13 -070023set -o xtrace
24
Jesse Andrewsd74257d2011-09-13 01:24:50 -070025# Important paths: ``DIR`` is where we are executing from and ``DEST`` is
26# where we are installing openstack.
Jesse Andrewsba23cc72011-09-11 03:22:13 -070027DIR=`pwd`
28DEST=/opt
Jesse Andrewsba23cc72011-09-11 03:22:13 -070029
Jesse Andrews6f3baaf2011-09-12 11:59:38 -070030# Set the destination directories for openstack projects
Jesse Andrewsba23cc72011-09-11 03:22:13 -070031NOVA_DIR=$DEST/nova
32DASH_DIR=$DEST/dash
33GLANCE_DIR=$DEST/glance
34KEYSTONE_DIR=$DEST/keystone
35NOVACLIENT_DIR=$DEST/python-novaclient
36API_DIR=$DEST/openstackx
37NOVNC_DIR=$DEST/noVNC
Anthony Youngbdbe6d92011-09-13 09:43:46 -070038ENABLED_SERVICES=g-api,g-reg,key,n-api,n-cpu,n-net,n-sch,n-vnc,dash
Jesse Andrewsba23cc72011-09-11 03:22:13 -070039
Jesse Andrewsd74257d2011-09-13 01:24:50 -070040# Use the first IP unless an explicit is set by ``HOST_IP`` environment variable
Jesse Andrewsba23cc72011-09-11 03:22:13 -070041if [ ! -n "$HOST_IP" ]; then
42 HOST_IP=`LC_ALL=C ifconfig | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
43fi
44
Jesse Andrewsd74257d2011-09-13 01:24:50 -070045# Nova network configuration
Jesse Andrewsba23cc72011-09-11 03:22:13 -070046INTERFACE=${INTERFACE:-eth0}
47FLOATING_RANGE=${FLOATING_RANGE:-10.6.0.0/27}
48FIXED_RANGE=${FIXED_RANGE:-10.0.0.0/24}
Jesse Andrewsba23cc72011-09-11 03:22:13 -070049NET_MAN=${NET_MAN:-VlanManager}
Jesse Andrews30f68e92011-09-13 00:59:54 -070050
Jesse Andrewsd74257d2011-09-13 01:24:50 -070051# If you are using FlatDHCP on multiple hosts, set the ``FLAT_INTERFACE``
52# variable but make sure that the interface doesn't already have an
53# ip or you risk breaking things.
Jesse Andrewsba23cc72011-09-11 03:22:13 -070054# FLAT_INTERFACE=eth0
55
Jesse Andrewsd74257d2011-09-13 01:24:50 -070056# Nova hypervisor configuration
57LIBVIRT_TYPE=${LIBVIRT_TYPE:-qemu}
58
59
Jesse Andrews2caf8fd2011-09-12 16:15:11 -070060# TODO: switch to mysql for all services
Jesse Andrews1c1d1502011-09-12 19:29:56 -070061MYSQL_PASS=${MYSQL_PASS:-nova}
62SQL_CONN=${SQL_CONN:-mysql://root:$MYSQL_PASS@localhost/nova}
63# TODO: set rabbitmq conn string explicitly as well
Jesse Andrewsba23cc72011-09-11 03:22:13 -070064
Jesse Andrews30f68e92011-09-13 00:59:54 -070065# Install Packages
Jesse Andrewsd74257d2011-09-13 01:24:50 -070066# ================
Jesse Andrews30f68e92011-09-13 00:59:54 -070067#
68# Openstack uses a fair number of other projects.
69
Jesse Andrewsd74257d2011-09-13 01:24:50 -070070# Seed configuration with mysql password so that apt-get install doesn't
71# prompt us for a password upon install.
Jesse Andrews18d350d2011-09-12 21:46:12 -070072cat <<MYSQL_PRESEED | sudo debconf-set-selections
Jesse Andrews1c1d1502011-09-12 19:29:56 -070073mysql-server-5.1 mysql-server/root_password password $MYSQL_PASS
74mysql-server-5.1 mysql-server/root_password_again password $MYSQL_PASS
75mysql-server-5.1 mysql-server/start_on_boot boolean true
76MYSQL_PRESEED
Jesse Andrews2caf8fd2011-09-12 16:15:11 -070077
Jesse Andrews75a37652011-09-12 17:09:08 -070078# install apt requirements
Jesse Andrews18d350d2011-09-12 21:46:12 -070079sudo apt-get install -y -q `cat $DIR/apts/* | cut -d\# -f1`
Jesse Andrewsba23cc72011-09-11 03:22:13 -070080
Jesse Andrews75a37652011-09-12 17:09:08 -070081# install python requirements
Anthony Young1bbd9e02011-09-12 23:59:19 -070082sudo PIP_DOWNLOAD_CACHE=/var/cache/pip pip install `cat $DIR/pips/*`
Jesse Andrewsba23cc72011-09-11 03:22:13 -070083
Jesse Andrews61632572011-09-12 17:40:00 -070084# git clone only if directory doesn't exist already
85function git_clone {
86 if [ ! -d $2 ]; then
87 git clone $1 $2
88 fi
89}
90
Jesse Andrews75a37652011-09-12 17:09:08 -070091# compute service
Jesse Andrews61632572011-09-12 17:40:00 -070092git_clone https://github.com/cloudbuilders/nova.git $NOVA_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070093# image catalog service
Jesse Andrews61632572011-09-12 17:40:00 -070094git_clone https://github.com/cloudbuilders/glance.git $GLANCE_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070095# unified auth system (manages accounts/tokens)
Jesse Andrews61632572011-09-12 17:40:00 -070096git_clone https://github.com/cloudbuilders/keystone.git $KEYSTONE_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070097# a websockets/html5 or flash powered VNC console for vm instances
Jesse Andrews61632572011-09-12 17:40:00 -070098git_clone https://github.com/cloudbuilders/noVNC.git $NOVNC_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070099# django powered web control panel for openstack
Jesse Andrews61632572011-09-12 17:40:00 -0700100git_clone https://github.com/cloudbuilders/openstack-dashboard.git $DASH_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -0700101# python client library to nova that dashboard (and others) use
Jesse Andrews61632572011-09-12 17:40:00 -0700102git_clone https://github.com/cloudbuilders/python-novaclient.git $NOVACLIENT_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -0700103# openstackx is a collection of extensions to openstack.compute & nova
104# that is *deprecated*. The code is being moved into python-novaclient & nova.
Jesse Andrews61632572011-09-12 17:40:00 -0700105git_clone https://github.com/cloudbuilders/openstackx.git $API_DIR
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700106
Jesse Andrews30f68e92011-09-13 00:59:54 -0700107# Initialization
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700108# ==============
Jesse Andrews30f68e92011-09-13 00:59:54 -0700109
Jesse Andrews75a37652011-09-12 17:09:08 -0700110# setup our checkouts so they are installed into python path
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700111# allowing ``import nova`` or ``import glance.client``
Jesse Andrews18d350d2011-09-12 21:46:12 -0700112cd $NOVACLIENT_DIR; sudo python setup.py develop
113cd $KEYSTONE_DIR; sudo python setup.py develop
114cd $GLANCE_DIR; sudo python setup.py develop
115cd $API_DIR; sudo python setup.py develop
116cd $DASH_DIR/django-openstack; sudo python setup.py develop
117cd $DASH_DIR/openstack-dashboard; sudo python setup.py develop
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700118
Jesse Andrews75a37652011-09-12 17:09:08 -0700119# attempt to load modules: kvm (hardware virt) and nbd (network block
120# device - used to manage qcow images)
Jesse Andrews18d350d2011-09-12 21:46:12 -0700121sudo modprobe nbd || true
122sudo modprobe kvm || true
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700123# user needs to be member of libvirtd group for nova-compute to use libvirt
124sudo usermod -a -G libvirtd `whoami`
Jesse Andrews75a37652011-09-12 17:09:08 -0700125# if kvm wasn't running before we need to restart libvirt to enable it
Jesse Andrews18d350d2011-09-12 21:46:12 -0700126sudo /etc/init.d/libvirt-bin restart
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700127
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700128## FIXME(ja): should LIBVIRT_TYPE be kvm if kvm module is loaded?
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700129
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700130# add useful screenrc
131cp $DIR/files/screenrc ~/.screenrc
Jesse Andrews6f3baaf2011-09-12 11:59:38 -0700132
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700133# TODO: update current user to allow sudo for all commands in files/sudo/*
134
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700135
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700136# Dashboard
137# ---------
138#
139# Setup the django application to serve via apache/wsgi
Jesse Andrews75a37652011-09-12 17:09:08 -0700140
141# Dash currently imports quantum even if you aren't using it. Instead
142# of installing quantum we can create a simple module that will pass the
143# initial imports
Anthony Young5d4843c2011-09-13 17:22:18 -0700144sudo mkdir -p $DASH_DIR/openstack-dashboard/quantum || true
145sudo touch $DASH_DIR/openstack-dashboard/quantum/__init__.py
146sudo touch $DASH_DIR/openstack-dashboard/quantum/client.py
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700147
Jesse Andrews75a37652011-09-12 17:09:08 -0700148cd $DASH_DIR/openstack-dashboard
Anthony Young5d4843c2011-09-13 17:22:18 -0700149sudo cp local/local_settings.py.example local/local_settings.py
Jesse Andrews75a37652011-09-12 17:09:08 -0700150dashboard/manage.py syncdb
151
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700152# create an empty directory that apache uses as docroot
Anthony Young5d4843c2011-09-13 17:22:18 -0700153sudo mkdir -p $DASH_DIR/.blackhole
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700154
Anthony Young76d5dc72011-09-13 17:00:00 -0700155## Configure apache's 000-default to run dashboard
156sudo cp $DIR/files/000-default.template /etc/apache2/sites-enabled/000-default
Anthony Young4da66862011-09-13 17:08:12 -0700157sudo sed -e "s,%DASH_DIR%,$DASH_DIR,g" -i /etc/apache2/sites-enabled/000-default
Jesse Andrews18d350d2011-09-12 21:46:12 -0700158
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700159# ``python setup.py develop`` left some files owned by root in ``DASH_DIR`` and
Jesse Andrews18d350d2011-09-12 21:46:12 -0700160# others by the original owner. We need to change the owner to apache so
161# dashboard can run
162sudo chown -R www-data:www-data $DASH_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -0700163
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700164
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700165# Glance
166# ------
167
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700168# Glance uses ``/var/lib/glance`` and ``/var/log/glance`` by default, so
169# we need to insure that our user has permissions to use them.
Jesse Andrews9053d6a2011-09-12 22:13:11 -0700170sudo mkdir -p /var/log/glance
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700171sudo chown -R `whoami` /var/log/glance
172sudo mkdir -p /var/lib/glance
173sudo chown -R `whoami` /var/lib/glance
Jesse Andrews75a37652011-09-12 17:09:08 -0700174
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700175# Delete existing images/database as glance will recreate the db on startup
176rm -rf /var/lib/glance/images/*
Anthony Youngb6838a12011-09-13 17:13:32 -0700177# (re)create glance database
178mysql -uroot -p$MYSQL_PASS -e 'DROP DATABASE glance;' || true
179mysql -uroot -p$MYSQL_PASS -e 'CREATE DATABASE glance;'
180# Copy over our glance-registry.conf
Anthony Youngaf9de3d2011-09-13 19:45:18 -0700181GLANCE_CONF=$GLANCE_DIR/etc/glance-registry.conf
Anthony Young79918c52011-09-13 19:43:14 -0700182cp $DIR/files/glance-registry.conf $GLANCE_CONF
183sudo sed -e "s,%MYSQL_PASS%,$MYSQL_PASS,g" -i $GLANCE_CONF
Jesse Andrews75a37652011-09-12 17:09:08 -0700184
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700185# Nova
186# ----
187
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700188function add_nova_flag {
189 echo "$1" >> $NOVA_DIR/bin/nova.conf
190}
191
Jesse Andrews75a37652011-09-12 17:09:08 -0700192# (re)create nova.conf
193rm -f $NOVA_DIR/bin/nova.conf
194add_nova_flag "--verbose"
195add_nova_flag "--nodaemon"
196add_nova_flag "--dhcpbridge_flagfile=$NOVA_DIR/bin/nova.conf"
197add_nova_flag "--network_manager=nova.network.manager.$NET_MAN"
198add_nova_flag "--my_ip=$HOST_IP"
199add_nova_flag "--public_interface=$INTERFACE"
200add_nova_flag "--vlan_interface=$INTERFACE"
201add_nova_flag "--sql_connection=$SQL_CONN"
202add_nova_flag "--libvirt_type=$LIBVIRT_TYPE"
203add_nova_flag "--osapi_extensions_path=$API_DIR/extensions"
204add_nova_flag "--vncproxy_url=http://$HOST_IP:6080"
Anthony Young1f81db62011-09-13 03:35:00 -0700205add_nova_flag "--vncproxy_wwwroot=$NOVNC_DIR/"
Jesse Andrews75a37652011-09-12 17:09:08 -0700206add_nova_flag "--api_paste_config=$KEYSTONE_DIR/examples/paste/nova-api-paste.ini"
207add_nova_flag "--image_service=nova.image.glance.GlanceImageService"
208if [ -n "$FLAT_INTERFACE" ]; then
209 add_nova_flag "--flat_interface=$FLAT_INTERFACE"
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700210fi
211
Jesse Andrews75a37652011-09-12 17:09:08 -0700212# create a new named screen to store things in
213screen -d -m -S nova -t nova
214sleep 1
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700215
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700216# setup nova instance directory
217mkdir -p $NOVA_DIR/instances
218
219# if there is a partition labeled nova-instances use it (ext filesystems
220# can be labeled via e2label)
221## FIXME: if already mounted this blows up...
222if [ -L /dev/disk/by-label/nova-instances ]; then
223 sudo mount -L nova-instances $NOVA_DIR/instances
224 sudo chown -R `whoami` $NOVA_DIR/instances
225fi
226
Jesse Andrews75a37652011-09-12 17:09:08 -0700227# Clean out the instances directory
228rm -rf $NOVA_DIR/instances/*
229
230# delete traces of nova networks from prior runs
231killall dnsmasq || true
232rm -rf $NOVA_DIR/networks
233mkdir -p $NOVA_DIR/networks
234
235# (re)create nova database
Jesse Andrews18d350d2011-09-12 21:46:12 -0700236mysql -uroot -p$MYSQL_PASS -e 'DROP DATABASE nova;' || true
237mysql -uroot -p$MYSQL_PASS -e 'CREATE DATABASE nova;'
Jesse Andrewse8d9cd82011-09-13 15:16:26 -0700238$NOVA_DIR/bin/nova-manage db sync
239
240# create a small network
241$NOVA_DIR/bin/nova-manage network create private $FIXED_RANGE 1 32
242
243# create some floating ips
244$NOVA_DIR/bin/nova-manage floating create $FLOATING_RANGE
245
246# Keystone
247# --------
248
249# (re)create keystone database
Anthony Young3a093122011-09-13 19:01:45 +0000250mysql -uroot -p$MYSQL_PASS -e 'DROP DATABASE keystone;' || true
251mysql -uroot -p$MYSQL_PASS -e 'CREATE DATABASE keystone;'
Jesse Andrews75a37652011-09-12 17:09:08 -0700252
Anthony Young3a093122011-09-13 19:01:45 +0000253# FIXME (anthony) keystone should use keystone.conf.example
254KEYSTONE_CONF=$KEYSTONE_DIR/etc/keystone.conf
255cp $DIR/files/keystone.conf $KEYSTONE_CONF
Anthony Young79918c52011-09-13 19:43:14 -0700256sudo sed -e "s,%MYSQL_PASS%,$MYSQL_PASS,g" -i $KEYSTONE_CONF
Anthony Young3a093122011-09-13 19:01:45 +0000257
Jesse Andrews75a37652011-09-12 17:09:08 -0700258# initialize keystone with default users/endpoints
Jesse Andrews73e27b82011-09-12 17:55:00 -0700259BIN_DIR=$KEYSTONE_DIR/bin bash $DIR/files/keystone_data.sh
Jesse Andrews75a37652011-09-12 17:09:08 -0700260
Jesse Andrews75a37652011-09-12 17:09:08 -0700261
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700262# Launch Services
263# ===============
Jesse Andrews30f68e92011-09-13 00:59:54 -0700264
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700265# nova api crashes if we start it with a regular screen command,
266# so send the start command by forcing text into the window.
Jesse Andrewsdfcd2002011-09-13 13:17:22 -0700267# Only run the services specified in ``ENABLED_SERVICES``
268
269NL=`echo -ne '\015'`
270
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700271function screen_it {
Anthony Young292e46d2011-09-13 11:28:56 -0700272 if [[ "$ENABLED_SERVICES" =~ "$1" ]]; then
273 screen -S nova -X screen -t $1
274 screen -S nova -p $1 -X stuff "$2$NL"
275 fi
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700276}
277
Jesse Andrews75a37652011-09-12 17:09:08 -0700278screen_it g-api "cd $GLANCE_DIR; bin/glance-api --config-file=etc/glance-api.conf"
279screen_it g-reg "cd $GLANCE_DIR; bin/glance-registry --config-file=etc/glance-registry.conf"
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700280# keystone drops a keystone.log where if it is run, so change the path to
281# where it can write
Anthony Young3a093122011-09-13 19:01:45 +0000282screen_it key "cd /tmp; $KEYSTONE_DIR/bin/keystone --config-file $KEYSTONE_CONF"
Jesse Andrews55508d62011-09-12 19:00:28 -0700283screen_it n-api "$NOVA_DIR/bin/nova-api"
284screen_it n-cpu "$NOVA_DIR/bin/nova-compute"
285screen_it n-net "$NOVA_DIR/bin/nova-network"
286screen_it n-sch "$NOVA_DIR/bin/nova-scheduler"
Anthony Young1f81db62011-09-13 03:35:00 -0700287# nova-vncproxy binds a privileged port, and so needs sudo
288screen_it n-vnc "sudo $NOVA_DIR/bin/nova-vncproxy"
Anthony Young8fbba912011-09-13 09:20:58 -0700289screen_it dash "sudo /etc/init.d/apache2 restart; sudo tail -f /var/log/apache2/error.log"
Jesse Andrews75a37652011-09-12 17:09:08 -0700290
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700291# Install Images
292# ==============
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700293
Jesse Andrews30f68e92011-09-13 00:59:54 -0700294# Downloads a tty image (ami/aki/ari style), then extracts it. Upon extraction
295# we upload to glance with the glance cli tool.
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700296
297mkdir -p $DEST/images
298cd $DEST/images
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700299if [ ! -f $DEST/tty.tgz ]; then
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700300 wget -c http://images.ansolabs.com/tty.tgz -O $DEST/tty.tgz
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700301fi
302
303# extract ami-tty/image, aki-tty/image & ari-tty/image
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700304tar -zxf $DEST/tty.tgz
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700305
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700306# add images to glance
307# FIXME: kernel/ramdisk is hardcoded - use return result from add
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700308glance add name="tty-kernel" is_public=true container_format=aki disk_format=aki < aki-tty/image
309glance add name="tty-ramdisk" is_public=true container_format=ari disk_format=ari < ari-tty/image
310glance 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 -0700311