blob: 00bb891c1592cf48278905bc707b5c00b6a84401 [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
5# Quit script on error
6set -o errexit
7
8# Log commands as they are run for debugging
9set -o xtrace
10
11DIR=`pwd`
12DEST=/opt
13CMD=$1
14
Jesse Andrews6f3baaf2011-09-12 11:59:38 -070015# Set the destination directories for openstack projects
Jesse Andrewsba23cc72011-09-11 03:22:13 -070016NOVA_DIR=$DEST/nova
17DASH_DIR=$DEST/dash
18GLANCE_DIR=$DEST/glance
19KEYSTONE_DIR=$DEST/keystone
20NOVACLIENT_DIR=$DEST/python-novaclient
21API_DIR=$DEST/openstackx
22NOVNC_DIR=$DEST/noVNC
23
24# Use the first IP unless an explicit is set by a HOST_IP environment variable
25if [ ! -n "$HOST_IP" ]; then
26 HOST_IP=`LC_ALL=C ifconfig | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
27fi
28
29# NOVA CONFIGURATION
30INTERFACE=${INTERFACE:-eth0}
31FLOATING_RANGE=${FLOATING_RANGE:-10.6.0.0/27}
32FIXED_RANGE=${FIXED_RANGE:-10.0.0.0/24}
33LIBVIRT_TYPE=${LIBVIRT_TYPE:-qemu}
34NET_MAN=${NET_MAN:-VlanManager}
35# NOTE(vish): If you are using FlatDHCP on multiple hosts, set the interface
36# below but make sure that the interface doesn't already have an
37# ip or you risk breaking things.
38# FLAT_INTERFACE=eth0
39
Jesse Andrews2caf8fd2011-09-12 16:15:11 -070040# TODO: set rabbitmq conn string explicitly as well
41# TODO: switch to mysql for all services
Jesse Andrewsba23cc72011-09-11 03:22:13 -070042SQL_CONN=sqlite:///$NOVA_DIR/nova.sqlite
43
Jesse Andrews2caf8fd2011-09-12 16:15:11 -070044# FIXME: commands should be: stack.sh all or list of services to install/run
45
Jesse Andrewsba23cc72011-09-11 03:22:13 -070046# You should only have to run this once
47if [ "$CMD" == "install" ]; then
Jesse Andrews2e8ade12011-09-11 13:28:06 -070048 # install apt requirements
Jesse Andrewsf2ef7602011-09-11 16:23:21 -070049 apt-get install -y -q `cat $DIR/apts/* | cut -d\# -f1`
Jesse Andrewsba23cc72011-09-11 03:22:13 -070050
51 # install python requirements
Jesse Andrewsf2ef7602011-09-11 16:23:21 -070052 pip install `cat $DIR/pips/*`
Jesse Andrewsba23cc72011-09-11 03:22:13 -070053
Jesse Andrewsf110fd92011-09-12 12:11:23 -070054 # compute service
55 git clone https://github.com/cloudbuilders/nova.git $NOVA_DIR
56 # image catalog service
57 git clone https://github.com/cloudbuilders/glance.git $GLANCE_DIR
Jesse Andrews6f3baaf2011-09-12 11:59:38 -070058 # unified auth system (manages accounts/tokens)
Jesse Andrewsf110fd92011-09-12 12:11:23 -070059 git clone https://github.com/cloudbuilders/keystone.git $KEYSTONE_DIR
60 # a websockets/html5 or flash powered VNC console for vm instances
61 git clone https://github.com/cloudbuilders/noVNC.git $NOVNC_DIR
62 # django powered web control panel for openstack
63 git clone https://github.com/cloudbuilders/openstack-dashboard.git $DASH_DIR
64 # python client library to nova that dashboard (and others) use
65 git clone https://github.com/cloudbuilders/python-novaclient.git $NOVACLIENT_DIR
Jesse Andrews6f3baaf2011-09-12 11:59:38 -070066 # openstackx is a collection of extensions to openstack.compute & nova
67 # that is *deprecated*. The code is being moved into python-novaclient & nova.
Jesse Andrewsf110fd92011-09-12 12:11:23 -070068 git clone https://github.com/cloudbuilders/openstackx.git $API_DIR
Jesse Andrewsba23cc72011-09-11 03:22:13 -070069
Jesse Andrews6f3baaf2011-09-12 11:59:38 -070070 # setup our checkouts so they are installed into python path
71 # allowing `import nova` or `import glance.client`
Jesse Andrewsba23cc72011-09-11 03:22:13 -070072 cd $NOVACLIENT_DIR; python setup.py develop
73 cd $KEYSTONE_DIR; python setup.py develop
74 cd $GLANCE_DIR; python setup.py develop
75 cd $API_DIR; python setup.py develop
76 cd $DASH_DIR/django-openstack; python setup.py develop
77 cd $DASH_DIR/openstack-dashboard; python setup.py develop
Jesse Andrewsba23cc72011-09-11 03:22:13 -070078
Jesse Andrews6f3baaf2011-09-12 11:59:38 -070079 # attempt to load modules: kvm (hardware virt) and nbd (network block
80 # device - used to manage qcow images)
Jesse Andrewsba23cc72011-09-11 03:22:13 -070081 modprobe nbd || true
Jesse Andrews6f3baaf2011-09-12 11:59:38 -070082 modprobe kvm || true
83 # if kvm wasn't running before we need to restart libvirt to enable it
Jesse Andrewsba23cc72011-09-11 03:22:13 -070084 /etc/init.d/libvirt-bin restart
85
Jesse Andrews6f3baaf2011-09-12 11:59:38 -070086 # setup nova instance directory
87 mkdir -p $NOVA_DIR/instances
88
89 # if there is a partition labeled nova-instances use it (ext filesystems
90 # can be labeled via e2label)
91 if [ -L /dev/disk/by-label/nova-instances ]; then
92 mount -L nova-instances /$NOVA_DIR/instances
93 fi
94
95 # *Dashboard*: setup django application to serve via apache/wsgi
96
97 # Dash currently imports quantum even if you aren't using it. Instead
98 # of installing quantum we can create a simple module that will pass the
99 # initial imports
100 mkdir $DASH_DIR/openstack-dashboard/quantum
101 touch $DASH_DIR/openstack-dashboard/quantum/__init__.py
102 touch $DASH_DIR/openstack-dashboard/quantum/client.py
103 # local_settings has
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700104 cd $DASH_DIR/openstack-dashboard
105 cp local/local_settings.py.example local/local_settings.py
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700106 dashboard/manage.py syncdb
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700107
Jesse Andrewsf110fd92011-09-12 12:11:23 -0700108 # # Setup Apache
Jesse Andrews6f3baaf2011-09-12 11:59:38 -0700109 # create an empty directory to use as our
110 mkdir $DASH_DIR/.blackhole
Jesse Andrews8b564a82011-09-11 17:53:34 -0700111 # FIXME(ja): can't figure out how to make $DASH_DIR work in sed, also install to available/a2e it
Jesse Andrews2caf8fd2011-09-12 16:15:11 -0700112 cat $DIR/files/000-default.template | sed 's/%DASH_DIR%/\/opt\/dash/g' > /etc/apache2/sites-enabled/000-default
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700113
114 chown -R www-data:www-data $DASH_DIR
115
116 mkdir -p /var/log/glance
117
Jesse Andrews6f3baaf2011-09-12 11:59:38 -0700118 # prepare initial images for loading into glance
Jesse Andrews3107deb2011-09-11 16:46:44 -0700119 if [ ! -f $DEST/tty.tgz ]; then
120 wget -c http://images.ansolabs.com/tty.tgz -O $DEST/tty.tgz
121 fi
122
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700123 mkdir -p $DEST/images
Jesse Andrews3107deb2011-09-11 16:46:44 -0700124 tar -C $DEST/images -zxf $DEST/tty.tgz
Jesse Andrews8b564a82011-09-11 17:53:34 -0700125
126 # add useful screenrc
127 cp $DIR/files/screenrc ~/.screenrc
Jesse Andrews2caf8fd2011-09-12 16:15:11 -0700128
129 # TODO: update current user to allow sudo for all commands in files/sudo/*
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700130 exit
131fi
132
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700133NL=`echo -ne '\015'`
134
135function screen_it {
Jesse Andrews6f3baaf2011-09-12 11:59:38 -0700136 # nova api crashes if we start it with a regular screen command,
137 # so send the start command by forcing text into the window.
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700138 screen -S nova -X screen -t $1
139 screen -S nova -p $1 -X stuff "$2$NL"
140}
141
142function add_nova_flag {
143 echo "$1" >> $NOVA_DIR/bin/nova.conf
144}
145
146if [ "$CMD" == "run" ] || [ "$CMD" == "run_detached" ]; then
147
Jesse Andrews6f3baaf2011-09-12 11:59:38 -0700148 # (re)create nova.conf
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700149 rm -f $NOVA_DIR/bin/nova.conf
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700150 add_nova_flag "--verbose"
151 add_nova_flag "--nodaemon"
152 add_nova_flag "--dhcpbridge_flagfile=$NOVA_DIR/bin/nova.conf"
153 add_nova_flag "--network_manager=nova.network.manager.$NET_MAN"
154 add_nova_flag "--my_ip=$HOST_IP"
155 add_nova_flag "--public_interface=$INTERFACE"
156 add_nova_flag "--vlan_interface=$INTERFACE"
157 add_nova_flag "--sql_connection=$SQL_CONN"
158 add_nova_flag "--libvirt_type=$LIBVIRT_TYPE"
159 add_nova_flag "--osapi_extensions_path=$API_DIR/extensions"
160 add_nova_flag "--vncproxy_url=http://$HOST_IP:6080"
161 add_nova_flag "--vncproxy_wwwroot=$NOVNC_DIR/noVNC/noVNC"
Jesse Andrews6f3baaf2011-09-12 11:59:38 -0700162 add_nova_flag "--api_paste_config=$KEYSTONE_DIR/examples/paste/nova-api-paste.ini"
163 add_nova_flag "--image_service=nova.image.glance.GlanceImageService"
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700164 if [ -n "$FLAT_INTERFACE" ]; then
165 add_nova_flag "--flat_interface=$FLAT_INTERFACE"
166 fi
167
Jesse Andrews6f3baaf2011-09-12 11:59:38 -0700168 # create a new named screen to store things in
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700169 screen -d -m -S nova -t nova
170 sleep 1
Jesse Andrews6f3baaf2011-09-12 11:59:38 -0700171
172 # Clean out the instances directory
Jesse Andrews1b175702011-09-11 17:11:11 -0700173 rm -rf $NOVA_DIR/instances/*
Jesse Andrews6f3baaf2011-09-12 11:59:38 -0700174
175 # delete traces of nova networks from prior runs
176 killall dnsmasq || true
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700177 rm -rf $NOVA_DIR/networks
178 mkdir -p $NOVA_DIR/networks
179
Jesse Andrews6f3baaf2011-09-12 11:59:38 -0700180 # (re)create nova database
181 rm -f $NOVA_DIR/nova.sqlite
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700182 $NOVA_DIR/bin/nova-manage db sync
Jesse Andrews6f3baaf2011-09-12 11:59:38 -0700183
184 # initialize keystone with default users/endpoints
185 # FIXME(ja): move initial_data.sh into this script
186 rm -f /opt/keystone/keystone.db
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700187 curl -OL https://raw.github.com/cloudbuilders/deploy.sh/master/initial_data.sh
188 BIN_DIR=$KEYSTONE_DIR/bin bash initial_data.sh
189
190 # create a small network
191 $NOVA_DIR/bin/nova-manage network create private $FIXED_RANGE 1 32
192
193 # create some floating ips
194 $NOVA_DIR/bin/nova-manage floating create $FLOATING_RANGE
195
Jesse Andrews6f3baaf2011-09-12 11:59:38 -0700196 # delete existing glance images/database. Glance will recreate the db
197 # when it is ran.
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700198 rm -rf /var/lib/glance/images/*
199 rm -f $GLANCE_DIR/glance.sqlite
200
201 screen_it n-api "$NOVA_DIR/bin/nova-api"
202 screen_it g-api "cd $GLANCE_DIR; bin/glance-api --config-file=etc/glance-api.conf"
203 screen_it g-reg "cd $GLANCE_DIR; bin/glance-registry --config-file=etc/glance-registry.conf"
204 screen_it cpu "$NOVA_DIR/bin/nova-compute"
205 screen_it net "$NOVA_DIR/bin/nova-network"
206 screen_it sched "$NOVA_DIR/bin/nova-scheduler"
207 screen_it key "$KEYSTONE_DIR/bin/keystone --config-file $KEYSTONE_DIR/etc/keystone.conf"
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700208 screen_it vnc "$NOVA_DIR/bin/nova-vncproxy"
Jesse Andrews2e8ade12011-09-11 13:28:06 -0700209 screen_it dash "/etc/init.d/apache2 restart; tail -f /var/log/apache2/error.log"
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700210
211 # FIXME: switch to just importing images
212 # remove previously converted images
213 rm -rf $DIR/images/[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]
214 $NOVA_DIR/bin/nova-manage image convert $DIR/images
215
216 if [ "$CMD" != "run_detached" ]; then
217 screen -S nova -x
218 fi
219fi
220
221if [ "$CMD" == "run" ] || [ "$CMD" == "terminate" ]; then
222 virsh list | grep i- | awk '{print $1}' | xargs -n1 virsh destroy
223 $NOVA_DIR/tools/clean-vlans
224 echo "FIXME: clean networks?"
225fi
226
227if [ "$CMD" == "run" ] || [ "$CMD" == "clean" ]; then
228 screen -S nova -X quit
229 rm -f *.pid*
230fi
231