2012-01-12 17:11:56 -08:00
|
|
|
#!/bin/bash
|
|
|
|
|
2012-04-27 18:28:28 +01:00
|
|
|
# This script is run by install_os_domU.sh
|
|
|
|
#
|
|
|
|
# It modifies the ubuntu image created by install_os_domU.sh
|
|
|
|
# and previously moodified by prepare_guest_template.sh
|
|
|
|
#
|
|
|
|
# This script is responsible for:
|
|
|
|
# - pushing in the DevStack code
|
|
|
|
# - creating run.sh, to run the code on boot
|
|
|
|
# It does this by mounting the disk image of the VM.
|
|
|
|
#
|
|
|
|
# The resultant image is then templated and started
|
|
|
|
# by install_os_domU.sh
|
|
|
|
|
|
|
|
# Exit on errors
|
|
|
|
set -o errexit
|
|
|
|
# Echo commands
|
|
|
|
set -o xtrace
|
2012-01-12 17:11:56 -08:00
|
|
|
|
|
|
|
# This directory
|
|
|
|
TOP_DIR=$(cd $(dirname "$0") && pwd)
|
|
|
|
|
2012-04-27 18:28:28 +01:00
|
|
|
# Include onexit commands
|
|
|
|
. $TOP_DIR/scripts/on_exit.sh
|
|
|
|
|
2014-02-02 09:16:20 +00:00
|
|
|
# xapi functions
|
|
|
|
. $TOP_DIR/functions
|
|
|
|
|
2012-01-12 17:11:56 -08:00
|
|
|
# Source params - override xenrc params in your localrc to suite your taste
|
|
|
|
source xenrc
|
|
|
|
|
2012-04-27 18:28:28 +01:00
|
|
|
#
|
|
|
|
# Parameters
|
|
|
|
#
|
2012-04-02 15:46:53 -07:00
|
|
|
GUEST_NAME="$1"
|
2012-01-12 17:11:56 -08:00
|
|
|
|
2014-02-21 15:35:08 +11:00
|
|
|
function _print_interface_config {
|
2013-06-17 13:54:43 +01:00
|
|
|
local device_nr
|
|
|
|
local ip_address
|
|
|
|
local netmask
|
|
|
|
|
|
|
|
device_nr="$1"
|
|
|
|
ip_address="$2"
|
|
|
|
netmask="$3"
|
|
|
|
|
|
|
|
local device
|
|
|
|
|
|
|
|
device="eth${device_nr}"
|
|
|
|
|
|
|
|
echo "auto $device"
|
|
|
|
if [ $ip_address == "dhcp" ]; then
|
|
|
|
echo "iface $device inet dhcp"
|
|
|
|
else
|
|
|
|
echo "iface $device inet static"
|
|
|
|
echo " address $ip_address"
|
|
|
|
echo " netmask $netmask"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Turn off tx checksumming for better performance
|
|
|
|
echo " post-up ethtool -K $device tx off"
|
|
|
|
}
|
|
|
|
|
2014-02-21 15:35:08 +11:00
|
|
|
function print_interfaces_config {
|
2013-06-17 13:54:43 +01:00
|
|
|
echo "auto lo"
|
|
|
|
echo "iface lo inet loopback"
|
|
|
|
|
|
|
|
_print_interface_config $PUB_DEV_NR $PUB_IP $PUB_NETMASK
|
|
|
|
_print_interface_config $VM_DEV_NR $VM_IP $VM_NETMASK
|
|
|
|
_print_interface_config $MGT_DEV_NR $MGT_IP $MGT_NETMASK
|
|
|
|
}
|
|
|
|
|
2012-04-27 18:28:28 +01:00
|
|
|
#
|
|
|
|
# Mount the VDI
|
|
|
|
#
|
2012-04-02 15:46:53 -07:00
|
|
|
STAGING_DIR=$($TOP_DIR/scripts/manage-vdi open $GUEST_NAME 0 1 | grep -o "/tmp/tmp.[[:alnum:]]*")
|
|
|
|
add_on_exit "$TOP_DIR/scripts/manage-vdi close $GUEST_NAME 0 1"
|
2012-01-12 17:11:56 -08:00
|
|
|
|
|
|
|
# Make sure we have a stage
|
|
|
|
if [ ! -d $STAGING_DIR/etc ]; then
|
|
|
|
echo "Stage is not properly set up!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2013-02-01 15:16:51 +00:00
|
|
|
# Only support DHCP for now - don't support how different versions of Ubuntu handle resolv.conf
|
|
|
|
if [ "$MGT_IP" != "dhcp" ] && [ "$PUB_IP" != "dhcp" ]; then
|
|
|
|
echo "Configuration without DHCP not supported"
|
2012-06-26 11:16:38 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
2012-01-12 17:11:56 -08:00
|
|
|
|
|
|
|
# Copy over devstack
|
|
|
|
rm -f /tmp/devstack.tar
|
2012-04-02 15:46:53 -07:00
|
|
|
cd $TOP_DIR/../../
|
|
|
|
tar --exclude='stage' --exclude='xen/xvas' --exclude='xen/nova' -cvf /tmp/devstack.tar .
|
|
|
|
mkdir -p $STAGING_DIR/opt/stack/devstack
|
|
|
|
tar xf /tmp/devstack.tar -C $STAGING_DIR/opt/stack/devstack
|
2012-01-12 17:11:56 -08:00
|
|
|
cd $TOP_DIR
|
|
|
|
|
2013-09-24 17:35:00 +01:00
|
|
|
# Create an upstart job (task) for devstack, which can interact with the console
|
|
|
|
cat >$STAGING_DIR/etc/init/devstack.conf << EOF
|
|
|
|
start on stopped rc RUNLEVEL=[2345]
|
|
|
|
|
|
|
|
console output
|
|
|
|
task
|
|
|
|
|
|
|
|
pre-start script
|
2015-01-26 14:13:02 +00:00
|
|
|
rm -f /opt/stack/runsh.succeeded
|
2013-09-24 17:35:00 +01:00
|
|
|
end script
|
|
|
|
|
|
|
|
script
|
|
|
|
initctl stop hvc0 || true
|
|
|
|
|
|
|
|
# Read any leftover characters from standard input
|
|
|
|
while read -n 1 -s -t 0.1 -r ignored; do
|
|
|
|
true
|
|
|
|
done
|
|
|
|
|
|
|
|
clear
|
|
|
|
|
|
|
|
chown -R $STACK_USER /opt/stack
|
|
|
|
|
2015-01-15 12:48:26 +00:00
|
|
|
su -c "/opt/stack/run.sh" $STACK_USER
|
2013-09-26 13:57:02 +01:00
|
|
|
|
|
|
|
# Update /etc/issue
|
|
|
|
{
|
|
|
|
echo "OpenStack VM - Installed by DevStack"
|
|
|
|
IPADDR=\$(ip -4 address show eth0 | sed -n 's/.*inet \\([0-9\.]\\+\\).*/\1/p')
|
|
|
|
echo " Management IP: \$IPADDR"
|
|
|
|
echo -n " Devstack run: "
|
2015-01-26 14:13:02 +00:00
|
|
|
if [ -e /opt/stack/runsh.succeeded ]; then
|
2013-09-26 13:57:02 +01:00
|
|
|
echo "SUCCEEDED"
|
|
|
|
else
|
|
|
|
echo "FAILED"
|
|
|
|
fi
|
|
|
|
echo ""
|
|
|
|
} > /etc/issue
|
2013-09-24 17:35:00 +01:00
|
|
|
initctl start hvc0 > /dev/null 2>&1
|
|
|
|
end script
|
2012-01-12 17:11:56 -08:00
|
|
|
EOF
|
|
|
|
|
|
|
|
# Configure the hostname
|
|
|
|
echo $GUEST_NAME > $STAGING_DIR/etc/hostname
|
|
|
|
|
|
|
|
# Hostname must resolve for rabbit
|
2012-04-27 18:28:28 +01:00
|
|
|
HOSTS_FILE_IP=$PUB_IP
|
|
|
|
if [ $MGT_IP != "dhcp" ]; then
|
|
|
|
HOSTS_FILE_IP=$MGT_IP
|
|
|
|
fi
|
2012-01-12 17:11:56 -08:00
|
|
|
cat <<EOF >$STAGING_DIR/etc/hosts
|
2012-04-27 18:28:28 +01:00
|
|
|
$HOSTS_FILE_IP $GUEST_NAME
|
2012-01-12 17:11:56 -08:00
|
|
|
127.0.0.1 localhost localhost.localdomain
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# Configure the network
|
2013-06-17 13:54:43 +01:00
|
|
|
print_interfaces_config > $STAGING_DIR/etc/network/interfaces
|
2012-04-27 18:28:28 +01:00
|
|
|
|
2012-01-12 17:11:56 -08:00
|
|
|
# Gracefully cp only if source file/dir exists
|
|
|
|
function cp_it {
|
|
|
|
if [ -e $1 ] || [ -d $1 ]; then
|
|
|
|
cp -pRL $1 $2
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Copy over your ssh keys and env if desired
|
|
|
|
COPYENV=${COPYENV:-1}
|
|
|
|
if [ "$COPYENV" = "1" ]; then
|
|
|
|
cp_it ~/.ssh $STAGING_DIR/opt/stack/.ssh
|
|
|
|
cp_it ~/.ssh/id_rsa.pub $STAGING_DIR/opt/stack/.ssh/authorized_keys
|
|
|
|
cp_it ~/.gitconfig $STAGING_DIR/opt/stack/.gitconfig
|
|
|
|
cp_it ~/.vimrc $STAGING_DIR/opt/stack/.vimrc
|
|
|
|
cp_it ~/.bashrc $STAGING_DIR/opt/stack/.bashrc
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Configure run.sh
|
|
|
|
cat <<EOF >$STAGING_DIR/opt/stack/run.sh
|
|
|
|
#!/bin/bash
|
2013-09-24 17:35:00 +01:00
|
|
|
set -eux
|
2015-01-15 12:48:26 +00:00
|
|
|
(
|
|
|
|
flock -n 9 || exit 1
|
|
|
|
|
|
|
|
[ -e /opt/stack/runsh.succeeded ] && rm /opt/stack/runsh.succeeded
|
|
|
|
echo \$\$ >> /opt/stack/run_sh.pid
|
|
|
|
|
|
|
|
cd /opt/stack/devstack
|
|
|
|
./unstack.sh || true
|
|
|
|
./stack.sh
|
|
|
|
|
|
|
|
# Got to the end - success
|
|
|
|
touch /opt/stack/runsh.succeeded
|
|
|
|
rm /opt/stack/run_sh.pid
|
|
|
|
) 9> /opt/stack/.runsh_lock
|
2012-01-12 17:11:56 -08:00
|
|
|
EOF
|
|
|
|
chmod 755 $STAGING_DIR/opt/stack/run.sh
|