Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # **stack.sh** is rackspace cloudbuilder's opinionated openstack installation. |
| 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 |
| 13 | CMD=$1 |
| 14 | |
| 15 | # Set hte destination directories for openstack projects |
| 16 | NOVA_DIR=$DEST/nova |
| 17 | DASH_DIR=$DEST/dash |
| 18 | GLANCE_DIR=$DEST/glance |
| 19 | KEYSTONE_DIR=$DEST/keystone |
| 20 | NOVACLIENT_DIR=$DEST/python-novaclient |
| 21 | API_DIR=$DEST/openstackx |
| 22 | NOVNC_DIR=$DEST/noVNC |
| 23 | |
| 24 | # Use the first IP unless an explicit is set by a HOST_IP environment variable |
| 25 | if [ ! -n "$HOST_IP" ]; then |
| 26 | HOST_IP=`LC_ALL=C ifconfig | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'` |
| 27 | fi |
| 28 | |
| 29 | # NOVA CONFIGURATION |
| 30 | INTERFACE=${INTERFACE:-eth0} |
| 31 | FLOATING_RANGE=${FLOATING_RANGE:-10.6.0.0/27} |
| 32 | FIXED_RANGE=${FIXED_RANGE:-10.0.0.0/24} |
| 33 | LIBVIRT_TYPE=${LIBVIRT_TYPE:-qemu} |
| 34 | NET_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 | |
| 40 | SQL_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 |
| 44 | function clone_or_up { |
| 45 | if [ -d $2 ]; then |
Jesse Andrews | 3107deb | 2011-09-11 16:46:44 -0700 | [diff] [blame] | 46 | echo commenting out update for now for speed |
| 47 | # cd $2 |
| 48 | # git fetch origin |
| 49 | # git checkout origin/master |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 50 | else |
| 51 | git clone $1 $2 |
| 52 | fi |
| 53 | } |
| 54 | |
| 55 | # You should only have to run this once |
| 56 | if [ "$CMD" == "install" ]; then |
Jesse Andrews | 2e8ade1 | 2011-09-11 13:28:06 -0700 | [diff] [blame] | 57 | # install apt requirements |
Jesse Andrews | f2ef760 | 2011-09-11 16:23:21 -0700 | [diff] [blame] | 58 | apt-get install -y -q `cat $DIR/apts/* | cut -d\# -f1` |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 59 | |
| 60 | # install python requirements |
Jesse Andrews | f2ef760 | 2011-09-11 16:23:21 -0700 | [diff] [blame] | 61 | pip install `cat $DIR/pips/*` |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 62 | |
| 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 Andrews | 2e8ade1 | 2011-09-11 13:28:06 -0700 | [diff] [blame] | 82 | # HACK: dash currently imports quantum even if you aren't using it |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 83 | cd $DASH_DIR/openstack-dashboard |
| 84 | mkdir quantum |
| 85 | touch quantum/__init__.py |
| 86 | touch quantum/client.py |
| 87 | |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 88 | # 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 Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 96 | dashboard/manage.py syncdb |
| 97 | # setup apache |
| 98 | mkdir $DASH_DIR/.blackhole |
| 99 | |
Jesse Andrews | 8b564a8 | 2011-09-11 17:53:34 -0700 | [diff] [blame] | 100 | # 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 Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 102 | |
| 103 | chown -R www-data:www-data $DASH_DIR |
| 104 | |
| 105 | mkdir -p /var/log/glance |
| 106 | |
Jesse Andrews | 3107deb | 2011-09-11 16:46:44 -0700 | [diff] [blame] | 107 | if [ ! -f $DEST/tty.tgz ]; then |
| 108 | wget -c http://images.ansolabs.com/tty.tgz -O $DEST/tty.tgz |
| 109 | fi |
| 110 | |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 111 | mkdir -p $DEST/images |
Jesse Andrews | 3107deb | 2011-09-11 16:46:44 -0700 | [diff] [blame] | 112 | tar -C $DEST/images -zxf $DEST/tty.tgz |
Jesse Andrews | 8b564a8 | 2011-09-11 17:53:34 -0700 | [diff] [blame] | 113 | |
| 114 | # add useful screenrc |
| 115 | cp $DIR/files/screenrc ~/.screenrc |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 116 | exit |
| 117 | fi |
| 118 | |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 119 | NL=`echo -ne '\015'` |
| 120 | |
| 121 | function screen_it { |
| 122 | screen -S nova -X screen -t $1 |
| 123 | screen -S nova -p $1 -X stuff "$2$NL" |
| 124 | } |
| 125 | |
| 126 | function add_nova_flag { |
| 127 | echo "$1" >> $NOVA_DIR/bin/nova.conf |
| 128 | } |
| 129 | |
| 130 | if [ "$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 Andrews | 1b17570 | 2011-09-11 17:11:11 -0700 | [diff] [blame] | 158 | rm -rf $NOVA_DIR/instances/* |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 159 | mkdir -p $NOVA_DIR/instances |
Jesse Andrews | 1b17570 | 2011-09-11 17:11:11 -0700 | [diff] [blame] | 160 | # 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 Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 165 | 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 Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 181 | rm -rf /var/lib/glance/images/* |
| 182 | rm -f $GLANCE_DIR/glance.sqlite |
| 183 | |
Jesse Andrews | 3107deb | 2011-09-11 16:46:44 -0700 | [diff] [blame] | 184 | # 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 Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 186 | 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 Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 193 | screen_it vnc "$NOVA_DIR/bin/nova-vncproxy" |
Jesse Andrews | 2e8ade1 | 2011-09-11 13:28:06 -0700 | [diff] [blame] | 194 | screen_it dash "/etc/init.d/apache2 restart; tail -f /var/log/apache2/error.log" |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 195 | |
| 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 |
| 204 | fi |
| 205 | |
| 206 | if [ "$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?" |
| 210 | fi |
| 211 | |
| 212 | if [ "$CMD" == "run" ] || [ "$CMD" == "clean" ]; then |
| 213 | screen -S nova -X quit |
| 214 | rm -f *.pid* |
| 215 | fi |
| 216 | |