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 | |
| 5 | # Quit script on error |
| 6 | set -o errexit |
| 7 | |
| 8 | # Log commands as they are run for debugging |
| 9 | set -o xtrace |
| 10 | |
| 11 | DIR=`pwd` |
| 12 | DEST=/opt |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 13 | |
Jesse Andrews | 6f3baaf | 2011-09-12 11:59:38 -0700 | [diff] [blame] | 14 | # Set the destination directories for openstack projects |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 15 | NOVA_DIR=$DEST/nova |
| 16 | DASH_DIR=$DEST/dash |
| 17 | GLANCE_DIR=$DEST/glance |
| 18 | KEYSTONE_DIR=$DEST/keystone |
| 19 | NOVACLIENT_DIR=$DEST/python-novaclient |
| 20 | API_DIR=$DEST/openstackx |
| 21 | NOVNC_DIR=$DEST/noVNC |
| 22 | |
| 23 | # Use the first IP unless an explicit is set by a HOST_IP environment variable |
| 24 | if [ ! -n "$HOST_IP" ]; then |
| 25 | HOST_IP=`LC_ALL=C ifconfig | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'` |
| 26 | fi |
| 27 | |
| 28 | # NOVA CONFIGURATION |
| 29 | INTERFACE=${INTERFACE:-eth0} |
| 30 | FLOATING_RANGE=${FLOATING_RANGE:-10.6.0.0/27} |
| 31 | FIXED_RANGE=${FIXED_RANGE:-10.0.0.0/24} |
| 32 | LIBVIRT_TYPE=${LIBVIRT_TYPE:-qemu} |
| 33 | NET_MAN=${NET_MAN:-VlanManager} |
| 34 | # NOTE(vish): If you are using FlatDHCP on multiple hosts, set the interface |
| 35 | # below but make sure that the interface doesn't already have an |
| 36 | # ip or you risk breaking things. |
| 37 | # FLAT_INTERFACE=eth0 |
| 38 | |
Jesse Andrews | 2caf8fd | 2011-09-12 16:15:11 -0700 | [diff] [blame] | 39 | # TODO: set rabbitmq conn string explicitly as well |
| 40 | # TODO: switch to mysql for all services |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 41 | SQL_CONN=sqlite:///$NOVA_DIR/nova.sqlite |
| 42 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 43 | # FIXME: commands should be: stack.sh should allow specifying a subset of services |
Jesse Andrews | 2caf8fd | 2011-09-12 16:15:11 -0700 | [diff] [blame] | 44 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 45 | # install apt requirements |
| 46 | apt-get install -y -q `cat $DIR/apts/* | cut -d\# -f1` |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 47 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 48 | # install python requirements |
| 49 | pip install `cat $DIR/pips/*` |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 50 | |
Jesse Andrews | 6163257 | 2011-09-12 17:40:00 -0700 | [diff] [blame^] | 51 | # git clone only if directory doesn't exist already |
| 52 | function git_clone { |
| 53 | if [ ! -d $2 ]; then |
| 54 | git clone $1 $2 |
| 55 | fi |
| 56 | } |
| 57 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 58 | # compute service |
Jesse Andrews | 6163257 | 2011-09-12 17:40:00 -0700 | [diff] [blame^] | 59 | git_clone https://github.com/cloudbuilders/nova.git $NOVA_DIR |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 60 | # image catalog service |
Jesse Andrews | 6163257 | 2011-09-12 17:40:00 -0700 | [diff] [blame^] | 61 | git_clone https://github.com/cloudbuilders/glance.git $GLANCE_DIR |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 62 | # unified auth system (manages accounts/tokens) |
Jesse Andrews | 6163257 | 2011-09-12 17:40:00 -0700 | [diff] [blame^] | 63 | git_clone https://github.com/cloudbuilders/keystone.git $KEYSTONE_DIR |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 64 | # a websockets/html5 or flash powered VNC console for vm instances |
Jesse Andrews | 6163257 | 2011-09-12 17:40:00 -0700 | [diff] [blame^] | 65 | git_clone https://github.com/cloudbuilders/noVNC.git $NOVNC_DIR |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 66 | # django powered web control panel for openstack |
Jesse Andrews | 6163257 | 2011-09-12 17:40:00 -0700 | [diff] [blame^] | 67 | git_clone https://github.com/cloudbuilders/openstack-dashboard.git $DASH_DIR |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 68 | # python client library to nova that dashboard (and others) use |
Jesse Andrews | 6163257 | 2011-09-12 17:40:00 -0700 | [diff] [blame^] | 69 | git_clone https://github.com/cloudbuilders/python-novaclient.git $NOVACLIENT_DIR |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 70 | # openstackx is a collection of extensions to openstack.compute & nova |
| 71 | # that is *deprecated*. The code is being moved into python-novaclient & nova. |
Jesse Andrews | 6163257 | 2011-09-12 17:40:00 -0700 | [diff] [blame^] | 72 | git_clone https://github.com/cloudbuilders/openstackx.git $API_DIR |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 73 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 74 | # setup our checkouts so they are installed into python path |
| 75 | # allowing `import nova` or `import glance.client` |
| 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 Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 82 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 83 | # attempt to load modules: kvm (hardware virt) and nbd (network block |
| 84 | # device - used to manage qcow images) |
| 85 | modprobe nbd || true |
| 86 | modprobe kvm || true |
| 87 | # if kvm wasn't running before we need to restart libvirt to enable it |
| 88 | /etc/init.d/libvirt-bin restart |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 89 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 90 | # setup nova instance directory |
| 91 | mkdir -p $NOVA_DIR/instances |
Jesse Andrews | 6f3baaf | 2011-09-12 11:59:38 -0700 | [diff] [blame] | 92 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 93 | # if there is a partition labeled nova-instances use it (ext filesystems |
| 94 | # can be labeled via e2label) |
| 95 | if [ -L /dev/disk/by-label/nova-instances ]; then |
| 96 | mount -L nova-instances /$NOVA_DIR/instances |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 97 | fi |
| 98 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 99 | # *Dashboard*: setup django application to serve via apache/wsgi |
| 100 | |
| 101 | # Dash currently imports quantum even if you aren't using it. Instead |
| 102 | # of installing quantum we can create a simple module that will pass the |
| 103 | # initial imports |
| 104 | mkdir $DASH_DIR/openstack-dashboard/quantum |
| 105 | touch $DASH_DIR/openstack-dashboard/quantum/__init__.py |
| 106 | touch $DASH_DIR/openstack-dashboard/quantum/client.py |
| 107 | # local_settings has |
| 108 | cd $DASH_DIR/openstack-dashboard |
| 109 | cp local/local_settings.py.example local/local_settings.py |
| 110 | dashboard/manage.py syncdb |
| 111 | |
| 112 | # ## Setup Apache |
| 113 | # create an empty directory to use as our |
| 114 | mkdir $DASH_DIR/.blackhole |
| 115 | # FIXME(ja): can't figure out how to make $DASH_DIR work in sed, also install to available/a2e it |
| 116 | cat $DIR/files/000-default.template | sed 's/%DASH_DIR%/\/opt\/dash/g' > /etc/apache2/sites-enabled/000-default |
| 117 | |
| 118 | chown -R www-data:www-data $DASH_DIR |
| 119 | |
| 120 | mkdir -p /var/log/glance |
| 121 | |
| 122 | # prepare initial images for loading into glance |
| 123 | if [ ! -f $DEST/tty.tgz ]; then |
| 124 | wget -c http://images.ansolabs.com/tty.tgz -O $DEST/tty.tgz |
| 125 | fi |
| 126 | |
| 127 | mkdir -p $DEST/images |
| 128 | tar -C $DEST/images -zxf $DEST/tty.tgz |
| 129 | |
| 130 | # add useful screenrc |
| 131 | cp $DIR/files/screenrc ~/.screenrc |
| 132 | |
| 133 | # TODO: update current user to allow sudo for all commands in files/sudo/* |
| 134 | |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 135 | NL=`echo -ne '\015'` |
| 136 | |
| 137 | function screen_it { |
Jesse Andrews | 6f3baaf | 2011-09-12 11:59:38 -0700 | [diff] [blame] | 138 | # nova api crashes if we start it with a regular screen command, |
| 139 | # so send the start command by forcing text into the window. |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 140 | screen -S nova -X screen -t $1 |
| 141 | screen -S nova -p $1 -X stuff "$2$NL" |
| 142 | } |
| 143 | |
| 144 | function add_nova_flag { |
| 145 | echo "$1" >> $NOVA_DIR/bin/nova.conf |
| 146 | } |
| 147 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 148 | # (re)create nova.conf |
| 149 | rm -f $NOVA_DIR/bin/nova.conf |
| 150 | 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" |
| 162 | add_nova_flag "--api_paste_config=$KEYSTONE_DIR/examples/paste/nova-api-paste.ini" |
| 163 | add_nova_flag "--image_service=nova.image.glance.GlanceImageService" |
| 164 | if [ -n "$FLAT_INTERFACE" ]; then |
| 165 | add_nova_flag "--flat_interface=$FLAT_INTERFACE" |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 166 | fi |
| 167 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 168 | # create a new named screen to store things in |
| 169 | screen -d -m -S nova -t nova |
| 170 | sleep 1 |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 171 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 172 | # Clean out the instances directory |
| 173 | rm -rf $NOVA_DIR/instances/* |
| 174 | |
| 175 | # delete traces of nova networks from prior runs |
| 176 | killall dnsmasq || true |
| 177 | rm -rf $NOVA_DIR/networks |
| 178 | mkdir -p $NOVA_DIR/networks |
| 179 | |
| 180 | # (re)create nova database |
| 181 | rm -f $NOVA_DIR/nova.sqlite |
| 182 | $NOVA_DIR/bin/nova-manage db sync |
| 183 | |
| 184 | # initialize keystone with default users/endpoints |
| 185 | # FIXME(ja): move initial_data.sh into this script |
| 186 | rm -f /opt/keystone/keystone.db |
| 187 | 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 | |
| 196 | # delete existing glance images/database. Glance will recreate the db |
| 197 | # when it is ran. |
| 198 | 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" |
| 208 | screen_it vnc "$NOVA_DIR/bin/nova-vncproxy" |
| 209 | screen_it dash "/etc/init.d/apache2 restart; tail -f /var/log/apache2/error.log" |
| 210 | |
| 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 |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 215 | |