Browse code

Fix merge conflicts

Dean Troyer authored on 2011/09/15 01:13:54
Showing 4 changed files
... ...
@@ -1,59 +1,111 @@
1
-#!/bin/bash
1
+#!/usr/bin/env bash
2 2
 # Configurable params
3 3
 BRIDGE=${BRIDGE:-br0}
4
-CONTAINER=${CONTAINER:-TESTER}
4
+CONTAINER=${CONTAINER:-STACK}
5 5
 CONTAINER_IP=${CONTAINER_IP:-192.168.1.50}
6 6
 CONTAINER_CIDR=${CONTAINER_CIDR:-$CONTAINER_IP/24}
7 7
 CONTAINER_NETMASK=${CONTAINER_NETMASK:-255.255.255.0}
8 8
 CONTAINER_GATEWAY=${CONTAINER_GATEWAY:-192.168.1.1}
9
-NAMESERVER=${NAMESERVER:-192.168.1.1}
9
+NAMESERVER=${NAMESERVER:-$CONTAINER_GATEWAY}
10 10
 COPYENV=${COPYENV:-1}
11
-WARMCACHE=${WARMCACHE:-0}
12 11
 
13
-# Destroy any existing container
14
-lxc-stop -n $CONTAINER
15
-sleep 1
16
-cgdelete -r cpu,net_cls:$CONTAINER
17
-sleep 1
18
-lxc-destroy -n $CONTAINER
19
-sleep 1
12
+# Param string to pass to stack.sh.  Like "EC2_DMZ_HOST=192.168.1.1 MYSQL_USER=nova"
13
+STACKSH_PARAMS=${STACKSH_PARAMS:-}
20 14
 
