Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
Jesse Andrews | 6f3baaf | 2011-09-12 11:59:38 -0700 | [diff] [blame] | 3 | # **stack.sh** is rackspace cloudbuilder's opinionated openstack dev installation. |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 4 | |
Jesse Andrews | be395c1 | 2011-09-12 19:11:30 -0700 | [diff] [blame] | 5 | # FIXME: commands should be: stack.sh should allow specifying a subset of services |
| 6 | |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 7 | # Quit script on error |
| 8 | set -o errexit |
| 9 | |
| 10 | # Log commands as they are run for debugging |
| 11 | set -o xtrace |
| 12 | |
| 13 | DIR=`pwd` |
| 14 | DEST=/opt |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 15 | |
Jesse Andrews | 6f3baaf | 2011-09-12 11:59:38 -0700 | [diff] [blame] | 16 | # Set the destination directories for openstack projects |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 17 | NOVA_DIR=$DEST/nova |
| 18 | DASH_DIR=$DEST/dash |
| 19 | GLANCE_DIR=$DEST/glance |
| 20 | KEYSTONE_DIR=$DEST/keystone |
| 21 | NOVACLIENT_DIR=$DEST/python-novaclient |
| 22 | API_DIR=$DEST/openstackx |
| 23 | NOVNC_DIR=$DEST/noVNC |
| 24 | |
| 25 | # Use the first IP unless an explicit is set by a HOST_IP environment variable |
| 26 | if [ ! -n "$HOST_IP" ]; then |
| 27 | HOST_IP=`LC_ALL=C ifconfig | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'` |
| 28 | fi |
| 29 | |
Jesse Andrews | be395c1 | 2011-09-12 19:11:30 -0700 | [diff] [blame] | 30 | # NOVA network / hypervisor configuration |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 31 | INTERFACE=${INTERFACE:-eth0} |
| 32 | FLOATING_RANGE=${FLOATING_RANGE:-10.6.0.0/27} |
| 33 | FIXED_RANGE=${FIXED_RANGE:-10.0.0.0/24} |
| 34 | LIBVIRT_TYPE=${LIBVIRT_TYPE:-qemu} |
| 35 | NET_MAN=${NET_MAN:-VlanManager} |
| 36 | # NOTE(vish): If you are using FlatDHCP on multiple hosts, set the interface |
| 37 | # below but make sure that the interface doesn't already have an |
| 38 | # ip or you risk breaking things. |
| 39 | # FLAT_INTERFACE=eth0 |
| 40 | |
Jesse Andrews | 2caf8fd | 2011-09-12 16:15:11 -0700 | [diff] [blame] | 41 | # TODO: switch to mysql for all services |
Jesse Andrews | 1c1d150 | 2011-09-12 19:29:56 -0700 | [diff] [blame] | 42 | MYSQL_PASS=${MYSQL_PASS:-nova} |
| 43 | SQL_CONN=${SQL_CONN:-mysql://root:$MYSQL_PASS@localhost/nova} |
| 44 | # TODO: set rabbitmq conn string explicitly as well |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 45 | |
Jesse Andrews | 1c1d150 | 2011-09-12 19:29:56 -0700 | [diff] [blame] | 46 | # seed configuration with mysql password |
| 47 | cat <<MYSQL_PRESEED | debconf-set-selections |
| 48 | mysql-server-5.1 mysql-server/root_password password $MYSQL_PASS |
| 49 | mysql-server-5.1 mysql-server/root_password_again password $MYSQL_PASS |
| 50 | mysql-server-5.1 mysql-server/start_on_boot boolean true |
| 51 | MYSQL_PRESEED |
Jesse Andrews | 2caf8fd | 2011-09-12 16:15:11 -0700 | [diff] [blame] | 52 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 53 | # install apt requirements |
| 54 | apt-get install -y -q `cat $DIR/apts/* | cut -d\# -f1` |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 55 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 56 | # install python requirements |
| 57 | pip install `cat $DIR/pips/*` |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 58 | |
Jesse Andrews | 6163257 | 2011-09-12 17:40:00 -0700 | [diff] [blame] | 59 | # git clone only if directory doesn't exist already |
| 60 | function git_clone { |
| 61 | if [ ! -d $2 ]; then |
| 62 | git clone $1 $2 |
| 63 | fi |
| 64 | } |
| 65 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 66 | # compute service |
Jesse Andrews | 6163257 | 2011-09-12 17:40:00 -0700 | [diff] [blame] | 67 | git_clone https://github.com/cloudbuilders/nova.git $NOVA_DIR |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 68 | # image catalog service |
Jesse Andrews | 6163257 | 2011-09-12 17:40:00 -0700 | [diff] [blame] | 69 | git_clone https://github.com/cloudbuilders/glance.git $GLANCE_DIR |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 70 | # unified auth system (manages accounts/tokens) |
Jesse Andrews | 6163257 | 2011-09-12 17:40:00 -0700 | [diff] [blame] | 71 | git_clone https://github.com/cloudbuilders/keystone.git $KEYSTONE_DIR |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 72 | # a websockets/html5 or flash powered VNC console for vm instances |
Jesse Andrews | 6163257 | 2011-09-12 17:40:00 -0700 | [diff] [blame] | 73 | git_clone https://github.com/cloudbuilders/noVNC.git $NOVNC_DIR |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 74 | # django powered web control panel for openstack |
Jesse Andrews | 6163257 | 2011-09-12 17:40:00 -0700 | [diff] [blame] | 75 | git_clone https://github.com/cloudbuilders/openstack-dashboard.git $DASH_DIR |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 76 | # python client library to nova that dashboard (and others) use |
Jesse Andrews | 6163257 | 2011-09-12 17:40:00 -0700 | [diff] [blame] | 77 | git_clone https://github.com/cloudbuilders/python-novaclient.git $NOVACLIENT_DIR |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 78 | # openstackx is a collection of extensions to openstack.compute & nova |
| 79 | # that is *deprecated*. The code is being moved into python-novaclient & nova. |
Jesse Andrews | 6163257 | 2011-09-12 17:40:00 -0700 | [diff] [blame] | 80 | git_clone https://github.com/cloudbuilders/openstackx.git $API_DIR |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 81 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 82 | # setup our checkouts so they are installed into python path |
| 83 | # allowing `import nova` or `import glance.client` |
| 84 | cd $NOVACLIENT_DIR; python setup.py develop |
| 85 | cd $KEYSTONE_DIR; python setup.py develop |
| 86 | cd $GLANCE_DIR; python setup.py develop |
| 87 | cd $API_DIR; python setup.py develop |
| 88 | cd $DASH_DIR/django-openstack; python setup.py develop |
| 89 | cd $DASH_DIR/openstack-dashboard; python setup.py develop |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 90 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 91 | # attempt to load modules: kvm (hardware virt) and nbd (network block |
| 92 | # device - used to manage qcow images) |
| 93 | modprobe nbd || true |
| 94 | modprobe kvm || true |
| 95 | # if kvm wasn't running before we need to restart libvirt to enable it |
| 96 | /etc/init.d/libvirt-bin restart |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 97 | |
Jesse Andrews | be395c1 | 2011-09-12 19:11:30 -0700 | [diff] [blame] | 98 | # FIXME(ja): should LIBVIRT_TYPE be kvm if kvm module is loaded? |
| 99 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 100 | # setup nova instance directory |
| 101 | mkdir -p $NOVA_DIR/instances |
Jesse Andrews | 6f3baaf | 2011-09-12 11:59:38 -0700 | [diff] [blame] | 102 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 103 | # if there is a partition labeled nova-instances use it (ext filesystems |
| 104 | # can be labeled via e2label) |
Jesse Andrews | 834531c | 2011-09-12 19:37:57 -0700 | [diff] [blame^] | 105 | # FIXME: if already mounted this blows up... |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 106 | if [ -L /dev/disk/by-label/nova-instances ]; then |
Jesse Andrews | 834531c | 2011-09-12 19:37:57 -0700 | [diff] [blame^] | 107 | mount -L nova-instances $NOVA_DIR/instances |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 108 | fi |
| 109 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 110 | # *Dashboard*: setup django application to serve via apache/wsgi |
| 111 | |
| 112 | # Dash currently imports quantum even if you aren't using it. Instead |
| 113 | # of installing quantum we can create a simple module that will pass the |
| 114 | # initial imports |
Jesse Andrews | 834531c | 2011-09-12 19:37:57 -0700 | [diff] [blame^] | 115 | mkdir $DASH_DIR/openstack-dashboard/quantum || true |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 116 | touch $DASH_DIR/openstack-dashboard/quantum/__init__.py |
| 117 | touch $DASH_DIR/openstack-dashboard/quantum/client.py |
Jesse Andrews | 1c1d150 | 2011-09-12 19:29:56 -0700 | [diff] [blame] | 118 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 119 | cd $DASH_DIR/openstack-dashboard |
| 120 | cp local/local_settings.py.example local/local_settings.py |
| 121 | dashboard/manage.py syncdb |
| 122 | |
| 123 | # ## Setup Apache |
| 124 | # create an empty directory to use as our |
| 125 | mkdir $DASH_DIR/.blackhole |
Jesse Andrews | 1c1d150 | 2011-09-12 19:29:56 -0700 | [diff] [blame] | 126 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 127 | # FIXME(ja): can't figure out how to make $DASH_DIR work in sed, also install to available/a2e it |
| 128 | cat $DIR/files/000-default.template | sed 's/%DASH_DIR%/\/opt\/dash/g' > /etc/apache2/sites-enabled/000-default |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 129 | chown -R www-data:www-data $DASH_DIR |
| 130 | |
| 131 | mkdir -p /var/log/glance |
| 132 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 133 | # add useful screenrc |
| 134 | cp $DIR/files/screenrc ~/.screenrc |
| 135 | |
| 136 | # TODO: update current user to allow sudo for all commands in files/sudo/* |
| 137 | |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 138 | NL=`echo -ne '\015'` |
| 139 | |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 140 | |
| 141 | function add_nova_flag { |
| 142 | echo "$1" >> $NOVA_DIR/bin/nova.conf |
| 143 | } |
| 144 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 145 | # (re)create nova.conf |
| 146 | rm -f $NOVA_DIR/bin/nova.conf |
| 147 | add_nova_flag "--verbose" |
| 148 | add_nova_flag "--nodaemon" |
| 149 | add_nova_flag "--dhcpbridge_flagfile=$NOVA_DIR/bin/nova.conf" |
| 150 | add_nova_flag "--network_manager=nova.network.manager.$NET_MAN" |
| 151 | add_nova_flag "--my_ip=$HOST_IP" |
| 152 | add_nova_flag "--public_interface=$INTERFACE" |
| 153 | add_nova_flag "--vlan_interface=$INTERFACE" |
| 154 | add_nova_flag "--sql_connection=$SQL_CONN" |
| 155 | add_nova_flag "--libvirt_type=$LIBVIRT_TYPE" |
| 156 | add_nova_flag "--osapi_extensions_path=$API_DIR/extensions" |
| 157 | add_nova_flag "--vncproxy_url=http://$HOST_IP:6080" |
| 158 | add_nova_flag "--vncproxy_wwwroot=$NOVNC_DIR/noVNC/noVNC" |
| 159 | add_nova_flag "--api_paste_config=$KEYSTONE_DIR/examples/paste/nova-api-paste.ini" |
| 160 | add_nova_flag "--image_service=nova.image.glance.GlanceImageService" |
| 161 | if [ -n "$FLAT_INTERFACE" ]; then |
| 162 | add_nova_flag "--flat_interface=$FLAT_INTERFACE" |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 163 | fi |
| 164 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 165 | # create a new named screen to store things in |
| 166 | screen -d -m -S nova -t nova |
| 167 | sleep 1 |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 168 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 169 | # Clean out the instances directory |
| 170 | rm -rf $NOVA_DIR/instances/* |
| 171 | |
| 172 | # delete traces of nova networks from prior runs |
| 173 | killall dnsmasq || true |
| 174 | rm -rf $NOVA_DIR/networks |
| 175 | mkdir -p $NOVA_DIR/networks |
| 176 | |
| 177 | # (re)create nova database |
Jesse Andrews | 834531c | 2011-09-12 19:37:57 -0700 | [diff] [blame^] | 178 | mysql -p$MYSQL_PASS -e 'DROP DATABASE nova;' || true |
Jesse Andrews | 1c1d150 | 2011-09-12 19:29:56 -0700 | [diff] [blame] | 179 | mysql -p$MYSQL_PASS -e 'CREATE DATABASE nova;' |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 180 | $NOVA_DIR/bin/nova-manage db sync |
| 181 | |
| 182 | # initialize keystone with default users/endpoints |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 183 | rm -f /opt/keystone/keystone.db |
Jesse Andrews | 73e27b8 | 2011-09-12 17:55:00 -0700 | [diff] [blame] | 184 | BIN_DIR=$KEYSTONE_DIR/bin bash $DIR/files/keystone_data.sh |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 185 | |
| 186 | # create a small network |
| 187 | $NOVA_DIR/bin/nova-manage network create private $FIXED_RANGE 1 32 |
| 188 | |
| 189 | # create some floating ips |
| 190 | $NOVA_DIR/bin/nova-manage floating create $FLOATING_RANGE |
| 191 | |
| 192 | # delete existing glance images/database. Glance will recreate the db |
| 193 | # when it is ran. |
| 194 | rm -rf /var/lib/glance/images/* |
| 195 | rm -f $GLANCE_DIR/glance.sqlite |
| 196 | |
Jesse Andrews | 1c1d150 | 2011-09-12 19:29:56 -0700 | [diff] [blame] | 197 | # nova api crashes if we start it with a regular screen command, |
| 198 | # so send the start command by forcing text into the window. |
| 199 | function screen_it { |
| 200 | screen -S nova -X screen -t $1 |
| 201 | screen -S nova -p $1 -X stuff "$2$NL" |
| 202 | } |
| 203 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 204 | screen_it g-api "cd $GLANCE_DIR; bin/glance-api --config-file=etc/glance-api.conf" |
| 205 | screen_it g-reg "cd $GLANCE_DIR; bin/glance-registry --config-file=etc/glance-registry.conf" |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 206 | screen_it key "$KEYSTONE_DIR/bin/keystone --config-file $KEYSTONE_DIR/etc/keystone.conf" |
Jesse Andrews | 55508d6 | 2011-09-12 19:00:28 -0700 | [diff] [blame] | 207 | screen_it n-api "$NOVA_DIR/bin/nova-api" |
| 208 | screen_it n-cpu "$NOVA_DIR/bin/nova-compute" |
| 209 | screen_it n-net "$NOVA_DIR/bin/nova-network" |
| 210 | screen_it n-sch "$NOVA_DIR/bin/nova-scheduler" |
| 211 | screen_it n-vnc "$NOVA_DIR/bin/nova-vncproxy" |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 212 | screen_it dash "/etc/init.d/apache2 restart; tail -f /var/log/apache2/error.log" |
| 213 | |
Jesse Andrews | e49b8bd | 2011-09-12 18:08:04 -0700 | [diff] [blame] | 214 | |
Jesse Andrews | e49b8bd | 2011-09-12 18:08:04 -0700 | [diff] [blame] | 215 | # ---- download an install images ---- |
| 216 | |
| 217 | mkdir -p $DEST/images |
| 218 | cd $DEST/images |
| 219 | # prepare initial images for loading into glance |
| 220 | if [ ! -f $DEST/tty.tgz ]; then |
Jesse Andrews | be395c1 | 2011-09-12 19:11:30 -0700 | [diff] [blame] | 221 | wget -c http://images.ansolabs.com/tty.tgz -O $DEST/tty.tgz |
Jesse Andrews | e49b8bd | 2011-09-12 18:08:04 -0700 | [diff] [blame] | 222 | fi |
| 223 | |
| 224 | # extract ami-tty/image, aki-tty/image & ari-tty/image |
Jesse Andrews | be395c1 | 2011-09-12 19:11:30 -0700 | [diff] [blame] | 225 | tar -zxf $DEST/tty.tgz |
Jesse Andrews | e49b8bd | 2011-09-12 18:08:04 -0700 | [diff] [blame] | 226 | |
Jesse Andrews | be395c1 | 2011-09-12 19:11:30 -0700 | [diff] [blame] | 227 | # add images to glance |
| 228 | # FIXME: kernel/ramdisk is hardcoded - use return result from add |
Jesse Andrews | e49b8bd | 2011-09-12 18:08:04 -0700 | [diff] [blame] | 229 | glance add name="tty-kernel" is_public=true container_format=aki disk_format=aki < aki-tty/image |
| 230 | glance add name="tty-ramdisk" is_public=true container_format=ari disk_format=ari < ari-tty/image |
| 231 | glance add name="tty" is_public=true container_format=ami disk_format=ami kernel_id=1 ramdisk_id=2 < ami-tty/image |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 232 | |