Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Abort if localrc is not set |
| 4 | if [ ! -e ../../localrc ]; then |
| 5 | echo "You must have a localrc with ALL necessary passwords defined before proceeding." |
| 6 | echo "See the xen README for required passwords." |
| 7 | exit 1 |
| 8 | fi |
| 9 | |
Anthony Young | af6ed6b | 2011-11-02 07:50:27 -0500 | [diff] [blame] | 10 | # This directory |
| 11 | TOP_DIR=$(cd $(dirname "$0") && pwd) |
| 12 | |
Anthony Young | 1188904 | 2012-01-12 17:11:56 -0800 | [diff] [blame^] | 13 | # Source params - override xenrc params in your localrc to suite your taste |
| 14 | source xenrc |
Anthony Young | af6ed6b | 2011-11-02 07:50:27 -0500 | [diff] [blame] | 15 | |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 16 | # Echo commands |
| 17 | set -o xtrace |
| 18 | |
Anthony Young | 1188904 | 2012-01-12 17:11:56 -0800 | [diff] [blame^] | 19 | # Check for xva file |
| 20 | if [ ! -e $XVA ]; then |
| 21 | echo "Missing xva file. Please run build_xva.sh (ideally on a non dom0 host since the build can require lots of space)." |
| 22 | echo "Place the resulting xva file in $XVA" |
| 23 | exit 1 |
| 24 | fi |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 25 | |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 26 | # Make sure we have git |
| 27 | if ! which git; then |
| 28 | GITDIR=/tmp/git-1.7.7 |
| 29 | cd /tmp |
| 30 | rm -rf $GITDIR* |
| 31 | wget http://git-core.googlecode.com/files/git-1.7.7.tar.gz |
| 32 | tar xfv git-1.7.7.tar.gz |
| 33 | cd $GITDIR |
| 34 | ./configure |
| 35 | make install |
| 36 | cd $TOP_DIR |
| 37 | fi |
| 38 | |
| 39 | # Helper to create networks |
| 40 | function create_network() { |
| 41 | if ! xe network-list | grep bridge | grep -q $1; then |
| 42 | echo "Creating bridge $1" |
| 43 | xe network-create name-label=$1 |
| 44 | fi |
| 45 | } |
| 46 | |
| 47 | # Create host, vm, mgmt, pub networks |
| 48 | create_network xapi0 |
| 49 | create_network $VM_BR |
| 50 | create_network $MGT_BR |
| 51 | create_network $PUB_BR |
| 52 | |
| 53 | # Get the uuid for our physical (public) interface |
| 54 | PIF=`xe pif-list --minimal device=eth0` |
| 55 | |
| 56 | # Create networks/bridges for vm and management |
| 57 | VM_NET=`xe network-list --minimal bridge=$VM_BR` |
| 58 | MGT_NET=`xe network-list --minimal bridge=$MGT_BR` |
| 59 | |
| 60 | # Helper to create vlans |
| 61 | function create_vlan() { |
| 62 | pif=$1 |
| 63 | vlan=$2 |
| 64 | net=$3 |
| 65 | if ! xe vlan-list | grep tag | grep -q $vlan; then |
| 66 | xe vlan-create pif-uuid=$pif vlan=$vlan network-uuid=$net |
| 67 | fi |
| 68 | } |
| 69 | |
| 70 | # Create vlans for vm and management |
| 71 | create_vlan $PIF $VM_VLAN $VM_NET |
| 72 | create_vlan $PIF $MGT_VLAN $MGT_NET |
| 73 | |
Anthony Young | 1188904 | 2012-01-12 17:11:56 -0800 | [diff] [blame^] | 74 | # dom0 ip |
| 75 | HOST_IP=${HOST_IP:-`ifconfig xenbr0 | grep "inet addr" | cut -d ":" -f2 | sed "s/ .*//"`} |
| 76 | |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 77 | # Setup host-only nat rules |
| 78 | HOST_NET=169.254.0.0/16 |
| 79 | if ! iptables -L -v -t nat | grep -q $HOST_NET; then |
| 80 | iptables -t nat -A POSTROUTING -s $HOST_NET -j SNAT --to-source $HOST_IP |
| 81 | iptables -I FORWARD 1 -s $HOST_NET -j ACCEPT |
| 82 | /etc/init.d/iptables save |
| 83 | fi |
| 84 | |
| 85 | # Set up ip forwarding |
| 86 | if ! grep -q "FORWARD_IPV4=YES" /etc/sysconfig/network; then |
| 87 | # FIXME: This doesn't work on reboot! |
| 88 | echo "FORWARD_IPV4=YES" >> /etc/sysconfig/network |
| 89 | fi |
| 90 | |
| 91 | # Also, enable ip forwarding in rc.local, since the above trick isn't working |
| 92 | if ! grep -q "echo 1 >/proc/sys/net/ipv4/ip_forward" /etc/rc.local; then |
| 93 | echo "echo 1 >/proc/sys/net/ipv4/ip_forward" >> /etc/rc.local |
| 94 | fi |
| 95 | |
| 96 | # Enable ip forwarding at runtime as well |
| 97 | echo 1 > /proc/sys/net/ipv4/ip_forward |
| 98 | |
Anthony Young | 1188904 | 2012-01-12 17:11:56 -0800 | [diff] [blame^] | 99 | # Set local storage il8n |
| 100 | SR_UUID=`xe sr-list --minimal name-label="Local storage"` |
| 101 | xe sr-param-set uuid=$SR_UUID other-config:i18n-key=local-storage |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 102 | |
| 103 | # Clean nova if desired |
| 104 | if [ "$CLEAN" = "1" ]; then |
| 105 | rm -rf $TOP_DIR/nova |
| 106 | fi |
| 107 | |
| 108 | # Checkout nova |
| 109 | if [ ! -d $TOP_DIR/nova ]; then |
Anthony Young | 419770f | 2012-01-11 17:35:40 -0800 | [diff] [blame] | 110 | git clone $NOVA_REPO |
| 111 | cd $TOP_DIR/nova |
| 112 | git checkout $NOVA_BRANCH |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 113 | fi |
| 114 | |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 115 | # Install plugins |
| 116 | cp -pr $TOP_DIR/nova/plugins/xenserver/xenapi/etc/xapi.d /etc/ |
| 117 | chmod a+x /etc/xapi.d/plugins/* |
| 118 | yum --enablerepo=base install -y parted |
| 119 | mkdir -p /boot/guest |
| 120 | |
Anthony Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 121 | # Shutdown previous runs |
| 122 | DO_SHUTDOWN=${DO_SHUTDOWN:-1} |
| 123 | if [ "$DO_SHUTDOWN" = "1" ]; then |
Anthony Young | 40b5737 | 2011-11-05 00:30:07 -0500 | [diff] [blame] | 124 | # Shutdown all domU's that created previously |
Anthony Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 125 | xe vm-list --minimal name-label="$LABEL" | xargs ./scripts/uninstall-os-vpx.sh |
| 126 | |
| 127 | # Destroy any instances that were launched |
| 128 | for uuid in `xe vm-list | grep -1 instance | grep uuid | sed "s/.*\: //g"`; do |
| 129 | echo "Shutting down nova instance $uuid" |
| 130 | xe vm-unpause uuid=$uuid || true |
| 131 | xe vm-shutdown uuid=$uuid |
| 132 | xe vm-destroy uuid=$uuid |
| 133 | done |
Anthony Young | fa4ecc6 | 2011-11-11 10:23:22 -0800 | [diff] [blame] | 134 | |
| 135 | # Destroy orphaned vdis |
| 136 | for uuid in `xe vdi-list | grep -1 Glance | grep uuid | sed "s/.*\: //g"`; do |
| 137 | xe vdi-destroy uuid=$uuid |
| 138 | done |
Anthony Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 139 | fi |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 140 | |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 141 | # Start guest |
| 142 | $TOP_DIR/scripts/install-os-vpx.sh -f $XVA -v $VM_BR -m $MGT_BR -p $PUB_BR |
Anthony Young | 3eb8f59 | 2011-10-26 23:11:52 -0700 | [diff] [blame] | 143 | |
Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 144 | # If we have copied our ssh credentials, use ssh to monitor while the installation runs |
| 145 | WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1} |
| 146 | if [ "$WAIT_TILL_LAUNCH" = "1" ] && [ -e ~/.ssh/id_rsa.pub ] && [ "$COPYENV" = "1" ]; then |
| 147 | # Done creating the container, let's tail the log |
| 148 | echo |
| 149 | echo "=============================================================" |
| 150 | echo " -- YAY! --" |
| 151 | echo "=============================================================" |
| 152 | echo |
| 153 | echo "We're done launching the vm, about to start tailing the" |
| 154 | echo "stack.sh log. It will take a second or two to start." |
| 155 | echo |
| 156 | echo "Just CTRL-C at any time to stop tailing." |
| 157 | |
| 158 | set +o xtrace |
| 159 | |
| 160 | while ! ssh -q stack@$PUB_IP "[ -e run.sh.log ]"; do |
| 161 | sleep 1 |
| 162 | done |
| 163 | |
| 164 | ssh stack@$PUB_IP 'tail -f run.sh.log' & |
| 165 | |
| 166 | TAIL_PID=$! |
| 167 | |
| 168 | function kill_tail() { |
| 169 | kill $TAIL_PID |
| 170 | exit 1 |
| 171 | } |
| 172 | |
| 173 | # Let Ctrl-c kill tail and exit |
| 174 | trap kill_tail SIGINT |
| 175 | |
| 176 | echo "Waiting stack.sh to finish..." |
Anthony Young | f0dca55 | 2011-11-01 14:23:14 -0700 | [diff] [blame] | 177 | while ! ssh -q stack@$PUB_IP "grep -q 'stack.sh completed in' run.sh.log"; do |
Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 178 | sleep 1 |
| 179 | done |
| 180 | |
| 181 | kill $TAIL_PID |
| 182 | |
Anthony Young | f0dca55 | 2011-11-01 14:23:14 -0700 | [diff] [blame] | 183 | if ssh -q stack@$PUB_IP "grep -q 'stack.sh failed' run.sh.log"; then |
Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 184 | exit 1 |
| 185 | fi |
| 186 | echo "" |
| 187 | echo "Finished - Zip-a-dee Doo-dah!" |
| 188 | echo "You can then visit the OpenStack Dashboard" |
| 189 | echo "at http://$PUB_IP, and contact other services at the usual ports." |
| 190 | else |
| 191 | echo "################################################################################" |
| 192 | echo "" |
| 193 | echo "All Finished!" |
| 194 | echo "Now, you can monitor the progress of the stack.sh installation by " |
| 195 | echo "tailing /opt/stack/run.sh.log from within your domU." |
| 196 | echo "" |
| 197 | echo "ssh into your domU now: 'ssh stack@$PUB_IP' using your password" |
| 198 | echo "and then do: 'tail -f /opt/stack/run.sh.log'" |
| 199 | echo "" |
| 200 | echo "When the script completes, you can then visit the OpenStack Dashboard" |
| 201 | echo "at http://$PUB_IP, and contact other services at the usual ports." |
| 202 | |
| 203 | fi |