21
-CACHEDIR=/var/cache/lxc/natty/rootfs-amd64
22
-if [ "$WARMCACHE" = "1" ]; then
23
-    if [ -d $CACHEDIR ]; then
24
-        # Pre-cache files
25
-        chroot $CACHEDIR apt-get update
26
-        chroot $CACHEDIR apt-get install -y `cat apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
27
-        chroot $CACHEDIR pip install `cat pips/*`
28
-    fi
15
+# Warn users who aren't on natty
16
+if ! grep -q natty /etc/lsb-release; then
17
+    echo "WARNING: this script has only been tested on natty"
29 18
 fi
30 19
 
31
-# Create network configuration
32
-NET_CONF=/tmp/net.conf
33
-cat > $NET_CONF <<EOF
20
+# Install deps
21
+apt-get install lxc debootstrap
22
+
23
+# Install cgroup-bin from source, since the packaging is buggy and possibly incompatible with our setup
24
+if ! which cgdelete | grep -q cgdelete; then
25
+    apt-get install g++ bison flex libpam0g-dev
26
+    wget http://sourceforge.net/projects/libcg/files/libcgroup/v0.37.1/libcgroup-0.37.1.tar.bz2/download -O /tmp/libcgroup-0.37.1.tar.bz2 
27
+    cd /tmp && bunzip2 libcgroup-0.37.1.tar.bz2  && tar xfv libcgroup-0.37.1.tar
28
+    cd libcgroup-0.37.1
29
+    ./configure
30
+    make install
31
+fi
32
+
33
+# Create lxc configuration
34
+LXC_CONF=/tmp/$CONTAINER.conf
35
+cat > $LXC_CONF <<EOF
34 36
 lxc.network.type = veth
35 37
 lxc.network.link = $BRIDGE
36 38
 lxc.network.flags = up
37 39
 lxc.network.ipv4 = $CONTAINER_CIDR
40
+# allow tap/tun devices
38 41
 lxc.cgroup.devices.allow = c 10:200 rwm
39 42
 EOF
40 43
 
41
-# Configure the network
42
-lxc-create -n $CONTAINER -t natty -f $NET_CONF
43
-sleep 2
44
+# Shutdown any existing container
45
+lxc-stop -n $CONTAINER
44 46
 
45
-# Where our container lives
47
+# This kills zombie containers
48
+if [ -d /cgroup/$CONTAINER ]; then
49
+    cgdelete -r cpu,net_cls:$CONTAINER
50
+fi
51
+
52
+# Warm the base image on first install
53
+CACHEDIR=/var/cache/lxc/natty/rootfs-amd64
54
+if [  -d $CACHEDIR ]; then
55
+    # trigger the initial debootstrap
56
+    lxc-create -n $CONTAINER -t natty -f $LXC_CONF
57
+    chroot $CACHEDIR apt-get update
58
+    chroot $CACHEDIR apt-get install -y `cat apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
59
+    chroot $CACHEDIR pip install `cat pips/*`
60
+    git clone https://github.com/cloudbuilders/nova.git $CACHEDIR/opt/nova
61
+    git clone https://github.com/cloudbuilders/openstackx.git $CACHEDIR/opt/openstackx
62
+    git clone https://github.com/cloudbuilders/noVNC.git $CACHEDIR/opt/noVNC
63
+    git clone https://github.com/cloudbuilders/openstack-dashboard.git $CACHEDIR/opt/dash
64
+    git clone https://github.com/cloudbuilders/python-novaclient.git $CACHEDIR/opt/python-novaclient
65
+    git clone https://github.com/cloudbuilders/keystone.git $CACHEDIR/opt/keystone
66
+    git clone https://github.com/cloudbuilders/glance.git $CACHEDIR/opt/glance
67
+fi
68
+
69
+# Destroy the old container
70
+lxc-destroy -n $CONTAINER
71
+
72
+# Create the container
73
+lxc-create -n $CONTAINER -t natty -f $LXC_CONF
74
+
75
+# Specify where our container rootfs lives
46 76
 ROOTFS=/var/lib/lxc/$CONTAINER/rootfs/
47 77
 
78
+# Create a stack user that is a member of the libvirtd group so that stack 
79
+# is able to interact with libvirt.
80
+chroot $ROOTFS groupadd libvirtd
81
+chroot $ROOTFS useradd stack -s /bin/bash -d /opt -G libvirtd
82
+
83
+# a simple password - pass
84
+echo stack:pass | chroot $ROOTFS chpasswd
85
+
86
+# and has sudo ability (in the future this should be limited to only what 
87
+# stack requires)
88
+echo "stack ALL=(ALL) NOPASSWD: ALL" >> $ROOTFS/etc/sudoers
89
+
90
+# Gracefully cp only if source file/dir exists
91
+function cp_it {
92
+    if [ -e $1 ] || [ -d $1 ]; then
93
+        cp -pr $1 $2
94
+    fi
95
+}
96
+
48 97
 # Copy over your ssh keys and env if desired
49 98
 if [ "$COPYENV" = "1" ]; then
50
-    cp -pr ~/.ssh $ROOTFS/root/.ssh
51
-    cp -p ~/.ssh/id_rsa.pub $ROOTFS/root/.ssh/authorized_keys
52
-    cp -pr ~/.gitconfig $ROOTFS/root/.gitconfig
53
-    cp -pr ~/.vimrc $ROOTFS/root/.vimrc
54
-    cp -pr ~/.bashrc $ROOTFS/root/.bashrc
99
+    cp_it ~/.ssh $ROOTFS/opt/.ssh
100
+    cp_it ~/.ssh/id_rsa.pub $ROOTFS/opt/.ssh/authorized_keys
101
+    cp_it ~/.gitconfig $ROOTFS/opt/.gitconfig
102
+    cp_it ~/.vimrc $ROOTFS/opt/.vimrc
103
+    cp_it ~/.bashrc $ROOTFS/opt/.bashrc
55 104
 fi
56 105
 
106
+# Give stack ownership over /opt so it may do the work needed
107
+chroot $ROOTFS chown -R stack /opt
108
+
57 109
 # Configure instance network
58 110
 INTERFACES=$ROOTFS/etc/network/interfaces
59 111
 cat > $INTERFACES <<EOF
... ...
@@ -67,57 +119,41 @@ iface eth0 inet static
67 67
         gateway $CONTAINER_GATEWAY
68 68
 EOF
69 69
 
70
-# Configure the first run installer
71
-INSTALL_SH=$ROOTFS/root/install.sh
72
-cat > $INSTALL_SH <<EOF
70
+# Configure the runner
71
+RUN_SH=$ROOTFS/opt/run.sh
72
+cat > $RUN_SH <<EOF
73 73
 #!/bin/bash
74
-echo \#\!/bin/sh -e > /etc/rc.local
75
-echo "nameserver $NAMESERVER" | resolvconf -a eth0
74
+# Make sure dns is set up
75
+echo "nameserver $NAMESERVER" | sudo resolvconf -a eth0
76 76
 sleep 1
77
-# Create a stack user that is a member of the libvirtd group so that stack 
78
-# is able to interact with libvirt.
79
-groupadd libvirtd
80
-useradd stack -s /bin/bash -d /opt -G libvirtd
81 77
 
82
-# a simple password - pass
83
-echo stack:pass | chpasswd
84
-
85
-# give stack ownership over /opt so it may do the work needed
86
-chown -R stack /opt
87
-
88
-# and has sudo ability (in the future this should be limited to only what 
89
-# stack requires)
90
-
91
-echo "stack ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
78
+# Kill any existing screens
79
+killall screen
92 80
 
93 81
 # Install and run stack.sh
94
-apt-get update
95
-apt-get -y --force-yes install git-core vim-nox sudo
96
-su -c "git clone git://github.com/cloudbuilders/nfs-stack.git /opt/nfs-stack" stack
97
-su -c "cd /opt/nfs-stack && ./stack.sh" stack
82
+sudo apt-get update
83
+sudo apt-get -y --force-yes install git-core vim-nox sudo
84
+if [ ! -d "/opt/nfs-stack" ]; then
85
+    git clone git://github.com/cloudbuilders/nfs-stack.git ~/nfs-stack
86
+fi
87
+cd /opt/nfs-stack && $STACKSH_PARAMS ./stack.sh > /opt/run.sh.log
98 88
 EOF
99 89
 
100
-chmod 700 $INSTALL_SH
90
+# Make the run.sh executable
91
+chmod 755 $RUN_SH
101 92
 
102
-# Make installer run on boot
93
+# Make runner launch on boot
103 94
 RC_LOCAL=$ROOTFS/etc/rc.local
104 95
 cat > $RC_LOCAL <<EOF
105 96
 #!/bin/sh -e
106
-/root/install.sh
97
+su -c "/opt/run.sh" stack
107 98
 EOF
108 99
 
109 100
 # Configure cgroup directory
110
-mkdir -p /cgroup
111
-mount none -t cgroup /cgroup
101
+if ! mount | grep -q cgroup; then
102
+    mkdir -p /cgroup
103
+    mount none -t cgroup /cgroup
104
+fi
112 105
 
113 106
 # Start our container
114 107
 lxc-start -d -n $CONTAINER
115
-
116
-cat << EOF > /bin/remove_dead_cgroup.shecho
117
-"Removing dead cgroup .$CONTAINER." >> /var/log/cgroup
118
-rmdir /cgroup/$CONTAINER >> /var/log/cgroup 2>&1
119
-echo "return value was $?" >> /var/log/cgroup
120
-EOF
121
-chmod 755 /bin/remove_dead_cgroup.sh
122
-echo /bin/remove_dead_cgroup.sh > /cgroup/release_agent
123
-echo 1 > /cgroup/notify_on_release
124 108
new file mode 100644
... ...
@@ -0,0 +1,67 @@
0
+[DEFAULT]
1
+# Show more verbose log output (sets INFO log level output)
2
+verbose = True
3
+
4
+# Show debugging output in logs (sets DEBUG log level output)
5
+debug = False
6
+
7
+# Address to bind the registry server
8
+bind_host = 0.0.0.0
9
+
10
+# Port the bind the registry server to
11
+bind_port = 9191
12
+
13
+# Log to this file. Make sure you do not set the same log
14
+# file for both the API and registry servers!
15
+log_file = /var/log/glance/registry.log
16
+
17
+# Send logs to syslog (/dev/log) instead of to file specified by `log_file`
18
+use_syslog = False
19
+
20
+# SQLAlchemy connection string for the reference implementation
21
+# registry server. Any valid SQLAlchemy connection string is fine.
22
+# See: http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/connections.html#sqlalchemy.create_engine
23
+sql_connection = %SQL_CONN%
24
+
25
+# Period in seconds after which SQLAlchemy should reestablish its connection
26
+# to the database.
27
+#
28
+# MySQL uses a default `wait_timeout` of 8 hours, after which it will drop
29
+# idle connections. This can result in 'MySQL Gone Away' exceptions. If you
30
+# notice this, you can lower this value to ensure that SQLAlchemy reconnects
31
+# before MySQL can drop the connection.
32
+sql_idle_timeout = 3600
33
+
34
+# Limit the api to return `param_limit_max` items in a call to a container. If
35
+# a larger `limit` query param is provided, it will be reduced to this value.
36
+api_limit_max = 1000
37
+
38
+# If a `limit` query param is not provided in an api request, it will
39
+# default to `limit_param_default`
40
+limit_param_default = 25
41
+
42
+[pipeline:glance-registry]
43
+pipeline = context registryapp
44
+# NOTE: use the following pipeline for keystone
45
+# pipeline = authtoken keystone_shim context registryapp
46
+
47
+[app:registryapp]
48
+paste.app_factory = glance.registry.server:app_factory
49
+
50
+[filter:context]
51
+context_class = glance.registry.context.RequestContext
52
+paste.filter_factory = glance.common.context:filter_factory
53
+
54
+[filter:authtoken]
55
+paste.filter_factory = keystone.middleware.auth_token:filter_factory
56
+service_protocol = http
57
+service_host = 127.0.0.1
58
+service_port = 5000
59
+auth_host = 127.0.0.1
60
+auth_port = 5001
61
+auth_protocol = http
62
+auth_uri = http://127.0.0.1:5000/
63
+admin_token = 999888777666
64
+
65
+[filter:keystone_shim]
66
+paste.filter_factory = keystone.middleware.glance_auth_token:filter_factory
0 67
new file mode 100644
... ...
@@ -0,0 +1,86 @@
0
+[DEFAULT]
1
+# Show more verbose log output (sets INFO log level output)
2
+verbose = False
3
+
4
+# Show debugging output in logs (sets DEBUG log level output)
5
+debug = False
6
+
7
+# Which backend store should Keystone use by default.
8
+# Default: 'sqlite'
9
+# Available choices are 'sqlite' [future will include LDAP, PAM, etc]
10
+default_store = sqlite
11
+
12
+# Log to this file. Make sure you do not set the same log
13
+# file for both the API and registry servers!
14
+log_file = /opt/keystone/keystone.log
15
+
16
+# List of backends to be configured
17
+backends = keystone.backends.sqlalchemy
18
+#For LDAP support, add: ,keystone.backends.ldap
19
+
20
+# Dictionary Maps every service to a header.Missing services would get header
21
+# X_(SERVICE_NAME) Key => Service Name, Value => Header Name
22
+service-header-mappings = {
23
+	'nova' : 'X-Server-Management-Url',
24
+	'swift' : 'X-Storage-Url',
25
+	'cdn' : 'X-CDN-Management-Url'}
26
+
27
+# Address to bind the API server
28
+# TODO Properties defined within app not available via pipeline.
29
+service_host = 0.0.0.0
30
+
31
+# Port the bind the API server to
32
+service_port = 5000
33
+
34
+# Address to bind the Admin API server
35
+admin_host = 0.0.0.0
36
+
37
+# Port the bind the Admin API server to
38
+admin_port = 5001
39
+
40
+#Role that allows to perform admin operations.
41
+keystone-admin-role = Admin
42
+
43
+#Role that allows to perform service admin operations.
44
+keystone-service-admin-role = KeystoneServiceAdmin
45
+
46
+[keystone.backends.sqlalchemy]
47
+# SQLAlchemy connection string for the reference implementation registry
48
+# server. Any valid SQLAlchemy connection string is fine.
49
+# See: http://bit.ly/ideIpI
50
+#sql_connection = sqlite:///keystone.db
51
+sql_connection = %SQL_CONN%
52
+backend_entities = ['UserRoleAssociation', 'Endpoints', 'Role', 'Tenant',
53
+                    'User', 'Credentials', 'EndpointTemplates', 'Token',
54
+                    'Service']
55
+
56
+# Period in seconds after which SQLAlchemy should reestablish its connection
57
+# to the database.
58
+sql_idle_timeout = 30
59
+
60
+[pipeline:admin]
61
+pipeline =
62
+	urlrewritefilter
63
+	admin_api
64
+
65
+[pipeline:keystone-legacy-auth]
66
+pipeline =
67
+	urlrewritefilter
68
+    legacy_auth
69
+    RAX-KEY-extension
70
+    service_api
71
+
72
+[app:service_api]
73
+paste.app_factory = keystone.server:service_app_factory
74
+
75
+[app:admin_api]
76
+paste.app_factory = keystone.server:admin_app_factory
77
+
78
+[filter:urlrewritefilter]
79
+paste.filter_factory = keystone.middleware.url:filter_factory
80
+
81
+[filter:legacy_auth]
82
+paste.filter_factory = keystone.frontends.legacy_token_auth:filter_factory
83
+
84
+[filter:RAX-KEY-extension]
85
+paste.filter_factory = keystone.contrib.extensions.service.raxkey.frontend:filter_factory
... ...
@@ -12,6 +12,7 @@
12 12
 #     ./stack.sh
13 13
 #
14 14
 # or run on a single line ``MYSQL_PASS=simple ./stack.sh``
15
+# or simply ``./stack.sh``
15 16
 
16 17
 # This script exits on an error so that errors don't compound and you see 
17 18
 # only the first error that occured.
... ...
@@ -36,6 +37,9 @@ API_DIR=$DEST/openstackx
36 36
 NOVNC_DIR=$DEST/noVNC
37 37
 MUNIN_DIR=$DEST/openstack-munin
38 38
 
39
+# Specify which services to launch.  These generally correspond to screen tabs
40
+ENABLED_SERVICES=${ENABLED_SERVICES:-g-api,g-reg,key,n-api,n-cpu,n-net,n-sch,n-vnc,dash}
41
+
39 42
 # Use the first IP unless an explicit is set by ``HOST_IP`` environment variable
40 43
 if [ ! -n "$HOST_IP" ]; then
41 44
     HOST_IP=`LC_ALL=C /sbin/ifconfig  | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
... ...
@@ -46,6 +50,7 @@ INTERFACE=${INTERFACE:-eth0}
46 46
 FLOATING_RANGE=${FLOATING_RANGE:-10.6.0.0/27}
47 47
 FIXED_RANGE=${FIXED_RANGE:-10.0.0.0/24}
48 48
 NET_MAN=${NET_MAN:-VlanManager}
49
+EC2_DMZ_HOST=${EC2_DMZ_HOST:-$HOST_IP}
49 50
 
50 51
 # If you are using FlatDHCP on multiple hosts, set the ``FLAT_INTERFACE``
51 52
 # variable but make sure that the interface doesn't already have an
... ...
@@ -55,11 +60,15 @@ NET_MAN=${NET_MAN:-VlanManager}
55 55
 # Nova hypervisor configuration
56 56
 LIBVIRT_TYPE=${LIBVIRT_TYPE:-qemu}
57 57
 
58
-
59
-# TODO: switch to mysql for all services
58
+# Mysql connection info
59
+MYSQL_USER=${MYSQL_USER:-root}
60 60
 MYSQL_PASS=${MYSQL_PASS:-nova}
61
-SQL_CONN=${SQL_CONN:-mysql://root:$MYSQL_PASS@localhost/nova}
62
-# TODO: set rabbitmq conn string explicitly as well
61
+MYSQL_HOST=${MYSQL_HOST:-localhost}
62
+# don't specify /db in this string, so we can use it for multiple services
63
+BASE_SQL_CONN=${BASE_SQL_CONN:-mysql://$MYSQL_USER:$MYSQL_PASS@$MYSQL_HOST}
64
+
65
+# Rabbit connection info
66
+RABBIT_HOST=${RABBIT_HOST:-localhost}
63 67
 
64 68
 # Install Packages
65 69
 # ================
... ...
@@ -127,18 +136,13 @@ sudo usermod -a -G libvirtd `whoami`
127 127
 # if kvm wasn't running before we need to restart libvirt to enable it
128 128
 sudo /etc/init.d/libvirt-bin restart
129 129
 
130
-# FIXME(ja): should LIBVIRT_TYPE be kvm if kvm module is loaded?
130
+## FIXME(ja): should LIBVIRT_TYPE be kvm if kvm module is loaded?
131 131
 
132
-# setup nova instance directory
133
-mkdir -p $NOVA_DIR/instances
132
+# add useful screenrc
133
+cp $DIR/files/screenrc ~/.screenrc
134
+
135
+# TODO: update current user to allow sudo for all commands in files/sudo/*
134 136
 
135
-# if there is a partition labeled nova-instances use it (ext filesystems
136
-# can be labeled via e2label)
137
-# FIXME: if already mounted this blows up...
138
-if [ -L /dev/disk/by-label/nova-instances ]; then
139
-    sudo mount -L nova-instances $NOVA_DIR/instances
140
-    sudo chown -R `whoami` $NOVA_DIR/instances
141
-fi
142 137
 
143 138
 # Dashboard
144 139
 # ---------
... ...
@@ -148,27 +152,33 @@ fi
148 148
 # Dash currently imports quantum even if you aren't using it.  Instead 
149 149
 # of installing quantum we can create a simple module that will pass the 
150 150
 # initial imports
151
-mkdir $DASH_DIR/openstack-dashboard/quantum || true
152
-touch $DASH_DIR/openstack-dashboard/quantum/__init__.py || true
153
-touch $DASH_DIR/openstack-dashboard/quantum/client.py || true
151
+sudo mkdir -p  $DASH_DIR/openstack-dashboard/quantum || true
152
+sudo touch $DASH_DIR/openstack-dashboard/quantum/__init__.py
153
+sudo touch $DASH_DIR/openstack-dashboard/quantum/client.py
154 154
 
155 155
 cd $DASH_DIR/openstack-dashboard
156
-[ ! -r local/local_settings.py ] && cp local/local_settings.py.example local/local_settings.py
156
+sudo cp local/local_settings.py.example local/local_settings.py
157 157
 dashboard/manage.py syncdb
158 158
 
159
-# setup apache
160
-# create an empty directory to use as our 
161
-mkdir -p $DASH_DIR/.blackhole
159
+# create an empty directory that apache uses as docroot
160
+sudo mkdir -p $DASH_DIR/.blackhole
162 161
 
163
-# FIXME(ja): can't figure out how to make $DASH_DIR work in sed, also install to available/a2e it 
164
-cat $DIR/files/000-default.template | sed 's/%DASH_DIR%/\/opt\/dash/g' > /tmp/000-default
165
-sudo mv /tmp/000-default /etc/apache2/sites-enabled
162
+## Configure apache's 000-default to run dashboard
163
+sudo cp $DIR/files/000-default.template /etc/apache2/sites-enabled/000-default
164
+sudo sed -e "s,%DASH_DIR%,$DASH_DIR,g" -i /etc/apache2/sites-enabled/000-default
166 165
 
167
-# ``python setup.py develop`` left some files owned by root in $DASH_DIR and
166
+# ``python setup.py develop`` left some files owned by root in ``DASH_DIR`` and
168 167
 # others by the original owner.  We need to change the owner to apache so
169 168
 # dashboard can run
170 169
 sudo chown -R www-data:www-data $DASH_DIR
171 170
 
171
+# Update the DB to give user ‘$MYSQL_USER’@’%’ full control of the all databases:
172
+sudo mysql -uroot -p$MYSQL_PASS -e "GRANT ALL PRIVILEGES ON *.* TO '$MYSQL_USER'@'%' WITH GRANT OPTION;"
173
+
174
+# Edit /etc/mysql/my.cnf to change ‘bind-address’ from localhost (127.0.0.1) to any (0.0.0.0) and restart the mysql service:
175
+sudo sed -i 's/127.0.0.1/0.0.0.0/g' /etc/mysql/my.cnf
176
+sudo service mysql restart
177
+
172 178
 # Munin
173 179
 # -----
174 180
 
... ...
@@ -196,20 +206,26 @@ sudo restart munin-node
196 196
 # Glance
197 197
 # ------
198 198
 
199
+# Glance uses ``/var/lib/glance`` and ``/var/log/glance`` by default, so
200
+# we need to insure that our user has permissions to use them.
199 201
 sudo mkdir -p /var/log/glance
200
-sudo chown `whoami` /var/log/glance 
201
-
202
-# add useful screenrc
203
-cp $DIR/files/screenrc ~/.screenrc
202
+sudo chown -R `whoami` /var/log/glance 
203
+sudo mkdir -p /var/lib/glance
204
+sudo chown -R `whoami` /var/lib/glance
204 205
 
205
-# TODO: update current user to allow sudo for all commands in files/sudo/*
206
+# Delete existing images/database as glance will recreate the db on startup
207
+rm -rf /var/lib/glance/images/*
208
+# (re)create glance database
209
+mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'DROP DATABASE glance;' || true
210
+mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'CREATE DATABASE glance;'
211
+# Copy over our glance-registry.conf
212
+GLANCE_CONF=$GLANCE_DIR/etc/glance-registry.conf
213
+cp $DIR/files/glance-registry.conf $GLANCE_CONF
214
+sudo sed -e "s,%SQL_CONN%,$BASE_SQL_CONN/glance,g" -i $GLANCE_CONF
206 215
 
207 216
 # Nova
208 217
 # ----
209 218
 
210
-NL=`echo -ne '\015'`
211
-
212
-
213 219
 function add_nova_flag {
214 220
     echo "$1" >> $NOVA_DIR/bin/nova.conf
215 221
 }
... ...
@@ -223,13 +239,16 @@ add_nova_flag "--network_manager=nova.network.manager.$NET_MAN"
223 223
 add_nova_flag "--my_ip=$HOST_IP"
224 224
 add_nova_flag "--public_interface=$INTERFACE"
225 225
 add_nova_flag "--vlan_interface=$INTERFACE"
226
-add_nova_flag "--sql_connection=$SQL_CONN"
226
+add_nova_flag "--sql_connection=$BASE_SQL_CONN/nova"
227 227
 add_nova_flag "--libvirt_type=$LIBVIRT_TYPE"
228 228
 add_nova_flag "--osapi_extensions_path=$API_DIR/extensions"
229 229
 add_nova_flag "--vncproxy_url=http://$HOST_IP:6080"
230 230
 add_nova_flag "--vncproxy_wwwroot=$NOVNC_DIR/"
231 231
 add_nova_flag "--api_paste_config=$KEYSTONE_DIR/examples/paste/nova-api-paste.ini"
232 232
 add_nova_flag "--image_service=nova.image.glance.GlanceImageService"
233
+add_nova_flag "--image_service=nova.image.glance.GlanceImageService"
234
+add_nova_flag "--ec2_dmz_host=$EC2_DMZ_HOST"
235
+add_nova_flag "--rabbit_host=$RABBIT_HOST"
233 236
 if [ -n "$FLAT_INTERFACE" ]; then
234 237
     add_nova_flag "--flat_interface=$FLAT_INTERFACE"
235 238
 fi
... ...
@@ -238,6 +257,17 @@ fi
238 238
 screen -d -m -S nova -t nova
239 239
 sleep 1
240 240
 
241
+# setup nova instance directory
242
+mkdir -p $NOVA_DIR/instances
243
+
244
+# if there is a partition labeled nova-instances use it (ext filesystems
245
+# can be labeled via e2label)
246
+## FIXME: if already mounted this blows up...
247
+if [ -L /dev/disk/by-label/nova-instances ]; then
248
+    sudo mount -L nova-instances $NOVA_DIR/instances
249
+    sudo chown -R `whoami` $NOVA_DIR/instances
250
+fi
251
+
241 252
 # Clean out the instances directory
242 253
 rm -rf $NOVA_DIR/instances/*
243 254
 
... ...
@@ -247,45 +277,53 @@ rm -rf $NOVA_DIR/networks
247 247
 mkdir -p $NOVA_DIR/networks
248 248
 
249 249
 # (re)create nova database
250
-mysql -uroot -p$MYSQL_PASS -e 'DROP DATABASE nova;' || true
251
-mysql -uroot -p$MYSQL_PASS -e 'CREATE DATABASE nova;'
250
+mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'DROP DATABASE nova;' || true
251
+mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'CREATE DATABASE nova;'
252 252
 $NOVA_DIR/bin/nova-manage db sync
253 253
 
254
-# initialize keystone with default users/endpoints
255
-rm -f /opt/keystone/keystone.db
256
-# FIXME keystone creates a keystone.log wherever you run it from (bugify)
257
-cd /tmp
258
-BIN_DIR=$KEYSTONE_DIR/bin bash $DIR/files/keystone_data.sh
259
-
260 254
 # create a small network
261 255
 $NOVA_DIR/bin/nova-manage network create private $FIXED_RANGE 1 32
262 256
 
263 257
 # create some floating ips
264 258
 $NOVA_DIR/bin/nova-manage floating create $FLOATING_RANGE
265 259
 
266
-# delete existing glance images/database.  Glance will recreate the db
267
-# when it is ran.
268
-# FIXME: configure glance not to shove files in /var/lib/glance?
269
-sudo mkdir -p /var/lib/glance
270
-sudo chown -R `whoami` /var/lib/glance
271
-rm -rf /var/lib/glance/images/*
272
-rm -f $GLANCE_DIR/glance.sqlite
260
+# Keystone
261
+# --------
262
+
263
+# (re)create keystone database
264
+mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'DROP DATABASE keystone;' || true
265
+mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'CREATE DATABASE keystone;'
266
+
267
+# FIXME (anthony) keystone should use keystone.conf.example
268
+KEYSTONE_CONF=$KEYSTONE_DIR/etc/keystone.conf
269
+cp $DIR/files/keystone.conf $KEYSTONE_CONF
270
+sudo sed -e "s,%SQL_CONN%,$BASE_SQL_CONN/keystone,g" -i $KEYSTONE_CONF
271
+
272
+# initialize keystone with default users/endpoints
273
+BIN_DIR=$KEYSTONE_DIR/bin bash $DIR/files/keystone_data.sh
274
+
273 275
 
274 276
 # Launch Services
275 277
 # ===============
276 278
 
277 279
 # nova api crashes if we start it with a regular screen command,
278 280
 # so send the start command by forcing text into the window.
281
+# Only run the services specified in ``ENABLED_SERVICES``
282
+
283
+NL=`echo -ne '\015'`
284
+
279 285
 function screen_it {
280
-    screen -S nova -X screen -t $1
281
-    screen -S nova -p $1 -X stuff "$2$NL"
286
+    if [[ "$ENABLED_SERVICES" =~ "$1" ]]; then
287
+        screen -S nova -X screen -t $1
288
+        screen -S nova -p $1 -X stuff "$2$NL"
289
+    fi
282 290
 }
283 291
 
284 292
 screen_it g-api "cd $GLANCE_DIR; bin/glance-api --config-file=etc/glance-api.conf"
285 293
 screen_it g-reg "cd $GLANCE_DIR; bin/glance-registry --config-file=etc/glance-registry.conf"
286 294
 # keystone drops a keystone.log where if it is run, so change the path to
287 295
 # where it can write
288
-screen_it key "cd /tmp; $KEYSTONE_DIR/bin/keystone --config-file $KEYSTONE_DIR/etc/keystone.conf"
296
+screen_it key "cd /tmp; $KEYSTONE_DIR/bin/keystone --config-file $KEYSTONE_CONF"
289 297
 screen_it n-api "$NOVA_DIR/bin/nova-api"
290 298
 screen_it n-cpu "$NOVA_DIR/bin/nova-compute"
291 299
 screen_it n-net "$NOVA_DIR/bin/nova-network"
... ...
@@ -314,4 +352,3 @@ tar -zxf $DEST/tty.tgz
314 314
 glance add name="tty-kernel" is_public=true container_format=aki disk_format=aki < aki-tty/image 
315 315
 glance add name="tty-ramdisk" is_public=true container_format=ari disk_format=ari < ari-tty/image 
316 316
 glance add name="tty" is_public=true container_format=ami disk_format=ami kernel_id=1 ramdisk_id=2 < ami-tty/image
317
-