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 | c4b3aab | 2011-09-15 22:54:52 -0700 | [diff] [blame] | 5 | # To keep this script simple we assume you are running on an **Ubuntu 11.04 |
Jesse Andrews | 2485906 | 2011-09-15 21:28:23 -0700 | [diff] [blame] | 6 | # Natty** machine. It should work in a VM or physical server. Additionally we |
| 7 | # put the list of *apt* and *pip* dependencies and other configuration files in |
| 8 | # this repo. So start by grabbing this script and the dependencies. |
| 9 | |
Jesse Andrews | 6edd17f | 2011-09-15 22:19:42 -0700 | [diff] [blame] | 10 | |
| 11 | # Sanity Check |
| 12 | # ============ |
| 13 | |
Jesse Andrews | c4b3aab | 2011-09-15 22:54:52 -0700 | [diff] [blame] | 14 | # Warn users who aren't on natty, but allow them to override check and attempt |
Jesse Andrews | 6edd17f | 2011-09-15 22:19:42 -0700 | [diff] [blame] | 15 | # installation with ``FORCE=yes ./stack`` |
Jesse Andrews | 6edd17f | 2011-09-15 22:19:42 -0700 | [diff] [blame] | 16 | if ! grep -q natty /etc/lsb-release; then |
| 17 | echo "WARNING: this script has only been tested on natty" |
| 18 | if [[ "$FORCE" != "yes" ]]; then |
| 19 | echo "If you wish to run this script anyway run with FORCE=yes" |
| 20 | exit 1 |
| 21 | fi |
| 22 | fi |
| 23 | |
Jesse Andrews | 4d28218 | 2011-09-16 11:27:43 -0700 | [diff] [blame] | 24 | # stack.sh keeps the list of **apt** and **pip** dependencies in external |
| 25 | # files, along with config templates and other useful files. You can find these |
| 26 | # in the ``files`` directory (next to this script). We will reference this |
Jesse Andrews | bf3868d | 2011-09-16 11:31:16 -0700 | [diff] [blame] | 27 | # directory using the ``FILES`` variable in this script. |
| 28 | FILES=`pwd`/files |
| 29 | if [ ! -d $FILES ]; then |
| 30 | echo "ERROR: missing devstack/files - did you grab more than just stack.sh?" |
Jesse Andrews | 6edd17f | 2011-09-15 22:19:42 -0700 | [diff] [blame] | 31 | exit 1 |
| 32 | fi |
| 33 | |
| 34 | # Settings |
| 35 | # ======== |
Jesse Andrews | 30f68e9 | 2011-09-13 00:59:54 -0700 | [diff] [blame] | 36 | |
Jesse Andrews | d74257d | 2011-09-13 01:24:50 -0700 | [diff] [blame] | 37 | # This script is customizable through setting environment variables. If you |
| 38 | # want to override a setting you can either:: |
| 39 | # |
| 40 | # export MYSQL_PASS=anothersecret |
| 41 | # ./stack.sh |
| 42 | # |
Jesse Andrews | 6edd17f | 2011-09-15 22:19:42 -0700 | [diff] [blame] | 43 | # You can also pass options on a single line ``MYSQL_PASS=simple ./stack.sh`` |
| 44 | # |
| 45 | # We try to have sensible defaults, so you should be able to run ``./stack.sh`` |
| 46 | # in most cases. |
Jesse Andrews | d74257d | 2011-09-13 01:24:50 -0700 | [diff] [blame] | 47 | |
Jesse Andrews | 6edd17f | 2011-09-15 22:19:42 -0700 | [diff] [blame] | 48 | # So that errors don't compound we exit on any errors so you see only the |
| 49 | # first error that occured. |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 50 | set -o errexit |
| 51 | |
Jesse Andrews | d74257d | 2011-09-13 01:24:50 -0700 | [diff] [blame] | 52 | # Print the commands being run so that we can see the command that triggers |
| 53 | # an error. It is also useful for following allowing as the install occurs. |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 54 | set -o xtrace |
| 55 | |
Jesse Andrews | 6edd17f | 2011-09-15 22:19:42 -0700 | [diff] [blame] | 56 | # Destination path for installation ``DEST`` |
| 57 | DEST=${DEST:-/opt} |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 58 | |
Jesse Andrews | 6f3baaf | 2011-09-12 11:59:38 -0700 | [diff] [blame] | 59 | # Set the destination directories for openstack projects |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 60 | NOVA_DIR=$DEST/nova |
| 61 | DASH_DIR=$DEST/dash |
Jake Dahn | 9337b33 | 2011-09-15 21:46:20 -0700 | [diff] [blame] | 62 | NIXON_DIR=$DEST/dash/openstack-dashboard/dashboard/nixon |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 63 | GLANCE_DIR=$DEST/glance |
| 64 | KEYSTONE_DIR=$DEST/keystone |
| 65 | NOVACLIENT_DIR=$DEST/python-novaclient |
| 66 | API_DIR=$DEST/openstackx |
| 67 | NOVNC_DIR=$DEST/noVNC |
Dean Troyer | 0017c8f | 2011-09-13 15:37:50 -0500 | [diff] [blame] | 68 | MUNIN_DIR=$DEST/openstack-munin |
Anthony Young | a841644 | 2011-09-13 20:07:44 -0700 | [diff] [blame] | 69 | |
| 70 | # Specify which services to launch. These generally correspond to screen tabs |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 71 | ENABLED_SERVICES=${ENABLED_SERVICES:-g-api,g-reg,key,n-api,n-cpu,n-net,n-sch,n-vnc,dash,mysql,rabbit} |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 72 | |
Jesse Andrews | d74257d | 2011-09-13 01:24:50 -0700 | [diff] [blame] | 73 | # Use the first IP unless an explicit is set by ``HOST_IP`` environment variable |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 74 | if [ ! -n "$HOST_IP" ]; then |
Dean Troyer | 2a15a7c | 2011-09-13 13:22:14 -0500 | [diff] [blame] | 75 | HOST_IP=`LC_ALL=C /sbin/ifconfig | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'` |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 76 | fi |
| 77 | |
Jesse Andrews | d74257d | 2011-09-13 01:24:50 -0700 | [diff] [blame] | 78 | # Nova network configuration |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 79 | INTERFACE=${INTERFACE:-eth0} |
| 80 | FLOATING_RANGE=${FLOATING_RANGE:-10.6.0.0/27} |
| 81 | FIXED_RANGE=${FIXED_RANGE:-10.0.0.0/24} |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 82 | NET_MAN=${NET_MAN:-VlanManager} |
Anthony Young | a841644 | 2011-09-13 20:07:44 -0700 | [diff] [blame] | 83 | EC2_DMZ_HOST=${EC2_DMZ_HOST:-$HOST_IP} |
Jesse Andrews | 30f68e9 | 2011-09-13 00:59:54 -0700 | [diff] [blame] | 84 | |
Jesse Andrews | d74257d | 2011-09-13 01:24:50 -0700 | [diff] [blame] | 85 | # If you are using FlatDHCP on multiple hosts, set the ``FLAT_INTERFACE`` |
| 86 | # variable but make sure that the interface doesn't already have an |
| 87 | # ip or you risk breaking things. |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 88 | # FLAT_INTERFACE=eth0 |
| 89 | |
Jesse Andrews | d74257d | 2011-09-13 01:24:50 -0700 | [diff] [blame] | 90 | # Nova hypervisor configuration |
| 91 | LIBVIRT_TYPE=${LIBVIRT_TYPE:-qemu} |
| 92 | |
Anthony Young | a841644 | 2011-09-13 20:07:44 -0700 | [diff] [blame] | 93 | # Mysql connection info |
Anthony Young | 320412b | 2011-09-14 02:39:10 -0700 | [diff] [blame] | 94 | MYSQL_USER=${MYSQL_USER:-root} |
Anthony Young | 1c36464 | 2011-09-13 20:21:42 -0700 | [diff] [blame] | 95 | MYSQL_PASS=${MYSQL_PASS:-nova} |
Anthony Young | a841644 | 2011-09-13 20:07:44 -0700 | [diff] [blame] | 96 | MYSQL_HOST=${MYSQL_HOST:-localhost} |
| 97 | # don't specify /db in this string, so we can use it for multiple services |
Anthony Young | fdaf21a | 2011-09-13 20:11:42 -0700 | [diff] [blame] | 98 | BASE_SQL_CONN=${BASE_SQL_CONN:-mysql://$MYSQL_USER:$MYSQL_PASS@$MYSQL_HOST} |
Anthony Young | a841644 | 2011-09-13 20:07:44 -0700 | [diff] [blame] | 99 | |
| 100 | # Rabbit connection info |
| 101 | RABBIT_HOST=${RABBIT_HOST:-localhost} |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 102 | |
Anthony Young | 377aae6 | 2011-09-14 09:55:31 -0700 | [diff] [blame] | 103 | # Glance connection info. Note the port must be specified. |
| 104 | GLANCE_HOSTPORT=${GLANCE_HOSTPORT:-0.0.0.0:9292} |
| 105 | |
Jesse Andrews | 30f68e9 | 2011-09-13 00:59:54 -0700 | [diff] [blame] | 106 | # Install Packages |
Jesse Andrews | d74257d | 2011-09-13 01:24:50 -0700 | [diff] [blame] | 107 | # ================ |
Jesse Andrews | 30f68e9 | 2011-09-13 00:59:54 -0700 | [diff] [blame] | 108 | # |
| 109 | # Openstack uses a fair number of other projects. |
| 110 | |
Jesse Andrews | d74257d | 2011-09-13 01:24:50 -0700 | [diff] [blame] | 111 | # Seed configuration with mysql password so that apt-get install doesn't |
| 112 | # prompt us for a password upon install. |
Jesse Andrews | 18d350d | 2011-09-12 21:46:12 -0700 | [diff] [blame] | 113 | cat <<MYSQL_PRESEED | sudo debconf-set-selections |
Jesse Andrews | 1c1d150 | 2011-09-12 19:29:56 -0700 | [diff] [blame] | 114 | mysql-server-5.1 mysql-server/root_password password $MYSQL_PASS |
| 115 | mysql-server-5.1 mysql-server/root_password_again password $MYSQL_PASS |
| 116 | mysql-server-5.1 mysql-server/start_on_boot boolean true |
| 117 | MYSQL_PRESEED |
Jesse Andrews | 2caf8fd | 2011-09-12 16:15:11 -0700 | [diff] [blame] | 118 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 119 | # install apt requirements |
Jesse Andrews | bf3868d | 2011-09-16 11:31:16 -0700 | [diff] [blame] | 120 | sudo apt-get install -y -q `cat $FILES/apts/* | cut -d\# -f1 | grep -Ev "mysql-server|rabbitmq-server"` |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 121 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 122 | # install python requirements |
Jesse Andrews | bf3868d | 2011-09-16 11:31:16 -0700 | [diff] [blame] | 123 | sudo PIP_DOWNLOAD_CACHE=/var/cache/pip pip install `cat $FILES/pips/*` |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 124 | |
Jesse Andrews | d61db85 | 2011-09-16 14:13:17 -0700 | [diff] [blame] | 125 | # git clone only if directory doesn't exist already. Since ``DEST`` might not |
| 126 | # be owned by the installation user, we create the directory and change the |
| 127 | # ownership to the proper user. |
Jesse Andrews | 6163257 | 2011-09-12 17:40:00 -0700 | [diff] [blame] | 128 | function git_clone { |
| 129 | if [ ! -d $2 ]; then |
Jesse Andrews | d61db85 | 2011-09-16 14:13:17 -0700 | [diff] [blame] | 130 | sudo mkdir $2 |
| 131 | sudo chown `whoami` $2 |
Jesse Andrews | 6163257 | 2011-09-12 17:40:00 -0700 | [diff] [blame] | 132 | git clone $1 $2 |
| 133 | fi |
| 134 | } |
| 135 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 136 | # compute service |
Jesse Andrews | 6163257 | 2011-09-12 17:40:00 -0700 | [diff] [blame] | 137 | git_clone https://github.com/cloudbuilders/nova.git $NOVA_DIR |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 138 | # image catalog service |
Jesse Andrews | 6163257 | 2011-09-12 17:40:00 -0700 | [diff] [blame] | 139 | git_clone https://github.com/cloudbuilders/glance.git $GLANCE_DIR |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 140 | # unified auth system (manages accounts/tokens) |
Jesse Andrews | 6163257 | 2011-09-12 17:40:00 -0700 | [diff] [blame] | 141 | git_clone https://github.com/cloudbuilders/keystone.git $KEYSTONE_DIR |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 142 | # a websockets/html5 or flash powered VNC console for vm instances |
Jesse Andrews | 6163257 | 2011-09-12 17:40:00 -0700 | [diff] [blame] | 143 | git_clone https://github.com/cloudbuilders/noVNC.git $NOVNC_DIR |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 144 | # django powered web control panel for openstack |
Jesse Andrews | 6163257 | 2011-09-12 17:40:00 -0700 | [diff] [blame] | 145 | git_clone https://github.com/cloudbuilders/openstack-dashboard.git $DASH_DIR |
Jake Dahn | a3492ed | 2011-09-15 22:42:43 -0700 | [diff] [blame] | 146 | # add nixon, will use this to show munin graphs in dashboard |
Jake Dahn | 38fc665 | 2011-09-15 22:58:06 -0700 | [diff] [blame] | 147 | git_clone https://github.com/cloudbuilders/nixon.git $NIXON_DIR |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 148 | # python client library to nova that dashboard (and others) use |
Jesse Andrews | 6163257 | 2011-09-12 17:40:00 -0700 | [diff] [blame] | 149 | git_clone https://github.com/cloudbuilders/python-novaclient.git $NOVACLIENT_DIR |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 150 | # openstackx is a collection of extensions to openstack.compute & nova |
| 151 | # that is *deprecated*. The code is being moved into python-novaclient & nova. |
Jesse Andrews | 6163257 | 2011-09-12 17:40:00 -0700 | [diff] [blame] | 152 | git_clone https://github.com/cloudbuilders/openstackx.git $API_DIR |
Dean Troyer | 0017c8f | 2011-09-13 15:37:50 -0500 | [diff] [blame] | 153 | # openstack-munin is a collection of munin plugins for monitoring the stack |
| 154 | git_clone https://github.com/cloudbuilders/openstack-munin.git $MUNIN_DIR |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 155 | |
Jesse Andrews | 30f68e9 | 2011-09-13 00:59:54 -0700 | [diff] [blame] | 156 | # Initialization |
Jesse Andrews | d74257d | 2011-09-13 01:24:50 -0700 | [diff] [blame] | 157 | # ============== |
Jesse Andrews | 30f68e9 | 2011-09-13 00:59:54 -0700 | [diff] [blame] | 158 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 159 | # setup our checkouts so they are installed into python path |
Jesse Andrews | d74257d | 2011-09-13 01:24:50 -0700 | [diff] [blame] | 160 | # allowing ``import nova`` or ``import glance.client`` |
Dean Troyer | 0017c8f | 2011-09-13 15:37:50 -0500 | [diff] [blame] | 161 | cd $NOVA_DIR; sudo python setup.py develop |
Jesse Andrews | 18d350d | 2011-09-12 21:46:12 -0700 | [diff] [blame] | 162 | cd $NOVACLIENT_DIR; sudo python setup.py develop |
| 163 | cd $KEYSTONE_DIR; sudo python setup.py develop |
| 164 | cd $GLANCE_DIR; sudo python setup.py develop |
| 165 | cd $API_DIR; sudo python setup.py develop |
| 166 | cd $DASH_DIR/django-openstack; sudo python setup.py develop |
| 167 | cd $DASH_DIR/openstack-dashboard; sudo python setup.py develop |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 168 | |
Jesse Andrews | 6edd17f | 2011-09-15 22:19:42 -0700 | [diff] [blame] | 169 | # Add a useful screenrc. This isn't required to run openstack but is we do |
| 170 | # it since we are going to run the services in screen for simple |
Jesse Andrews | bf3868d | 2011-09-16 11:31:16 -0700 | [diff] [blame] | 171 | cp $FILES/screenrc ~/.screenrc |
Jesse Andrews | 6f3baaf | 2011-09-12 11:59:38 -0700 | [diff] [blame] | 172 | |
Jesse Andrews | 6edd17f | 2011-09-15 22:19:42 -0700 | [diff] [blame] | 173 | ## TODO: update current user to allow sudo for all commands in files/sudo/* |
Jesse Andrews | dfcd200 | 2011-09-13 13:17:22 -0700 | [diff] [blame] | 174 | |
Anthony Young | a09ae2f | 2011-09-15 23:11:29 -0700 | [diff] [blame] | 175 | # Rabbit |
| 176 | # --------- |
| 177 | # |
| 178 | if [[ "$ENABLED_SERVICES" =~ "rabbit" ]]; then |
| 179 | # Install and start rabbitmq-server |
Anthony Young | 093eeb0 | 2011-09-15 23:17:44 -0700 | [diff] [blame] | 180 | sudo apt-get install -y -q rabbitmq-server |
Anthony Young | a09ae2f | 2011-09-15 23:11:29 -0700 | [diff] [blame] | 181 | fi |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 182 | |
Jesse Andrews | 2485906 | 2011-09-15 21:28:23 -0700 | [diff] [blame] | 183 | # Mysql |
| 184 | # --------- |
| 185 | # |
| 186 | if [[ "$ENABLED_SERVICES" =~ "mysql" ]]; then |
Anthony Young | a09ae2f | 2011-09-15 23:11:29 -0700 | [diff] [blame] | 187 | # Install and start mysql-server |
Anthony Young | 093eeb0 | 2011-09-15 23:17:44 -0700 | [diff] [blame] | 188 | sudo apt-get -y -q install mysql-server |
Jesse Andrews | 2485906 | 2011-09-15 21:28:23 -0700 | [diff] [blame] | 189 | # Update the DB to give user ‘$MYSQL_USER’@’%’ full control of the all databases: |
| 190 | sudo mysql -uroot -p$MYSQL_PASS -e "GRANT ALL PRIVILEGES ON *.* TO '$MYSQL_USER'@'%' identified by '$MYSQL_PASS';" |
| 191 | |
| 192 | # 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: |
| 193 | sudo sed -i 's/127.0.0.1/0.0.0.0/g' /etc/mysql/my.cnf |
| 194 | sudo service mysql restart |
| 195 | fi |
| 196 | |
| 197 | |
Jesse Andrews | d74257d | 2011-09-13 01:24:50 -0700 | [diff] [blame] | 198 | # Dashboard |
| 199 | # --------- |
| 200 | # |
| 201 | # Setup the django application to serve via apache/wsgi |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 202 | |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 203 | if [[ "$ENABLED_SERVICES" =~ "dash" ]]; then |
Jesse Andrews | 2485906 | 2011-09-15 21:28:23 -0700 | [diff] [blame] | 204 | |
| 205 | # Dash currently imports quantum even if you aren't using it. Instead |
| 206 | # of installing quantum we can create a simple module that will pass the |
| 207 | # initial imports |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 208 | sudo mkdir -p $DASH_DIR/openstack-dashboard/quantum || true |
| 209 | sudo touch $DASH_DIR/openstack-dashboard/quantum/__init__.py |
| 210 | sudo touch $DASH_DIR/openstack-dashboard/quantum/client.py |
Jesse Andrews | 1c1d150 | 2011-09-12 19:29:56 -0700 | [diff] [blame] | 211 | |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 212 | cd $DASH_DIR/openstack-dashboard |
Jake Dahn | a3492ed | 2011-09-15 22:42:43 -0700 | [diff] [blame] | 213 | |
| 214 | # Includes settings for Nixon, to expose munin charts. |
Jesse Andrews | bf3868d | 2011-09-16 11:31:16 -0700 | [diff] [blame] | 215 | sudo cp $FILES/dash_settings.py local/local_settings.py |
Jake Dahn | 9337b33 | 2011-09-15 21:46:20 -0700 | [diff] [blame] | 216 | |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 217 | dashboard/manage.py syncdb |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 218 | |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 219 | # create an empty directory that apache uses as docroot |
| 220 | sudo mkdir -p $DASH_DIR/.blackhole |
Jesse Andrews | 1c1d150 | 2011-09-12 19:29:56 -0700 | [diff] [blame] | 221 | |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 222 | ## Configure apache's 000-default to run dashboard |
Jesse Andrews | bf3868d | 2011-09-16 11:31:16 -0700 | [diff] [blame] | 223 | sudo cp $FILES/000-default.template /etc/apache2/sites-enabled/000-default |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 224 | sudo sed -e "s,%DASH_DIR%,$DASH_DIR,g" -i /etc/apache2/sites-enabled/000-default |
Jesse Andrews | 18d350d | 2011-09-12 21:46:12 -0700 | [diff] [blame] | 225 | |
Jesse Andrews | 4d28218 | 2011-09-16 11:27:43 -0700 | [diff] [blame] | 226 | # ``python setup.py develop`` left some files owned by root in ``DASH_DIR`` |
| 227 | # and others are owned by the user you are using to run this script. |
| 228 | # We need to change the owner to apache for dashboard to run. |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 229 | sudo chown -R www-data:www-data $DASH_DIR |
| 230 | fi |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 231 | |
Anthony Young | 3859f73 | 2011-09-14 02:33:43 -0700 | [diff] [blame] | 232 | |
Dean Troyer | 0017c8f | 2011-09-13 15:37:50 -0500 | [diff] [blame] | 233 | # Munin |
| 234 | # ----- |
| 235 | |
Jesse Andrews | 2485906 | 2011-09-15 21:28:23 -0700 | [diff] [blame] | 236 | # Munin is accessable via apache and was configured in the dashboard section. |
Dean Troyer | 0017c8f | 2011-09-13 15:37:50 -0500 | [diff] [blame] | 237 | |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 238 | if [[ "$ENABLED_SERVICES" =~ "munin" ]]; then |
| 239 | # allow connections from other hosts |
| 240 | sudo sed -i -e '/Allow from localhost/s/localhost.*$/all/' /etc/munin/apache.conf |
| 241 | |
| 242 | cat >/tmp/nova <<EOF |
Dean Troyer | 0017c8f | 2011-09-13 15:37:50 -0500 | [diff] [blame] | 243 | [keystone_*] |
Dean Troyer | 925df4c | 2011-09-14 10:20:57 -0500 | [diff] [blame] | 244 | user `whoami` |
Dean Troyer | 0017c8f | 2011-09-13 15:37:50 -0500 | [diff] [blame] | 245 | |
| 246 | [nova_*] |
Dean Troyer | 925df4c | 2011-09-14 10:20:57 -0500 | [diff] [blame] | 247 | user `whoami` |
Dean Troyer | 0017c8f | 2011-09-13 15:37:50 -0500 | [diff] [blame] | 248 | EOF |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 249 | sudo mv /tmp/nova /etc/munin/plugin-conf.d/nova |
| 250 | # configure Munin for Nova plugins |
| 251 | PLUGINS="keystone_stats nova_floating_ips nova_instance_launched nova_instance_ nova_instance_timing nova_services" |
| 252 | for i in $PLUGINS; do |
| 253 | sudo cp -p $MUNIN_DIR/$i /usr/share/munin/plugins |
| 254 | sudo ln -sf /usr/share/munin/plugins/$i /etc/munin/plugins |
| 255 | done |
| 256 | sudo mv /etc/munin/plugins/nova_instance_ /etc/munin/plugins/nova_instance_launched |
| 257 | sudo restart munin-node |
| 258 | fi |
Dean Troyer | 0017c8f | 2011-09-13 15:37:50 -0500 | [diff] [blame] | 259 | |
Jesse Andrews | d74257d | 2011-09-13 01:24:50 -0700 | [diff] [blame] | 260 | # Glance |
| 261 | # ------ |
| 262 | |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 263 | if [[ "$ENABLED_SERVICES" =~ "g-reg" ]]; then |
| 264 | # Glance uses ``/var/lib/glance`` and ``/var/log/glance`` by default, so |
| 265 | # we need to insure that our user has permissions to use them. |
| 266 | sudo mkdir -p /var/log/glance |
| 267 | sudo chown -R `whoami` /var/log/glance |
| 268 | sudo mkdir -p /var/lib/glance |
| 269 | sudo chown -R `whoami` /var/lib/glance |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 270 | |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 271 | # Delete existing images/database as glance will recreate the db on startup |
| 272 | rm -rf /var/lib/glance/images/* |
| 273 | # (re)create glance database |
| 274 | mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'DROP DATABASE glance;' || true |
| 275 | mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'CREATE DATABASE glance;' |
| 276 | # Copy over our glance-registry.conf |
| 277 | GLANCE_CONF=$GLANCE_DIR/etc/glance-registry.conf |
Jesse Andrews | bf3868d | 2011-09-16 11:31:16 -0700 | [diff] [blame] | 278 | cp $FILES/glance-registry.conf $GLANCE_CONF |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 279 | sudo sed -e "s,%SQL_CONN%,$BASE_SQL_CONN/glance,g" -i $GLANCE_CONF |
| 280 | fi |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 281 | |
Jesse Andrews | d74257d | 2011-09-13 01:24:50 -0700 | [diff] [blame] | 282 | # Nova |
| 283 | # ---- |
| 284 | |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 285 | function add_nova_flag { |
| 286 | echo "$1" >> $NOVA_DIR/bin/nova.conf |
| 287 | } |
| 288 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 289 | # (re)create nova.conf |
| 290 | rm -f $NOVA_DIR/bin/nova.conf |
| 291 | add_nova_flag "--verbose" |
| 292 | add_nova_flag "--nodaemon" |
| 293 | add_nova_flag "--dhcpbridge_flagfile=$NOVA_DIR/bin/nova.conf" |
| 294 | add_nova_flag "--network_manager=nova.network.manager.$NET_MAN" |
| 295 | add_nova_flag "--my_ip=$HOST_IP" |
| 296 | add_nova_flag "--public_interface=$INTERFACE" |
| 297 | add_nova_flag "--vlan_interface=$INTERFACE" |
Anthony Young | a841644 | 2011-09-13 20:07:44 -0700 | [diff] [blame] | 298 | add_nova_flag "--sql_connection=$BASE_SQL_CONN/nova" |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 299 | add_nova_flag "--libvirt_type=$LIBVIRT_TYPE" |
| 300 | add_nova_flag "--osapi_extensions_path=$API_DIR/extensions" |
| 301 | add_nova_flag "--vncproxy_url=http://$HOST_IP:6080" |
Anthony Young | 1f81db6 | 2011-09-13 03:35:00 -0700 | [diff] [blame] | 302 | add_nova_flag "--vncproxy_wwwroot=$NOVNC_DIR/" |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 303 | add_nova_flag "--api_paste_config=$KEYSTONE_DIR/examples/paste/nova-api-paste.ini" |
| 304 | add_nova_flag "--image_service=nova.image.glance.GlanceImageService" |
Anthony Young | a841644 | 2011-09-13 20:07:44 -0700 | [diff] [blame] | 305 | add_nova_flag "--ec2_dmz_host=$EC2_DMZ_HOST" |
| 306 | add_nova_flag "--rabbit_host=$RABBIT_HOST" |
Anthony Young | 377aae6 | 2011-09-14 09:55:31 -0700 | [diff] [blame] | 307 | add_nova_flag "--glance_api_servers=$GLANCE_HOSTPORT" |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 308 | if [ -n "$FLAT_INTERFACE" ]; then |
| 309 | add_nova_flag "--flat_interface=$FLAT_INTERFACE" |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 310 | fi |
| 311 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 312 | # create a new named screen to store things in |
| 313 | screen -d -m -S nova -t nova |
| 314 | sleep 1 |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 315 | |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 316 | if [[ "$ENABLED_SERVICES" =~ "n-cpu" ]]; then |
Jesse Andrews | dfcd200 | 2011-09-13 13:17:22 -0700 | [diff] [blame] | 317 | |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 318 | # attempt to load modules: kvm (hardware virt) and nbd (network block |
| 319 | # device - used to manage qcow images) |
| 320 | sudo modprobe nbd || true |
| 321 | sudo modprobe kvm || true |
| 322 | # user needs to be member of libvirtd group for nova-compute to use libvirt |
| 323 | sudo usermod -a -G libvirtd `whoami` |
| 324 | # if kvm wasn't running before we need to restart libvirt to enable it |
| 325 | sudo /etc/init.d/libvirt-bin restart |
| 326 | |
| 327 | ## FIXME(ja): should LIBVIRT_TYPE be kvm if kvm module is loaded? |
| 328 | |
| 329 | # setup nova instance directory |
| 330 | mkdir -p $NOVA_DIR/instances |
| 331 | |
| 332 | # if there is a partition labeled nova-instances use it (ext filesystems |
| 333 | # can be labeled via e2label) |
| 334 | ## FIXME: if already mounted this blows up... |
| 335 | if [ -L /dev/disk/by-label/nova-instances ]; then |
| 336 | sudo mount -L nova-instances $NOVA_DIR/instances |
| 337 | sudo chown -R `whoami` $NOVA_DIR/instances |
| 338 | fi |
| 339 | |
| 340 | # Clean out the instances directory |
| 341 | rm -rf $NOVA_DIR/instances/* |
Jesse Andrews | dfcd200 | 2011-09-13 13:17:22 -0700 | [diff] [blame] | 342 | fi |
| 343 | |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 344 | if [[ "$ENABLED_SERVICES" =~ "n-net" ]]; then |
| 345 | # delete traces of nova networks from prior runs |
| 346 | killall dnsmasq || true |
| 347 | rm -rf $NOVA_DIR/networks |
| 348 | mkdir -p $NOVA_DIR/networks |
| 349 | fi |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 350 | |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 351 | if [[ "$ENABLED_SERVICES" =~ "mysql" ]]; then |
| 352 | # (re)create nova database |
| 353 | mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'DROP DATABASE nova;' || true |
| 354 | mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'CREATE DATABASE nova;' |
| 355 | $NOVA_DIR/bin/nova-manage db sync |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 356 | |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 357 | # create a small network |
| 358 | $NOVA_DIR/bin/nova-manage network create private $FIXED_RANGE 1 32 |
Jesse Andrews | e8d9cd8 | 2011-09-13 15:16:26 -0700 | [diff] [blame] | 359 | |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 360 | # create some floating ips |
| 361 | $NOVA_DIR/bin/nova-manage floating create $FLOATING_RANGE |
| 362 | fi |
Jesse Andrews | e8d9cd8 | 2011-09-13 15:16:26 -0700 | [diff] [blame] | 363 | |
| 364 | # Keystone |
| 365 | # -------- |
| 366 | |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 367 | if [[ "$ENABLED_SERVICES" =~ "key" ]]; then |
| 368 | # (re)create keystone database |
| 369 | mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'DROP DATABASE keystone;' || true |
| 370 | mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'CREATE DATABASE keystone;' |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 371 | |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 372 | # FIXME (anthony) keystone should use keystone.conf.example |
| 373 | KEYSTONE_CONF=$KEYSTONE_DIR/etc/keystone.conf |
Jesse Andrews | bf3868d | 2011-09-16 11:31:16 -0700 | [diff] [blame] | 374 | cp $FILES/keystone.conf $KEYSTONE_CONF |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 375 | sudo sed -e "s,%SQL_CONN%,$BASE_SQL_CONN/keystone,g" -i $KEYSTONE_CONF |
Anthony Young | 3a09312 | 2011-09-13 19:01:45 +0000 | [diff] [blame] | 376 | |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 377 | # initialize keystone with default users/endpoints |
Jesse Andrews | bf3868d | 2011-09-16 11:31:16 -0700 | [diff] [blame] | 378 | BIN_DIR=$KEYSTONE_DIR/bin bash $FILES/keystone_data.sh |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 379 | fi |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 380 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 381 | |
Jesse Andrews | d74257d | 2011-09-13 01:24:50 -0700 | [diff] [blame] | 382 | # Launch Services |
| 383 | # =============== |
Jesse Andrews | 30f68e9 | 2011-09-13 00:59:54 -0700 | [diff] [blame] | 384 | |
Jesse Andrews | 1c1d150 | 2011-09-12 19:29:56 -0700 | [diff] [blame] | 385 | # nova api crashes if we start it with a regular screen command, |
| 386 | # so send the start command by forcing text into the window. |
Jesse Andrews | dfcd200 | 2011-09-13 13:17:22 -0700 | [diff] [blame] | 387 | # Only run the services specified in ``ENABLED_SERVICES`` |
| 388 | |
| 389 | NL=`echo -ne '\015'` |
| 390 | |
Jesse Andrews | 1c1d150 | 2011-09-12 19:29:56 -0700 | [diff] [blame] | 391 | function screen_it { |
Anthony Young | 292e46d | 2011-09-13 11:28:56 -0700 | [diff] [blame] | 392 | if [[ "$ENABLED_SERVICES" =~ "$1" ]]; then |
| 393 | screen -S nova -X screen -t $1 |
| 394 | screen -S nova -p $1 -X stuff "$2$NL" |
| 395 | fi |
Jesse Andrews | 1c1d150 | 2011-09-12 19:29:56 -0700 | [diff] [blame] | 396 | } |
| 397 | |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 398 | screen_it g-api "cd $GLANCE_DIR; bin/glance-api --config-file=etc/glance-api.conf" |
| 399 | screen_it g-reg "cd $GLANCE_DIR; bin/glance-registry --config-file=etc/glance-registry.conf" |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 400 | screen_it key "$KEYSTONE_DIR/bin/keystone --config-file $KEYSTONE_CONF" |
Jesse Andrews | 55508d6 | 2011-09-12 19:00:28 -0700 | [diff] [blame] | 401 | screen_it n-api "$NOVA_DIR/bin/nova-api" |
| 402 | screen_it n-cpu "$NOVA_DIR/bin/nova-compute" |
| 403 | screen_it n-net "$NOVA_DIR/bin/nova-network" |
| 404 | screen_it n-sch "$NOVA_DIR/bin/nova-scheduler" |
Anthony Young | 1f81db6 | 2011-09-13 03:35:00 -0700 | [diff] [blame] | 405 | # nova-vncproxy binds a privileged port, and so needs sudo |
| 406 | screen_it n-vnc "sudo $NOVA_DIR/bin/nova-vncproxy" |
Anthony Young | 8fbba91 | 2011-09-13 09:20:58 -0700 | [diff] [blame] | 407 | screen_it dash "sudo /etc/init.d/apache2 restart; sudo tail -f /var/log/apache2/error.log" |
Jesse Andrews | 75a3765 | 2011-09-12 17:09:08 -0700 | [diff] [blame] | 408 | |
Jesse Andrews | d74257d | 2011-09-13 01:24:50 -0700 | [diff] [blame] | 409 | # Install Images |
| 410 | # ============== |
Jesse Andrews | e49b8bd | 2011-09-12 18:08:04 -0700 | [diff] [blame] | 411 | |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 412 | if [[ "$ENABLED_SERVICES" =~ "g-reg" ]]; then |
| 413 | # Downloads a tty image (ami/aki/ari style), then extracts it. Upon extraction |
| 414 | # we upload to glance with the glance cli tool. |
| 415 | mkdir -p $DEST/images |
| 416 | cd $DEST/images |
| 417 | if [ ! -f $DEST/tty.tgz ]; then |
| 418 | wget -c http://images.ansolabs.com/tty.tgz -O $DEST/tty.tgz |
| 419 | fi |
Jesse Andrews | e49b8bd | 2011-09-12 18:08:04 -0700 | [diff] [blame] | 420 | |
Anthony Young | 70dc5e0 | 2011-09-15 16:52:43 -0700 | [diff] [blame] | 421 | # extract ami-tty/image, aki-tty/image & ari-tty/image |
| 422 | tar -zxf $DEST/tty.tgz |
| 423 | |
| 424 | # add images to glance |
| 425 | # FIXME: kernel/ramdisk is hardcoded - use return result from add |
| 426 | glance add name="tty-kernel" is_public=true container_format=aki disk_format=aki < aki-tty/image |
| 427 | glance add name="tty-ramdisk" is_public=true container_format=ari disk_format=ari < ari-tty/image |
| 428 | glance add name="tty" is_public=true container_format=ami disk_format=ami kernel_id=1 ramdisk_id=2 < ami-tty/image |
Jesse Andrews | e49b8bd | 2011-09-12 18:08:04 -0700 | [diff] [blame] | 429 | fi |
Jesse Andrews | 2485906 | 2011-09-15 21:28:23 -0700 | [diff] [blame] | 430 | |
| 431 | # Using the cloud |
| 432 | # =============== |
| 433 | |
| 434 | # If you installed the dashboard on this server, then you should be able |
| 435 | # to access the site using your browser. |
| 436 | if [[ "$ENABLED_SERVICES" =~ "dash" ]]; then |
| 437 | echo "dashboard is now available at http://$HOST_IP/" |
| 438 | fi |
| 439 | |
| 440 | # If keystone is present, you can point nova cli to this server |
| 441 | if [[ "$ENABLED_SERVICES" =~ "key" ]]; then |
| 442 | echo "keystone is serving at http://$HOST_IP:5000/v2.0/" |
| 443 | echo "examples on using novaclient command line is in exercise.sh" |
| 444 | fi |