blob: c359c558060bcfad3d5f89439e8789095e677960 [file] [log] [blame]
Anthony Young11889042012-01-12 17:11:56 -08001#!/bin/bash
2
John Garbuttdaadf742012-04-27 18:28:28 +01003# This script is run by install_os_domU.sh
4#
5# It modifies the ubuntu image created by install_os_domU.sh
6# and previously moodified by prepare_guest_template.sh
7#
8# This script is responsible for:
9# - pushing in the DevStack code
10# - creating run.sh, to run the code on boot
11# It does this by mounting the disk image of the VM.
12#
13# The resultant image is then templated and started
14# by install_os_domU.sh
Renuka Apte0af143b2012-04-02 15:46:53 -070015
John Garbuttdaadf742012-04-27 18:28:28 +010016# Exit on errors
17set -o errexit
18# Echo commands
19set -o xtrace
Anthony Young11889042012-01-12 17:11:56 -080020
21# This directory
22TOP_DIR=$(cd $(dirname "$0") && pwd)
23
John Garbuttdaadf742012-04-27 18:28:28 +010024# Include onexit commands
25. $TOP_DIR/scripts/on_exit.sh
26
Anthony Young11889042012-01-12 17:11:56 -080027# Source params - override xenrc params in your localrc to suite your taste
28source xenrc
29
John Garbuttdaadf742012-04-27 18:28:28 +010030#
31# Parameters
32#
Renuka Apte0af143b2012-04-02 15:46:53 -070033GUEST_NAME="$1"
34
John Garbuttdaadf742012-04-27 18:28:28 +010035#
36# Mount the VDI
37#
Renuka Apte0af143b2012-04-02 15:46:53 -070038STAGING_DIR=$($TOP_DIR/scripts/manage-vdi open $GUEST_NAME 0 1 | grep -o "/tmp/tmp.[[:alnum:]]*")
39add_on_exit "$TOP_DIR/scripts/manage-vdi close $GUEST_NAME 0 1"
Anthony Young11889042012-01-12 17:11:56 -080040
41# Make sure we have a stage
42if [ ! -d $STAGING_DIR/etc ]; then
43 echo "Stage is not properly set up!"
44 exit 1
45fi
46
Anthony Young11889042012-01-12 17:11:56 -080047# Configure dns (use same dns as dom0)
John Garbuttd8f1a872012-06-26 11:16:38 +010048# but only when not precise
49if [ "$UBUNTU_INST_RELEASE" != "precise" ]; then
50 cp /etc/resolv.conf $STAGING_DIR/etc/resolv.conf
51elif [ "$MGT_IP" != "dhcp" ] && [ "$PUB_IP" != "dhcp" ]; then
52 echo "Configuration without DHCP not supported on Precise"
53 exit 1
54fi
Anthony Young11889042012-01-12 17:11:56 -080055
56# Copy over devstack
57rm -f /tmp/devstack.tar
Renuka Apte0af143b2012-04-02 15:46:53 -070058cd $TOP_DIR/../../
59tar --exclude='stage' --exclude='xen/xvas' --exclude='xen/nova' -cvf /tmp/devstack.tar .
60mkdir -p $STAGING_DIR/opt/stack/devstack
61tar xf /tmp/devstack.tar -C $STAGING_DIR/opt/stack/devstack
Anthony Young11889042012-01-12 17:11:56 -080062cd $TOP_DIR
63
Anthony Young11889042012-01-12 17:11:56 -080064# Run devstack on launch
65cat <<EOF >$STAGING_DIR/etc/rc.local
rootb1153412012-01-19 13:28:21 -080066# network restart required for getting the right gateway
67/etc/init.d/networking restart
John Garbuttdaadf742012-04-27 18:28:28 +010068chown -R stack /opt/stack
John Garbutt72cffd52012-12-04 16:14:04 +000069su -c "/opt/stack/run.sh > /opt/stack/run.sh.log" stack
Anthony Young11889042012-01-12 17:11:56 -080070exit 0
71EOF
72
Anthony Young11889042012-01-12 17:11:56 -080073# Configure the hostname
74echo $GUEST_NAME > $STAGING_DIR/etc/hostname
75
76# Hostname must resolve for rabbit
John Garbuttdaadf742012-04-27 18:28:28 +010077HOSTS_FILE_IP=$PUB_IP
78if [ $MGT_IP != "dhcp" ]; then
79 HOSTS_FILE_IP=$MGT_IP
80fi
Anthony Young11889042012-01-12 17:11:56 -080081cat <<EOF >$STAGING_DIR/etc/hosts
John Garbuttdaadf742012-04-27 18:28:28 +010082$HOSTS_FILE_IP $GUEST_NAME
Anthony Young11889042012-01-12 17:11:56 -080083127.0.0.1 localhost localhost.localdomain
84EOF
85
86# Configure the network
87INTERFACES=$STAGING_DIR/etc/network/interfaces
John Garbuttd8f1a872012-06-26 11:16:38 +010088TEMPLATES_DIR=$TOP_DIR/templates
Anthony Young11889042012-01-12 17:11:56 -080089cp $TEMPLATES_DIR/interfaces.in $INTERFACES
rootb1153412012-01-19 13:28:21 -080090if [ $VM_IP == "dhcp" ]; then
91 echo 'eth1 on dhcp'
92 sed -e "s,iface eth1 inet static,iface eth1 inet dhcp,g" -i $INTERFACES
93 sed -e '/@ETH1_/d' -i $INTERFACES
94else
95 sed -e "s,@ETH1_IP@,$VM_IP,g" -i $INTERFACES
96 sed -e "s,@ETH1_NETMASK@,$VM_NETMASK,g" -i $INTERFACES
97fi
98
99if [ $MGT_IP == "dhcp" ]; then
100 echo 'eth2 on dhcp'
101 sed -e "s,iface eth2 inet static,iface eth2 inet dhcp,g" -i $INTERFACES
102 sed -e '/@ETH2_/d' -i $INTERFACES
103else
104 sed -e "s,@ETH2_IP@,$MGT_IP,g" -i $INTERFACES
105 sed -e "s,@ETH2_NETMASK@,$MGT_NETMASK,g" -i $INTERFACES
106fi
107
108if [ $PUB_IP == "dhcp" ]; then
109 echo 'eth3 on dhcp'
110 sed -e "s,iface eth3 inet static,iface eth3 inet dhcp,g" -i $INTERFACES
111 sed -e '/@ETH3_/d' -i $INTERFACES
112else
113 sed -e "s,@ETH3_IP@,$PUB_IP,g" -i $INTERFACES
114 sed -e "s,@ETH3_NETMASK@,$PUB_NETMASK,g" -i $INTERFACES
115fi
116
John Garbutt030fb232012-04-27 18:28:28 +0100117if [ "$ENABLE_GI" == "true" ]; then
118 cat <<EOF >>$INTERFACES
119auto eth0
120iface eth0 inet dhcp
121EOF
122fi
123
Anthony Young11889042012-01-12 17:11:56 -0800124# Gracefully cp only if source file/dir exists
125function cp_it {
126 if [ -e $1 ] || [ -d $1 ]; then
127 cp -pRL $1 $2
128 fi
129}
130
131# Copy over your ssh keys and env if desired
132COPYENV=${COPYENV:-1}
133if [ "$COPYENV" = "1" ]; then
134 cp_it ~/.ssh $STAGING_DIR/opt/stack/.ssh
135 cp_it ~/.ssh/id_rsa.pub $STAGING_DIR/opt/stack/.ssh/authorized_keys
136 cp_it ~/.gitconfig $STAGING_DIR/opt/stack/.gitconfig
137 cp_it ~/.vimrc $STAGING_DIR/opt/stack/.vimrc
138 cp_it ~/.bashrc $STAGING_DIR/opt/stack/.bashrc
139fi
140
141# Configure run.sh
142cat <<EOF >$STAGING_DIR/opt/stack/run.sh
143#!/bin/bash
144cd /opt/stack/devstack
145killall screen
John Garbuttdaadf742012-04-27 18:28:28 +0100146VIRT_DRIVER=xenserver FORCE=yes MULTI_HOST=$MULTI_HOST HOST_IP_IFACE=$HOST_IP_IFACE $STACKSH_PARAMS ./stack.sh
Anthony Young11889042012-01-12 17:11:56 -0800147EOF
148chmod 755 $STAGING_DIR/opt/stack/run.sh