blob: 6f6ef27370536c5546b60e74b9ed444fbd662b95 [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 Andrewsbe395c12011-09-12 19:11:30 -07005# FIXME: commands should be: stack.sh should allow specifying a subset of services
6
Jesse Andrews30f68e92011-09-13 00:59:54 -07007# Settings/Options
8# ----------------
9
Jesse Andrewsba23cc72011-09-11 03:22:13 -070010# Quit script on error
11set -o errexit
12
13# Log commands as they are run for debugging
14set -o xtrace
15
Jesse Andrews30f68e92011-09-13 00:59:54 -070016# Important paths: `DIR` is where we are executing from and `DEST` is where we
17# are installing openstack.
Jesse Andrewsba23cc72011-09-11 03:22:13 -070018DIR=`pwd`
19DEST=/opt
Jesse Andrewsba23cc72011-09-11 03:22:13 -070020
Jesse Andrews6f3baaf2011-09-12 11:59:38 -070021# Set the destination directories for openstack projects
Jesse Andrewsba23cc72011-09-11 03:22:13 -070022NOVA_DIR=$DEST/nova
23DASH_DIR=$DEST/dash
24GLANCE_DIR=$DEST/glance
25KEYSTONE_DIR=$DEST/keystone
26NOVACLIENT_DIR=$DEST/python-novaclient
27API_DIR=$DEST/openstackx
28NOVNC_DIR=$DEST/noVNC
29
30# Use the first IP unless an explicit is set by a HOST_IP environment variable
31if [ ! -n "$HOST_IP" ]; then
32 HOST_IP=`LC_ALL=C ifconfig | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
33fi
34
Jesse Andrewsbe395c12011-09-12 19:11:30 -070035# NOVA network / hypervisor configuration
Jesse Andrewsba23cc72011-09-11 03:22:13 -070036INTERFACE=${INTERFACE:-eth0}
37FLOATING_RANGE=${FLOATING_RANGE:-10.6.0.0/27}
38FIXED_RANGE=${FIXED_RANGE:-10.0.0.0/24}
39LIBVIRT_TYPE=${LIBVIRT_TYPE:-qemu}
40NET_MAN=${NET_MAN:-VlanManager}
Jesse Andrews30f68e92011-09-13 00:59:54 -070041
Jesse Andrewsba23cc72011-09-11 03:22:13 -070042# NOTE(vish): If you are using FlatDHCP on multiple hosts, set the interface
43# below but make sure that the interface doesn't already have an
44# ip or you risk breaking things.
45# FLAT_INTERFACE=eth0
46
Jesse Andrews2caf8fd2011-09-12 16:15:11 -070047# TODO: switch to mysql for all services
Jesse Andrews1c1d1502011-09-12 19:29:56 -070048MYSQL_PASS=${MYSQL_PASS:-nova}
49SQL_CONN=${SQL_CONN:-mysql://root:$MYSQL_PASS@localhost/nova}
50# TODO: set rabbitmq conn string explicitly as well
Jesse Andrewsba23cc72011-09-11 03:22:13 -070051
Jesse Andrews30f68e92011-09-13 00:59:54 -070052# Install Packages
53# ----------------
54#
55# Openstack uses a fair number of other projects.
56
Jesse Andrews1c1d1502011-09-12 19:29:56 -070057# seed configuration with mysql password
Jesse Andrews18d350d2011-09-12 21:46:12 -070058cat <<MYSQL_PRESEED | sudo debconf-set-selections
Jesse Andrews1c1d1502011-09-12 19:29:56 -070059mysql-server-5.1 mysql-server/root_password password $MYSQL_PASS
60mysql-server-5.1 mysql-server/root_password_again password $MYSQL_PASS
61mysql-server-5.1 mysql-server/start_on_boot boolean true
62MYSQL_PRESEED
Jesse Andrews2caf8fd2011-09-12 16:15:11 -070063
Jesse Andrews75a37652011-09-12 17:09:08 -070064# install apt requirements
Jesse Andrews18d350d2011-09-12 21:46:12 -070065sudo apt-get install -y -q `cat $DIR/apts/* | cut -d\# -f1`
Jesse Andrewsba23cc72011-09-11 03:22:13 -070066
Jesse Andrews75a37652011-09-12 17:09:08 -070067# install python requirements
Anthony Young1bbd9e02011-09-12 23:59:19 -070068sudo PIP_DOWNLOAD_CACHE=/var/cache/pip pip install `cat $DIR/pips/*`
Jesse Andrewsba23cc72011-09-11 03:22:13 -070069
Jesse Andrews61632572011-09-12 17:40:00 -070070# git clone only if directory doesn't exist already
71function git_clone {
72 if [ ! -d $2 ]; then
73 git clone $1 $2
74 fi
75}
76
Jesse Andrews75a37652011-09-12 17:09:08 -070077# compute service
Jesse Andrews61632572011-09-12 17:40:00 -070078git_clone https://github.com/cloudbuilders/nova.git $NOVA_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070079# image catalog service
Jesse Andrews61632572011-09-12 17:40:00 -070080git_clone https://github.com/cloudbuilders/glance.git $GLANCE_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070081# unified auth system (manages accounts/tokens)
Jesse Andrews61632572011-09-12 17:40:00 -070082git_clone https://github.com/cloudbuilders/keystone.git $KEYSTONE_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070083# a websockets/html5 or flash powered VNC console for vm instances
Jesse Andrews61632572011-09-12 17:40:00 -070084git_clone https://github.com/cloudbuilders/noVNC.git $NOVNC_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070085# django powered web control panel for openstack
Jesse Andrews61632572011-09-12 17:40:00 -070086git_clone https://github.com/cloudbuilders/openstack-dashboard.git $DASH_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070087# python client library to nova that dashboard (and others) use
Jesse Andrews61632572011-09-12 17:40:00 -070088git_clone https://github.com/cloudbuilders/python-novaclient.git $NOVACLIENT_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -070089# openstackx is a collection of extensions to openstack.compute & nova
90# that is *deprecated*. The code is being moved into python-novaclient & nova.
Jesse Andrews61632572011-09-12 17:40:00 -070091git_clone https://github.com/cloudbuilders/openstackx.git $API_DIR
Jesse Andrewsba23cc72011-09-11 03:22:13 -070092
Jesse Andrews30f68e92011-09-13 00:59:54 -070093# Initialization
94# --------------
95
Jesse Andrews75a37652011-09-12 17:09:08 -070096# setup our checkouts so they are installed into python path
97# allowing `import nova` or `import glance.client`
Jesse Andrews18d350d2011-09-12 21:46:12 -070098cd $NOVACLIENT_DIR; sudo python setup.py develop
99cd $KEYSTONE_DIR; sudo python setup.py develop
100cd $GLANCE_DIR; sudo python setup.py develop
101cd $API_DIR; sudo python setup.py develop
102cd $DASH_DIR/django-openstack; sudo python setup.py develop
103cd $DASH_DIR/openstack-dashboard; sudo python setup.py develop
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700104
Jesse Andrews75a37652011-09-12 17:09:08 -0700105# attempt to load modules: kvm (hardware virt) and nbd (network block
106# device - used to manage qcow images)
Jesse Andrews18d350d2011-09-12 21:46:12 -0700107sudo modprobe nbd || true
108sudo modprobe kvm || true
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700109# user needs to be member of libvirtd group for nova-compute to use libvirt
110sudo usermod -a -G libvirtd `whoami`
Jesse Andrews75a37652011-09-12 17:09:08 -0700111# if kvm wasn't running before we need to restart libvirt to enable it
Jesse Andrews18d350d2011-09-12 21:46:12 -0700112sudo /etc/init.d/libvirt-bin restart
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700113
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700114# FIXME(ja): should LIBVIRT_TYPE be kvm if kvm module is loaded?
115
Jesse Andrews75a37652011-09-12 17:09:08 -0700116# setup nova instance directory
117mkdir -p $NOVA_DIR/instances
Jesse Andrews6f3baaf2011-09-12 11:59:38 -0700118
Jesse Andrews75a37652011-09-12 17:09:08 -0700119# if there is a partition labeled nova-instances use it (ext filesystems
120# can be labeled via e2label)
Jesse Andrews834531c2011-09-12 19:37:57 -0700121# FIXME: if already mounted this blows up...
Jesse Andrews75a37652011-09-12 17:09:08 -0700122if [ -L /dev/disk/by-label/nova-instances ]; then
Jesse Andrews18d350d2011-09-12 21:46:12 -0700123 sudo mount -L nova-instances $NOVA_DIR/instances
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700124 sudo chown -R `whoami` $NOVA_DIR/instances
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700125fi
126
Jesse Andrews75a37652011-09-12 17:09:08 -0700127# *Dashboard*: setup django application to serve via apache/wsgi
128
129# Dash currently imports quantum even if you aren't using it. Instead
130# of installing quantum we can create a simple module that will pass the
131# initial imports
Jesse Andrews834531c2011-09-12 19:37:57 -0700132mkdir $DASH_DIR/openstack-dashboard/quantum || true
Jesse Andrews75a37652011-09-12 17:09:08 -0700133touch $DASH_DIR/openstack-dashboard/quantum/__init__.py
134touch $DASH_DIR/openstack-dashboard/quantum/client.py
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700135
Jesse Andrews75a37652011-09-12 17:09:08 -0700136cd $DASH_DIR/openstack-dashboard
137cp local/local_settings.py.example local/local_settings.py
138dashboard/manage.py syncdb
139
Jesse Andrews30f68e92011-09-13 00:59:54 -0700140# setup apache
Jesse Andrews75a37652011-09-12 17:09:08 -0700141# create an empty directory to use as our
142mkdir $DASH_DIR/.blackhole
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700143
Jesse Andrews75a37652011-09-12 17:09:08 -0700144# 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 -0700145cat $DIR/files/000-default.template | sed 's/%DASH_DIR%/\/opt\/dash/g' > /tmp/000-default
146sudo mv /tmp/000-default /etc/apache2/sites-enabled
147
148# `python setup.py develop` left some files owned by root in $DASH_DIR and
149# others by the original owner. We need to change the owner to apache so
150# dashboard can run
151sudo chown -R www-data:www-data $DASH_DIR
Jesse Andrews75a37652011-09-12 17:09:08 -0700152
Jesse Andrews9053d6a2011-09-12 22:13:11 -0700153sudo mkdir -p /var/log/glance
154sudo chown `whoami` /var/log/glance
Jesse Andrews75a37652011-09-12 17:09:08 -0700155
Jesse Andrews75a37652011-09-12 17:09:08 -0700156# add useful screenrc
157cp $DIR/files/screenrc ~/.screenrc
158
159# TODO: update current user to allow sudo for all commands in files/sudo/*
160
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700161NL=`echo -ne '\015'`
162
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700163
164function add_nova_flag {
165 echo "$1" >> $NOVA_DIR/bin/nova.conf
166}
167
Jesse Andrews75a37652011-09-12 17:09:08 -0700168# (re)create nova.conf
169rm -f $NOVA_DIR/bin/nova.conf
170add_nova_flag "--verbose"
171add_nova_flag "--nodaemon"
172add_nova_flag "--dhcpbridge_flagfile=$NOVA_DIR/bin/nova.conf"
173add_nova_flag "--network_manager=nova.network.manager.$NET_MAN"
174add_nova_flag "--my_ip=$HOST_IP"
175add_nova_flag "--public_interface=$INTERFACE"
176add_nova_flag "--vlan_interface=$INTERFACE"
177add_nova_flag "--sql_connection=$SQL_CONN"
178add_nova_flag "--libvirt_type=$LIBVIRT_TYPE"
179add_nova_flag "--osapi_extensions_path=$API_DIR/extensions"
180add_nova_flag "--vncproxy_url=http://$HOST_IP:6080"
181add_nova_flag "--vncproxy_wwwroot=$NOVNC_DIR/noVNC/noVNC"
182add_nova_flag "--api_paste_config=$KEYSTONE_DIR/examples/paste/nova-api-paste.ini"
183add_nova_flag "--image_service=nova.image.glance.GlanceImageService"
184if [ -n "$FLAT_INTERFACE" ]; then
185 add_nova_flag "--flat_interface=$FLAT_INTERFACE"
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700186fi
187
Jesse Andrews75a37652011-09-12 17:09:08 -0700188# create a new named screen to store things in
189screen -d -m -S nova -t nova
190sleep 1
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700191
Jesse Andrews75a37652011-09-12 17:09:08 -0700192# Clean out the instances directory
193rm -rf $NOVA_DIR/instances/*
194
195# delete traces of nova networks from prior runs
196killall dnsmasq || true
197rm -rf $NOVA_DIR/networks
198mkdir -p $NOVA_DIR/networks
199
200# (re)create nova database
Jesse Andrews18d350d2011-09-12 21:46:12 -0700201mysql -uroot -p$MYSQL_PASS -e 'DROP DATABASE nova;' || true
202mysql -uroot -p$MYSQL_PASS -e 'CREATE DATABASE nova;'
Jesse Andrews75a37652011-09-12 17:09:08 -0700203$NOVA_DIR/bin/nova-manage db sync
204
205# initialize keystone with default users/endpoints
Jesse Andrews75a37652011-09-12 17:09:08 -0700206rm -f /opt/keystone/keystone.db
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700207# FIXME keystone creates a keystone.log wherever you run it from (bugify)
208cd /tmp
Jesse Andrews73e27b82011-09-12 17:55:00 -0700209BIN_DIR=$KEYSTONE_DIR/bin bash $DIR/files/keystone_data.sh
Jesse Andrews75a37652011-09-12 17:09:08 -0700210
211# create a small network
212$NOVA_DIR/bin/nova-manage network create private $FIXED_RANGE 1 32
213
214# create some floating ips
215$NOVA_DIR/bin/nova-manage floating create $FLOATING_RANGE
216
217# delete existing glance images/database. Glance will recreate the db
218# when it is ran.
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700219# FIXME: configure glance not to shove files in /var/lib/glance?
220sudo mkdir -p /var/lib/glance
221sudo chown -R `whoami` /var/lib/glance
222rm -rf /var/lib/glance/images/*
Jesse Andrews75a37652011-09-12 17:09:08 -0700223rm -f $GLANCE_DIR/glance.sqlite
224
Jesse Andrews30f68e92011-09-13 00:59:54 -0700225# Launching Services
226# ------------------
227
Jesse Andrews1c1d1502011-09-12 19:29:56 -0700228# nova api crashes if we start it with a regular screen command,
229# so send the start command by forcing text into the window.
230function screen_it {
231 screen -S nova -X screen -t $1
232 screen -S nova -p $1 -X stuff "$2$NL"
233}
234
Jesse Andrews75a37652011-09-12 17:09:08 -0700235screen_it g-api "cd $GLANCE_DIR; bin/glance-api --config-file=etc/glance-api.conf"
236screen_it g-reg "cd $GLANCE_DIR; bin/glance-registry --config-file=etc/glance-registry.conf"
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700237# keystone drops a keystone.log where if it is run, so change the path to
238# where it can write
239screen_it key "cd /tmp; $KEYSTONE_DIR/bin/keystone --config-file $KEYSTONE_DIR/etc/keystone.conf"
Jesse Andrews55508d62011-09-12 19:00:28 -0700240screen_it n-api "$NOVA_DIR/bin/nova-api"
241screen_it n-cpu "$NOVA_DIR/bin/nova-compute"
242screen_it n-net "$NOVA_DIR/bin/nova-network"
243screen_it n-sch "$NOVA_DIR/bin/nova-scheduler"
244screen_it n-vnc "$NOVA_DIR/bin/nova-vncproxy"
Jesse Andrews4d6cb142011-09-12 23:48:30 -0700245screen_it dash "sudo /etc/init.d/apache2 restart; tail -f /var/log/apache2/error.log"
Jesse Andrews75a37652011-09-12 17:09:08 -0700246
Jesse Andrews30f68e92011-09-13 00:59:54 -0700247# Installing Images
248# -----------------
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700249
Jesse Andrews30f68e92011-09-13 00:59:54 -0700250# Downloads a tty image (ami/aki/ari style), then extracts it. Upon extraction
251# we upload to glance with the glance cli tool.
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700252
253mkdir -p $DEST/images
254cd $DEST/images
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700255if [ ! -f $DEST/tty.tgz ]; then
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700256 wget -c http://images.ansolabs.com/tty.tgz -O $DEST/tty.tgz
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700257fi
258
259# extract ami-tty/image, aki-tty/image & ari-tty/image
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700260tar -zxf $DEST/tty.tgz
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700261
Jesse Andrewsbe395c12011-09-12 19:11:30 -0700262# add images to glance
263# FIXME: kernel/ramdisk is hardcoded - use return result from add
Jesse Andrewse49b8bd2011-09-12 18:08:04 -0700264glance add name="tty-kernel" is_public=true container_format=aki disk_format=aki < aki-tty/image
265glance add name="tty-ramdisk" is_public=true container_format=ari disk_format=ari < ari-tty/image
266glance 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 -0700267