blob: 0fe84ad742d29fdfefe6957d9f7b401e2b9d9b9e [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
Anthony Young10039522011-09-13 10:05:07 -070029# Provide option to move aside any old code
30if [ "$CLEAN" = "1"]; then
31 TMPDIR=/tmp/stackbak_`date +%s`
32 mkdir $TMPDIR
33 mv $DEST/* $TMPDIR
34fi
35
Jesse Andrews6f3baaf2011-09-12 11:59:38 -070036# Set the destination directories for openstack projects
Jesse Andrewsba23cc72011-09-11 03:22:13 -070037NOVA_DIR=$DEST/nova
38DASH_DIR=$DEST/dash
39GLANCE_DIR=$DEST/glance
40KEYSTONE_DIR=$DEST/keystone
41NOVACLIENT_DIR=$DEST/python-novaclient
42API_DIR=$DEST/openstackx
43NOVNC_DIR=$DEST/noVNC
Anthony Youngbdbe6d92011-09-13 09:43:46 -070044ENABLED_SERVICES=g-api,g-reg,key,n-api,n-cpu,n-net,n-sch,n-vnc,dash
Jesse Andrewsba23cc72011-09-11 03:22:13 -070045
Jesse Andrewsd74257d2011-09-13 01:24:50 -070046# Use the first IP unless an explicit is set by ``HOST_IP`` environment variable
Jesse Andrewsba23cc72011-09-11 03:22:13 -070047if [ ! -n "$HOST_IP" ]; then
48 HOST_IP=`LC_ALL=C ifconfig | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
49fi
50
Jesse Andrewsd74257d2011-09-13 01:24:50 -070051# Nova network configuration
Jesse Andrewsba23cc72011-09-11 03:22:13 -070052INTERFACE=${INTERFACE:-eth0}
53FLOATING_RANGE=${FLOATING_RANGE:-10.6.0.0/27}
54FIXED_RANGE=${FIXED_RANGE:-10.0.0.0/24}
Jesse Andrewsba23cc72011-09-11 03:22:13 -070055NET_MAN=${NET_MAN:-VlanManager}
Jesse Andrews30f68e92011-09-13 00:59:54 -070056
Jesse Andrewsd74257d2011-09-13 01:24:50 -070057# If you are using FlatDHCP on multiple hosts, set the ``FLAT_INTERFACE``
58# variable but make sure that the interface doesn't already have an
59# ip or you risk breaking things.
Jesse Andrewsba23cc72011-09-11 03:22:13 -070060# FLAT_INTERFACE=eth0
61
Jesse Andrewsd74257d2011-09-13 01:24:50 -070062# Nova hypervisor configuration
63LIBVIRT_TYPE=${LIBVIRT_TYPE:-qemu}
64
65
Jesse Andrews2caf8fd2011-09-12 16:15:11 -070066# TODO: switch to mysql for all services
Jesse Andrews1c1d1502011-09-12 19:29:56 -070067MYSQL_PASS=${MYSQL_PASS:-nova}
68SQL_CONN=${SQL_CONN:-mysql://root:$MYSQL_PASS@localhost/nova}
69# TODO: set rabbitmq conn string explicitly as well
Jesse Andrewsba23cc72011-09-11 03:22:13 -070070
Jesse Andrews30f68e92011-09-13 00:59:54 -070071# Install Packages
Jesse Andrewsd74257d2011-09-13 01:24:50 -070072# ================
Jesse Andrews30f68e92011-09-13 00:59:54 -070073#
74# Openstack uses a fair number of other projects.
75
Jesse Andrewsd74257d2011-09-13 01:24:50 -070076# Seed configuration with mysql password so that apt-get install doesn't
77# prompt us for a password upon install.
Jesse Andrews18d350d2011-09-12 21:46:12 -070078cat <<MYSQL_PRESEED | sudo debconf-set-selections
Jesse Andrews1c1d1502011-09-12 19:29:56 -070079mysql-server-5.1 mysql-server/root_password password $MYSQL_PASS
80mysql-server-5.1 mysql-server/root_password_again password $MYSQL_PASS
81mysql-server-5.1 mysql-server/start_on_boot boolean true
82MYSQL_PRESEED
Jesse Andrews2caf8fd2011-09-12 16:15:11 -070083
Jesse Andrews75a37652011-09-12 17:09:08 -070084# install apt requirements
Jesse Andrews18d350d2011-09-12 21:46:12 -070085sudo apt-get install -y -q `cat $DIR/apts/* | cut -d\# -f1`
Jesse Andrewsba23cc72011-09-11 03:22:13 -070086
Jesse Andrews75a37652011-09-12 17:09:08 -070087# install python requirements
Anthony Young1bbd9e02011-09-12 23:59:19 -070088sudo PIP_DOWNLOAD_CACHE=/var/cache/pip pip install `cat $DIR/pips/*`
Jesse Andrewsba23cc72011-09-11 03:22:13 -070089
Jesse Andrews61632572011-09-12 17:40:00 -070090# git clone only if directory doesn't exist already
91function git_clone {
92 if [ ! -d $2 ]; then
93 git clone $1 $2
94 fi
95}
96
Jesse Andrews75a37652011-09-12 17:09:08 -070097# compute service
Jesse Andrews61632572011-09-12 17:40:00 -070098git_clone https://github.com/cloudbuilders/nova.git $NOVA_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070099# image catalog service
Jesse Andrews61632572011-09-12 17:40:00 -0700100git_clone https://github.com/cloudbuilders/glance.git $GLANCE_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -0700101# unified auth system (manages accounts/tokens)
Jesse Andrews61632572011-09-12 17:40:00 -0700102git_clone https://github.com/cloudbuilders/keystone.git $KEYSTONE_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -0700103# a websockets/html5 or flash powered VNC console for vm instances
Jesse Andrews61632572011-09-12 17:40:00 -0700104git_clone https://github.com/cloudbuilders/noVNC.git $NOVNC_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -0700105# django powered web control panel for openstack
Jesse Andrews61632572011-09-12 17:40:00 -0700106git_clone https://github.com/cloudbuilders/openstack-dashboard.git $DASH_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -0700107# python client library to nova that dashboard (and others) use
Jesse Andrews61632572011-09-12 17:40:00 -0700108git_clone https://github.com/cloudbuilders/python-novaclient.git $NOVACLIENT_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -0700109# openstackx is a collection of extensions to openstack.compute & nova
110# that is *deprecated*. The code is being moved into python-novaclient & nova.
Jesse Andrews61632572011-09-12 17:40:00 -0700111git_clone https://github.com/cloudbuilders/openstackx.git $API_DIR
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700112
Jesse Andrews30f68e92011-09-13 00:59:54 -0700113# Initialization
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700114# ==============
Jesse Andrews30f68e92011-09-13 00:59:54 -0700115
Jesse Andrews75a37652011-09-12 17:09:08 -0700116# setup our checkouts so they are installed into python path
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700117# allowing ``import nova`` or ``import glance.client``
Jesse Andrews18d350d2011-09-12 21:46:12 -0700118cd $NOVACLIENT_DIR; sudo python setup.py develop
119cd $KEYSTONE_DIR; sudo python setup.py develop
120cd $GLANCE_DIR; sudo python setup.py develop
121cd $API_DIR; sudo python setup.py develop
122cd $DASH_DIR/django-openstack; sudo python setup.py develop
123cd $DASH_DIR/openstack-dashboard; sudo python setup.py develop
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700124
Jesse Andrews75a37652011-09-12 17:09:08 -0700125# attempt to load modules: kvm (hardware virt) and nbd (network block
126# device - used to manage qcow images)
Jesse Andrews18d350d2011-09-12 21:46:12 -0700127sudo modprobe nbd || true
128sudo modprobe kvm || true
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700129# user needs to be member of libvirtd group for nova-compute to use libvirt
130sudo usermod -a -G libvirtd `whoami`
Jesse Andrews75a37652011-09-12 17:09:08 -0700131# if kvm wasn't running before we need to restart libvirt to enable it
Jesse Andrews18d350d2011-09-12 21:46:12 -0700132sudo /etc/init.d/libvirt-bin restart
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700133
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700134# FIXME(ja): should LIBVIRT_TYPE be kvm if kvm module is loaded?
135
Jesse Andrews75a37652011-09-12 17:09:08 -0700136# setup nova instance directory
137mkdir -p $NOVA_DIR/instances
Jesse Andrews6f3baaf2011-09-12 11:59:38 -0700138
Jesse Andrews75a37652011-09-12 17:09:08 -0700139# if there is a partition labeled nova-instances use it (ext filesystems
140# can be labeled via e2label)
Jesse Andrews834531c2011-09-12 19:37:57 -0700141# FIXME: if already mounted this blows up...
Jesse Andrews75a37652011-09-12 17:09:08 -0700142if [ -L /dev/disk/by-label/nova-instances ]; then
Jesse Andrews18d350d2011-09-12 21:46:12 -0700143 sudo mount -L nova-instances $NOVA_DIR/instances
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700144 sudo chown -R `whoami` $NOVA_DIR/instances
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700145fi
146
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700147# Dashboard
148# ---------
149#
150# Setup the django application to serve via apache/wsgi
Jesse Andrews75a37652011-09-12 17:09:08 -0700151
152# Dash currently imports quantum even if you aren't using it. Instead
153# of installing quantum we can create a simple module that will pass the
154# initial imports
Jesse Andrews834531c2011-09-12 19:37:57 -0700155mkdir $DASH_DIR/openstack-dashboard/quantum || true
Jesse Andrews75a37652011-09-12 17:09:08 -0700156touch $DASH_DIR/openstack-dashboard/quantum/__init__.py
157touch $DASH_DIR/openstack-dashboard/quantum/client.py
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700158
Jesse Andrews75a37652011-09-12 17:09:08 -0700159cd $DASH_DIR/openstack-dashboard
160cp local/local_settings.py.example local/local_settings.py
161dashboard/manage.py syncdb
162
Jesse Andrews30f68e92011-09-13 00:59:54 -0700163# setup apache
Jesse Andrews75a37652011-09-12 17:09:08 -0700164# create an empty directory to use as our
165mkdir $DASH_DIR/.blackhole
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700166
Jesse Andrews75a37652011-09-12 17:09:08 -0700167# 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 -0700168cat $DIR/files/000-default.template | sed 's/%DASH_DIR%/\/opt\/dash/g' > /tmp/000-default
169sudo mv /tmp/000-default /etc/apache2/sites-enabled
170
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700171# ``python setup.py develop`` left some files owned by root in $DASH_DIR and
Jesse Andrews18d350d2011-09-12 21:46:12 -0700172# others by the original owner. We need to change the owner to apache so
173# dashboard can run
174sudo chown -R www-data:www-data $DASH_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -0700175
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700176# Glance
177# ------
178
Jesse Andrews9053d6a2011-09-12 22:13:11 -0700179sudo mkdir -p /var/log/glance
180sudo chown `whoami` /var/log/glance
Jesse Andrews75a37652011-09-12 17:09:08 -0700181
Jesse Andrews75a37652011-09-12 17:09:08 -0700182# add useful screenrc
183cp $DIR/files/screenrc ~/.screenrc
184
185# TODO: update current user to allow sudo for all commands in files/sudo/*
186
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700187# Nova
188# ----
189
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700190NL=`echo -ne '\015'`
191
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700192
193function add_nova_flag {
194 echo "$1" >> $NOVA_DIR/bin/nova.conf
195}
196
Jesse Andrews75a37652011-09-12 17:09:08 -0700197# (re)create nova.conf
198rm -f $NOVA_DIR/bin/nova.conf
199add_nova_flag "--verbose"
200add_nova_flag "--nodaemon"
201add_nova_flag "--dhcpbridge_flagfile=$NOVA_DIR/bin/nova.conf"
202add_nova_flag "--network_manager=nova.network.manager.$NET_MAN"
203add_nova_flag "--my_ip=$HOST_IP"
204add_nova_flag "--public_interface=$INTERFACE"
205add_nova_flag "--vlan_interface=$INTERFACE"
206add_nova_flag "--sql_connection=$SQL_CONN"
207add_nova_flag "--libvirt_type=$LIBVIRT_TYPE"
208add_nova_flag "--osapi_extensions_path=$API_DIR/extensions"
209add_nova_flag "--vncproxy_url=http://$HOST_IP:6080"
Anthony Young1f81db62011-09-13 03:35:00 -0700210add_nova_flag "--vncproxy_wwwroot=$NOVNC_DIR/"
Jesse Andrews75a37652011-09-12 17:09:08 -0700211add_nova_flag "--api_paste_config=$KEYSTONE_DIR/examples/paste/nova-api-paste.ini"
212add_nova_flag "--image_service=nova.image.glance.GlanceImageService"
213if [ -n "$FLAT_INTERFACE" ]; then
214 add_nova_flag "--flat_interface=$FLAT_INTERFACE"
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700215fi
216
Jesse Andrews75a37652011-09-12 17:09:08 -0700217# create a new named screen to store things in
218screen -d -m -S nova -t nova
219sleep 1
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700220
Jesse Andrews75a37652011-09-12 17:09:08 -0700221# Clean out the instances directory
222rm -rf $NOVA_DIR/instances/*
223
224# delete traces of nova networks from prior runs
225killall dnsmasq || true
226rm -rf $NOVA_DIR/networks
227mkdir -p $NOVA_DIR/networks
228
229# (re)create nova database
Jesse Andrews18d350d2011-09-12 21:46:12 -0700230mysql -uroot -p$MYSQL_PASS -e 'DROP DATABASE nova;' || true
231mysql -uroot -p$MYSQL_PASS -e 'CREATE DATABASE nova;'
Jesse Andrews75a37652011-09-12 17:09:08 -0700232$NOVA_DIR/bin/nova-manage db sync
233
234# initialize keystone with default users/endpoints
Jesse Andrews75a37652011-09-12 17:09:08 -0700235rm -f /opt/keystone/keystone.db
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700236# FIXME keystone creates a keystone.log wherever you run it from (bugify)
237cd /tmp
Jesse Andrews73e27b82011-09-12 17:55:00 -0700238BIN_DIR=$KEYSTONE_DIR/bin bash $DIR/files/keystone_data.sh
Jesse Andrews75a37652011-09-12 17:09:08 -0700239
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# delete existing glance images/database. Glance will recreate the db
247# when it is ran.
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700248# FIXME: configure glance not to shove files in /var/lib/glance?
249sudo mkdir -p /var/lib/glance
250sudo chown -R `whoami` /var/lib/glance
251rm -rf /var/lib/glance/images/*
Jesse Andrews75a37652011-09-12 17:09:08 -0700252rm -f $GLANCE_DIR/glance.sqlite
253
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700254# Launch Services
255# ===============
Jesse Andrews30f68e92011-09-13 00:59:54 -0700256
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700257# nova api crashes if we start it with a regular screen command,
258# so send the start command by forcing text into the window.
259function screen_it {
260 screen -S nova -X screen -t $1
Anthony Youngbdbe6d92011-09-13 09:43:46 -0700261 # only run the services specified in $ENABLED_SERVICES
262 if [[ $ENABLED_SERVICES == *$2* ]] then
263 screen -S nova -p $1 -X stuff "$2$NL"
264 fi
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700265}
266
Jesse Andrews75a37652011-09-12 17:09:08 -0700267screen_it g-api "cd $GLANCE_DIR; bin/glance-api --config-file=etc/glance-api.conf"
268screen_it g-reg "cd $GLANCE_DIR; bin/glance-registry --config-file=etc/glance-registry.conf"
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700269# keystone drops a keystone.log where if it is run, so change the path to
270# where it can write
271screen_it key "cd /tmp; $KEYSTONE_DIR/bin/keystone --config-file $KEYSTONE_DIR/etc/keystone.conf"
Jesse Andrews55508d62011-09-12 19:00:28 -0700272screen_it n-api "$NOVA_DIR/bin/nova-api"
273screen_it n-cpu "$NOVA_DIR/bin/nova-compute"
274screen_it n-net "$NOVA_DIR/bin/nova-network"
275screen_it n-sch "$NOVA_DIR/bin/nova-scheduler"
Anthony Young1f81db62011-09-13 03:35:00 -0700276# nova-vncproxy binds a privileged port, and so needs sudo
277screen_it n-vnc "sudo $NOVA_DIR/bin/nova-vncproxy"
Anthony Young8fbba912011-09-13 09:20:58 -0700278screen_it dash "sudo /etc/init.d/apache2 restart; sudo tail -f /var/log/apache2/error.log"
Jesse Andrews75a37652011-09-12 17:09:08 -0700279
Jesse Andrewsd74257d2011-09-13 01:24:50 -0700280# Install Images
281# ==============
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700282
Jesse Andrews30f68e92011-09-13 00:59:54 -0700283# Downloads a tty image (ami/aki/ari style), then extracts it. Upon extraction
284# we upload to glance with the glance cli tool.
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700285
286mkdir -p $DEST/images
287cd $DEST/images
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700288if [ ! -f $DEST/tty.tgz ]; then
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700289 wget -c http://images.ansolabs.com/tty.tgz -O $DEST/tty.tgz
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700290fi
291
292# extract ami-tty/image, aki-tty/image & ari-tty/image
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700293tar -zxf $DEST/tty.tgz
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700294
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700295# add images to glance
296# FIXME: kernel/ramdisk is hardcoded - use return result from add
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700297glance add name="tty-kernel" is_public=true container_format=aki disk_format=aki < aki-tty/image
298glance add name="tty-ramdisk" is_public=true container_format=ari disk_format=ari < ari-tty/image
299glance 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 -0700300