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 |
| 46 | cd $2 |
| 47 | git fetch origin |
| 48 | git checkout origin/master |
| 49 | else |
| 50 | git clone $1 $2 |
| 51 | fi |
| 52 | } |
| 53 | |
| 54 | # You should only have to run this once |
| 55 | if [ "$CMD" == "install" ]; then |
| 56 | #apt-get install -y python-software-properties |
| 57 | # FIXME: do we still need this? |
| 58 | # DELETEME: add-apt-repository ppa:nova-core/trunk |
| 59 | # DELETEME: apt-get update -qq |
| 60 | |
| 61 | # fixme: do we need: python-boto |
| 62 | apt-get install -y -q `cat $DIR/apts/*` |
| 63 | |
| 64 | # install python requirements |
| 65 | pip install -r $DIR/pips/dash |
| 66 | |
| 67 | # TODO: kill openstackx |
| 68 | clone_or_up https://github.com/cloudbuilders/nova.git $NOVA_DIR |
| 69 | clone_or_up https://github.com/cloudbuilders/openstackx.git $API_DIR |
| 70 | clone_or_up https://github.com/cloudbuilders/noVNC.git $NOVNC_DIR |
| 71 | clone_or_up https://github.com/cloudbuilders/openstack-dashboard.git $DASH_DIR |
| 72 | clone_or_up https://github.com/cloudbuilders/python-novaclient.git $NOVACLIENT_DIR |
| 73 | clone_or_up https://github.com/cloudbuilders/keystone.git $KEYSTONE_DIR |
| 74 | clone_or_up https://github.com/cloudbuilders/glance.git $GLANCE_DIR |
| 75 | |
| 76 | mkdir -p $NOVA_DIR/instances |
| 77 | mkdir -p $NOVA_DIR/networks |
| 78 | |
| 79 | # these components are imported into each other... |
| 80 | cd $NOVACLIENT_DIR; python setup.py develop |
| 81 | cd $KEYSTONE_DIR; python setup.py develop |
| 82 | cd $GLANCE_DIR; python setup.py develop |
| 83 | cd $API_DIR; python setup.py develop |
| 84 | cd $DASH_DIR/django-openstack; python setup.py develop |
| 85 | cd $DASH_DIR/openstack-dashboard; python setup.py develop |
| 86 | # dash currently imports quantum even if you aren't using it |
| 87 | cd $DASH_DIR/openstack-dashboard |
| 88 | mkdir quantum |
| 89 | touch quantum/__init__.py |
| 90 | touch quantum/client.py |
| 91 | |
| 92 | |
| 93 | # attempt to load kvm and nbd modules |
| 94 | modprobe kvm || true |
| 95 | modprobe nbd || true |
| 96 | /etc/init.d/libvirt-bin restart |
| 97 | |
| 98 | # install dashboard |
| 99 | cd $DASH_DIR/openstack-dashboard |
| 100 | cp local/local_settings.py.example local/local_settings.py |
| 101 | # python tools/install_venv.py |
| 102 | dashboard/manage.py syncdb |
| 103 | # setup apache |
| 104 | mkdir $DASH_DIR/.blackhole |
| 105 | |
| 106 | # cat > $DASH_DIR/openstack-dashboard/dashboard/wsgi/local.wsgi <<EOF |
| 107 | #import sys |
| 108 | #sys.path.append('/$DASH_DIR/openstack-dashboard/.dashboard-venv/lib/python2.6/site-packages/') |
| 109 | #sys.path.append('/$DASH_DIR/openstack-dashboard/.dashboard-venv/lib/python2.7/site-packages/') |
| 110 | #sys.path.append('/$DASH_DIR/openstack-dashboard/') |
| 111 | #sys.path.append('/$DASH_DIR/django-openstack/') |
| 112 | #sys.path.append('/$API_DIR') |
| 113 | #sys.path.append('/$DASH_DIR/openstack-dashboard/.dashboard-venv/src/openstack') |
| 114 | # |
| 115 | #EOF |
| 116 | cat $DASH_DIR/openstack-dashboard/dashboard/wsgi/django.wsgi >> $DASH_DIR/openstack-dashboard/dashboard/wsgi/local.wsgi |
| 117 | |
| 118 | cat > /etc/apache2/sites-enabled/000-default <<EOF |
| 119 | <VirtualHost *:80> |
| 120 | WSGIScriptAlias / $DASH_DIR/openstack-dashboard/dashboard/wsgi/local.wsgi |
| 121 | WSGIDaemonProcess dashboard user=www-data group=www-data processes=3 threads=10 |
| 122 | WSGIProcessGroup dashboard |
| 123 | |
| 124 | DocumentRoot $DASH_DIR/.blackhole/ |
| 125 | Alias /media $DASH_DIR/openstack-dashboard/media |
| 126 | |
| 127 | <Directory /> |
| 128 | Options FollowSymLinks |
| 129 | AllowOverride None |
| 130 | </Directory> |
| 131 | |
| 132 | <Directory $DASH_DIR/> |
| 133 | Options Indexes FollowSymLinks MultiViews |
| 134 | AllowOverride None |
| 135 | Order allow,deny |
| 136 | allow from all |
| 137 | </Directory> |
| 138 | |
| 139 | ErrorLog /var/log/apache2/error.log |
| 140 | LogLevel warn |
| 141 | CustomLog /var/log/apache2/access.log combined |
| 142 | </VirtualHost> |
| 143 | EOF |
| 144 | |
| 145 | chown -R www-data:www-data $DASH_DIR |
| 146 | |
| 147 | mkdir -p /var/log/glance |
| 148 | |
| 149 | mkdir -p $DEST/images |
| 150 | wget -c http://images.ansolabs.com/tty.tgz |
| 151 | tar -C $DEST/images -zxf tty.tgz |
| 152 | exit |
| 153 | fi |
| 154 | |
| 155 | # Configure screen |
| 156 | cat >~/.screenrc <<EOF |
| 157 | hardstatus on |
| 158 | hardstatus alwayslastline |
| 159 | hardstatus string "%{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..G}%H %{..Y}%d/%m %c" |
| 160 | |
| 161 | defscrollback 1024 |
| 162 | |
| 163 | vbell off |
| 164 | startup_message off |
| 165 | EOF |
| 166 | |
| 167 | NL=`echo -ne '\015'` |
| 168 | |
| 169 | function screen_it { |
| 170 | screen -S nova -X screen -t $1 |
| 171 | screen -S nova -p $1 -X stuff "$2$NL" |
| 172 | } |
| 173 | |
| 174 | function add_nova_flag { |
| 175 | echo "$1" >> $NOVA_DIR/bin/nova.conf |
| 176 | } |
| 177 | |
| 178 | if [ "$CMD" == "run" ] || [ "$CMD" == "run_detached" ]; then |
| 179 | |
| 180 | rm -f $NOVA_DIR/bin/nova.conf |
| 181 | |
| 182 | add_nova_flag "--verbose" |
| 183 | add_nova_flag "--nodaemon" |
| 184 | add_nova_flag "--dhcpbridge_flagfile=$NOVA_DIR/bin/nova.conf" |
| 185 | add_nova_flag "--network_manager=nova.network.manager.$NET_MAN" |
| 186 | add_nova_flag "--my_ip=$HOST_IP" |
| 187 | add_nova_flag "--public_interface=$INTERFACE" |
| 188 | add_nova_flag "--vlan_interface=$INTERFACE" |
| 189 | add_nova_flag "--sql_connection=$SQL_CONN" |
| 190 | add_nova_flag "--libvirt_type=$LIBVIRT_TYPE" |
| 191 | add_nova_flag "--osapi_extensions_path=$API_DIR/extensions" |
| 192 | add_nova_flag "--vncproxy_url=http://$HOST_IP:6080" |
| 193 | add_nova_flag "--vncproxy_wwwroot=$NOVNC_DIR/noVNC/noVNC" |
| 194 | |
| 195 | if [ -n "$FLAT_INTERFACE" ]; then |
| 196 | add_nova_flag "--flat_interface=$FLAT_INTERFACE" |
| 197 | fi |
| 198 | |
| 199 | add_nova_flag "--api_paste_config=$KEYSTONE_DIR/examples/paste/nova-api-paste.ini" |
| 200 | add_nova_flag "--image_service=nova.image.glance.GlanceImageService" |
| 201 | |
| 202 | killall dnsmasq || true |
| 203 | screen -d -m -S nova -t nova |
| 204 | sleep 1 |
| 205 | rm -f $NOVA_DIR/nova.sqlite |
| 206 | rm -rf $NOVA_DIR/instances |
| 207 | mkdir -p $NOVA_DIR/instances |
| 208 | rm -rf $NOVA_DIR/networks |
| 209 | mkdir -p $NOVA_DIR/networks |
| 210 | |
| 211 | # create the database |
| 212 | $NOVA_DIR/bin/nova-manage db sync |
| 213 | rm -f keystone.db |
| 214 | # add default data |
| 215 | curl -OL https://raw.github.com/cloudbuilders/deploy.sh/master/initial_data.sh |
| 216 | BIN_DIR=$KEYSTONE_DIR/bin bash initial_data.sh |
| 217 | |
| 218 | # create a small network |
| 219 | $NOVA_DIR/bin/nova-manage network create private $FIXED_RANGE 1 32 |
| 220 | |
| 221 | # create some floating ips |
| 222 | $NOVA_DIR/bin/nova-manage floating create $FLOATING_RANGE |
| 223 | |
| 224 | # nova api crashes if we start it with a regular screen command, |
| 225 | # so send the start command by forcing text into the window. |
| 226 | |
| 227 | rm -rf /var/lib/glance/images/* |
| 228 | rm -f $GLANCE_DIR/glance.sqlite |
| 229 | |
| 230 | screen_it n-api "$NOVA_DIR/bin/nova-api" |
| 231 | screen_it g-api "cd $GLANCE_DIR; bin/glance-api --config-file=etc/glance-api.conf" |
| 232 | screen_it g-reg "cd $GLANCE_DIR; bin/glance-registry --config-file=etc/glance-registry.conf" |
| 233 | screen_it cpu "$NOVA_DIR/bin/nova-compute" |
| 234 | screen_it net "$NOVA_DIR/bin/nova-network" |
| 235 | screen_it sched "$NOVA_DIR/bin/nova-scheduler" |
| 236 | screen_it key "$KEYSTONE_DIR/bin/keystone --config-file $KEYSTONE_DIR/etc/keystone.conf" |
| 237 | screen_it dash "/etc/init.d/apache2 restart; tail -f /var/log/apache2/error.log" |
| 238 | screen_it vnc "$NOVA_DIR/bin/nova-vncproxy" |
| 239 | screen_it test "" |
| 240 | |
| 241 | # FIXME: switch to just importing images |
| 242 | # remove previously converted images |
| 243 | 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] |
| 244 | $NOVA_DIR/bin/nova-manage image convert $DIR/images |
| 245 | |
| 246 | if [ "$CMD" != "run_detached" ]; then |
| 247 | screen -S nova -x |
| 248 | fi |
| 249 | fi |
| 250 | |
| 251 | if [ "$CMD" == "run" ] || [ "$CMD" == "terminate" ]; then |
| 252 | virsh list | grep i- | awk '{print $1}' | xargs -n1 virsh destroy |
| 253 | $NOVA_DIR/tools/clean-vlans |
| 254 | echo "FIXME: clean networks?" |
| 255 | fi |
| 256 | |
| 257 | if [ "$CMD" == "run" ] || [ "$CMD" == "clean" ]; then |
| 258 | screen -S nova -X quit |
| 259 | rm -f *.pid* |
| 260 | fi |
| 261 | |