blob: 8ef39fef1e295012f742c538356faf1dc445a9c2 [file] [log] [blame]
Jesse Andrewsba23cc72011-09-11 03:22:13 -07001#!/usr/bin/env bash
2
3# **stack.sh** is rackspace cloudbuilder's opinionated openstack installation.
4
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
15# Set hte destination directories for openstack projects
16NOVA_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
40SQL_CONN=sqlite:///$NOVA_DIR/nova.sqlite
41
42# clone a git repository to a location, or if it already
43# exists, fetch and checkout remote master
44function clone_or_up {
45 if [ -d $2 ]; then
Jesse Andrews3107deb2011-09-11 16:46:44 -070046 echo commenting out update for now for speed
47 # cd $2
48 # git fetch origin
49 # git checkout origin/master
Jesse Andrewsba23cc72011-09-11 03:22:13 -070050 else
51 git clone $1 $2
52 fi
53}
54
55# You should only have to run this once
56if [ "$CMD" == "install" ]; then
Jesse Andrews2e8ade12011-09-11 13:28:06 -070057 # install apt requirements
Jesse Andrewsf2ef7602011-09-11 16:23:21 -070058 apt-get install -y -q `cat $DIR/apts/* | cut -d\# -f1`
Jesse Andrewsba23cc72011-09-11 03:22:13 -070059
60 # install python requirements
Jesse Andrewsf2ef7602011-09-11 16:23:21 -070061 pip install `cat $DIR/pips/*`
Jesse Andrewsba23cc72011-09-11 03:22:13 -070062
63 # TODO: kill openstackx
64 clone_or_up https://github.com/cloudbuilders/nova.git $NOVA_DIR
65 clone_or_up https://github.com/cloudbuilders/openstackx.git $API_DIR
66 clone_or_up https://github.com/cloudbuilders/noVNC.git $NOVNC_DIR
67 clone_or_up https://github.com/cloudbuilders/openstack-dashboard.git $DASH_DIR
68 clone_or_up https://github.com/cloudbuilders/python-novaclient.git $NOVACLIENT_DIR
69 clone_or_up https://github.com/cloudbuilders/keystone.git $KEYSTONE_DIR
70 clone_or_up https://github.com/cloudbuilders/glance.git $GLANCE_DIR
71
72 mkdir -p $NOVA_DIR/instances
73 mkdir -p $NOVA_DIR/networks
74
75 # these components are imported into each other...
76 cd $NOVACLIENT_DIR; python setup.py develop
77 cd $KEYSTONE_DIR; python setup.py develop
78 cd $GLANCE_DIR; python setup.py develop
79 cd $API_DIR; python setup.py develop
80 cd $DASH_DIR/django-openstack; python setup.py develop
81 cd $DASH_DIR/openstack-dashboard; python setup.py develop
Jesse Andrews2e8ade12011-09-11 13:28:06 -070082 # HACK: dash currently imports quantum even if you aren't using it
Jesse Andrewsba23cc72011-09-11 03:22:13 -070083 cd $DASH_DIR/openstack-dashboard
84 mkdir quantum
85 touch quantum/__init__.py
86 touch quantum/client.py
87
Jesse Andrewsba23cc72011-09-11 03:22:13 -070088 # attempt to load kvm and nbd modules
89 modprobe kvm || true
90 modprobe nbd || true
91 /etc/init.d/libvirt-bin restart
92
93 # install dashboard
94 cd $DASH_DIR/openstack-dashboard
95 cp local/local_settings.py.example local/local_settings.py
Jesse Andrewsba23cc72011-09-11 03:22:13 -070096 dashboard/manage.py syncdb
97 # setup apache
98 mkdir $DASH_DIR/.blackhole
99
Jesse Andrews8b564a82011-09-11 17:53:34 -0700100 # FIXME(ja): can't figure out how to make $DASH_DIR work in sed, also install to available/a2e it
101 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 -0700102
103 chown -R www-data:www-data $DASH_DIR
104
105 mkdir -p /var/log/glance
106
Jesse Andrews3107deb2011-09-11 16:46:44 -0700107 if [ ! -f $DEST/tty.tgz ]; then
108 wget -c http://images.ansolabs.com/tty.tgz -O $DEST/tty.tgz
109 fi
110
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700111 mkdir -p $DEST/images
Jesse Andrews3107deb2011-09-11 16:46:44 -0700112 tar -C $DEST/images -zxf $DEST/tty.tgz
Jesse Andrews8b564a82011-09-11 17:53:34 -0700113
114 # add useful screenrc
115 cp $DIR/files/screenrc ~/.screenrc
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700116 exit
117fi
118
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700119NL=`echo -ne '\015'`
120
121function screen_it {
122 screen -S nova -X screen -t $1
123 screen -S nova -p $1 -X stuff "$2$NL"
124}
125
126function add_nova_flag {
127 echo "$1" >> $NOVA_DIR/bin/nova.conf
128}
129
130if [ "$CMD" == "run" ] || [ "$CMD" == "run_detached" ]; then
131
132 rm -f $NOVA_DIR/bin/nova.conf
133
134 add_nova_flag "--verbose"
135 add_nova_flag "--nodaemon"
136 add_nova_flag "--dhcpbridge_flagfile=$NOVA_DIR/bin/nova.conf"
137 add_nova_flag "--network_manager=nova.network.manager.$NET_MAN"
138 add_nova_flag "--my_ip=$HOST_IP"
139 add_nova_flag "--public_interface=$INTERFACE"
140 add_nova_flag "--vlan_interface=$INTERFACE"
141 add_nova_flag "--sql_connection=$SQL_CONN"
142 add_nova_flag "--libvirt_type=$LIBVIRT_TYPE"
143 add_nova_flag "--osapi_extensions_path=$API_DIR/extensions"
144 add_nova_flag "--vncproxy_url=http://$HOST_IP:6080"
145 add_nova_flag "--vncproxy_wwwroot=$NOVNC_DIR/noVNC/noVNC"
146
147 if [ -n "$FLAT_INTERFACE" ]; then
148 add_nova_flag "--flat_interface=$FLAT_INTERFACE"
149 fi
150
151 add_nova_flag "--api_paste_config=$KEYSTONE_DIR/examples/paste/nova-api-paste.ini"
152 add_nova_flag "--image_service=nova.image.glance.GlanceImageService"
153
154 killall dnsmasq || true
155 screen -d -m -S nova -t nova
156 sleep 1
157 rm -f $NOVA_DIR/nova.sqlite
Jesse Andrews1b175702011-09-11 17:11:11 -0700158 rm -rf $NOVA_DIR/instances/*
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700159 mkdir -p $NOVA_DIR/instances
Jesse Andrews1b175702011-09-11 17:11:11 -0700160 # if there is a partition labeled nova-instances use it (ext filesystems
161 # can be labeled via e2label)
162 if [ -L /dev/disk/by-label/nova-instances ]; then
163 mount -L nova-instances /$NOVA_DIR/instances
164 fi
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700165 rm -rf $NOVA_DIR/networks
166 mkdir -p $NOVA_DIR/networks
167
168 # create the database
169 $NOVA_DIR/bin/nova-manage db sync
170 rm -f keystone.db
171 # add default data
172 curl -OL https://raw.github.com/cloudbuilders/deploy.sh/master/initial_data.sh
173 BIN_DIR=$KEYSTONE_DIR/bin bash initial_data.sh
174
175 # create a small network
176 $NOVA_DIR/bin/nova-manage network create private $FIXED_RANGE 1 32
177
178 # create some floating ips
179 $NOVA_DIR/bin/nova-manage floating create $FLOATING_RANGE
180
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700181 rm -rf /var/lib/glance/images/*
182 rm -f $GLANCE_DIR/glance.sqlite
183
Jesse Andrews3107deb2011-09-11 16:46:44 -0700184 # nova api crashes if we start it with a regular screen command,
185 # so send the start command by forcing text into the window.
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700186 screen_it n-api "$NOVA_DIR/bin/nova-api"
187 screen_it g-api "cd $GLANCE_DIR; bin/glance-api --config-file=etc/glance-api.conf"
188 screen_it g-reg "cd $GLANCE_DIR; bin/glance-registry --config-file=etc/glance-registry.conf"
189 screen_it cpu "$NOVA_DIR/bin/nova-compute"
190 screen_it net "$NOVA_DIR/bin/nova-network"
191 screen_it sched "$NOVA_DIR/bin/nova-scheduler"
192 screen_it key "$KEYSTONE_DIR/bin/keystone --config-file $KEYSTONE_DIR/etc/keystone.conf"
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700193 screen_it vnc "$NOVA_DIR/bin/nova-vncproxy"
Jesse Andrews2e8ade12011-09-11 13:28:06 -0700194 screen_it dash "/etc/init.d/apache2 restart; tail -f /var/log/apache2/error.log"
Jesse Andrewsba23cc72011-09-11 03:22:13 -0700195
196 # FIXME: switch to just importing images
197 # remove previously converted images
198 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]
199 $NOVA_DIR/bin/nova-manage image convert $DIR/images
200
201 if [ "$CMD" != "run_detached" ]; then
202 screen -S nova -x
203 fi
204fi
205
206if [ "$CMD" == "run" ] || [ "$CMD" == "terminate" ]; then
207 virsh list | grep i- | awk '{print $1}' | xargs -n1 virsh destroy
208 $NOVA_DIR/tools/clean-vlans
209 echo "FIXME: clean networks?"
210fi
211
212if [ "$CMD" == "run" ] || [ "$CMD" == "clean" ]; then
213 screen -S nova -X quit
214 rm -f *.pid*
215fi
216