blob: c220f0294c4d04571ba3c39dccb8be65b4783727 [file] [log] [blame]
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -07001#!/bin/bash
Dean Troyer56119512011-10-11 19:39:34 -05002# build_ramdisk.sh - Build RAM disk images
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -07003
4if [ ! "$#" -eq "1" ]; then
5 echo "$0 builds a gziped natty openstack install"
6 echo "usage: $0 dest"
7 exit 1
8fi
9
Dean Troyera6466e02011-10-25 17:53:24 -050010IMG_FILE=$1
11
Dean Troyer407ee7e2011-09-29 16:38:59 -050012PROGDIR=`dirname $0`
Dean Troyerd4a3bac2011-10-03 21:16:27 -050013CHROOTCACHE=${CHROOTCACHE:-/var/cache/devstack}
Dean Troyer407ee7e2011-09-29 16:38:59 -050014
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070015# Source params
16source ./stackrc
17
Dean Troyer03412c82011-10-03 09:56:41 -050018# Store cwd
19CWD=`pwd`
20
Dean Troyer11e5e6f2011-10-03 09:40:32 -050021DEST=${DEST:-/opt/stack}
22
Dean Troyer8f851e72011-10-11 20:22:23 -050023# Param string to pass to stack.sh. Like "EC2_DMZ_HOST=192.168.1.1 MYSQL_USER=nova"
24STACKSH_PARAMS=${STACKSH_PARAMS:-}
25
Dean Troyera3379e02011-10-03 11:14:13 -050026# Option to use the version of devstack on which we are currently working
27USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1}
28
Dean Troyera6466e02011-10-25 17:53:24 -050029# Set up nbd
30modprobe nbd max_part=63
31NBD=${NBD:-/dev/nbd9}
32NBD_DEV=`basename $NBD`
33
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070034# clean install of natty
Dean Troyera6466e02011-10-25 17:53:24 -050035if [ ! -r $CHROOTCACHE/natty-base.img ]; then
36 $PROGDIR/get_uec_image.sh natty $CHROOTCACHE/natty-base.img
37# # copy kernel modules...
38# # NOTE(ja): is there a better way to do this?
39# cp -pr /lib/modules/`uname -r` $CHROOTCACHE/natty-base/lib/modules
40# # a simple password - pass
41# echo root:pass | chroot $CHROOTCACHE/natty-base chpasswd
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070042fi
43
44# prime natty with as many apt/pips as we can
Dean Troyera6466e02011-10-25 17:53:24 -050045if [ ! -r $CHROOTCACHE/natty-dev.img ]; then
46 cp -p $CHROOTCACHE/natty-base.img $CHROOTCACHE/natty-dev.img
47
48 qemu-nbd -c $NBD $CHROOTCACHE/natty-dev.img
49 if ! timeout 60 sh -c "while ! [ -e /sys/block/$NBD_DEV/pid ]; do sleep 1; done"; then
50 echo "Couldn't connect $NBD"
51 exit 1
52 fi
53 MNTDIR=`mktemp -d --tmpdir mntXXXXXXXX`
54 mount -t ext4 ${NBD}p1 $MNTDIR
55 cp -p /etc/resolv.conf $MNTDIR/etc/resolv.conf
56
57 chroot $MNTDIR apt-get install -y `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
58 chroot $MNTDIR pip install `cat files/pips/*`
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070059
Vishvananda Ishaya9b353672011-10-20 10:07:10 -070060 # Create a stack user that is a member of the libvirtd group so that stack
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070061 # is able to interact with libvirt.
Dean Troyera6466e02011-10-25 17:53:24 -050062 chroot $MNTDIR groupadd libvirtd
63 chroot $MNTDIR useradd stack -s /bin/bash -d $DEST -G libvirtd
64 mkdir -p $MNTDIR/$DEST
65 chroot $MNTDIR chown stack $DEST
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070066
67 # a simple password - pass
Dean Troyera6466e02011-10-25 17:53:24 -050068 echo stack:pass | chroot $MNTDIR chpasswd
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070069
Vishvananda Ishaya9b353672011-10-20 10:07:10 -070070 # and has sudo ability (in the future this should be limited to only what
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070071 # stack requires)
Dean Troyera6466e02011-10-25 17:53:24 -050072 echo "stack ALL=(ALL) NOPASSWD: ALL" >> $MNTDIR/etc/sudoers
73
74 umount $MNTDIR
75 rmdir $MNTDIR
76 qemu-nbd -d $NBD
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070077fi
78
79# clone git repositories onto the system
80# ======================================
81
Dean Troyera6466e02011-10-25 17:53:24 -050082if [ ! -r $IMG_FILE ]; then
Dean Troyer61be9242011-10-25 22:35:23 -050083 qemu-nbd -c $NBD $CHROOTCACHE/natty-dev.img
84 if ! timeout 60 sh -c "while ! [ -e /sys/block/$NBD_DEV/pid ]; do sleep 1; done"; then
85 echo "Couldn't connect $NBD"
86 exit 1
87 fi
88
89 # Pre-create the image file
90 # FIXME(dt): This should really get the partition size to
91 # pre-create the image file
92 dd if=/dev/zero of=$IMG_FILE bs=1 count=1 seek=$((2*1024*1024*1024))
93 # Create filesystem image for RAM disk
94 dd if=${NBD}p1 of=$IMG_FILE bs=1M
95
96 qemu-nbd -d $NBD
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070097fi
98
Dean Troyera6466e02011-10-25 17:53:24 -050099MNTDIR=`mktemp -d --tmpdir mntXXXXXXXX`
Dean Troyer61be9242011-10-25 22:35:23 -0500100mount -t ext4 -o loop $IMG_FILE $MNTDIR
Dean Troyera6466e02011-10-25 17:53:24 -0500101cp -p /etc/resolv.conf $MNTDIR/etc/resolv.conf
102
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700103# git clone only if directory doesn't exist already. Since ``DEST`` might not
104# be owned by the installation user, we create the directory and change the
105# ownership to the proper user.
106function git_clone {
107
108 # clone new copy or fetch latest changes
Dean Troyera6466e02011-10-25 17:53:24 -0500109 CHECKOUT=${MNTDIR}$2
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700110 if [ ! -d $CHECKOUT ]; then
111 mkdir -p $CHECKOUT
112 git clone $1 $CHECKOUT
113 else
114 pushd $CHECKOUT
115 git fetch
116 popd
117 fi
118
119 # FIXME(ja): checkout specified version (should works for branches and tags)
120
121 pushd $CHECKOUT
122 # checkout the proper branch/tag
123 git checkout $3
124 # force our local version to be the same as the remote version
125 git reset --hard origin/$3
126 popd
127
128 # give ownership to the stack user
Dean Troyera6466e02011-10-25 17:53:24 -0500129 chroot $MNTDIR chown -R stack $2
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700130}
131
Dean Troyer11e5e6f2011-10-03 09:40:32 -0500132git_clone $NOVA_REPO $DEST/nova $NOVA_BRANCH
133git_clone $GLANCE_REPO $DEST/glance $GLANCE_BRANCH
134git_clone $KEYSTONE_REPO $DEST/keystone $KEYSTONE_BRANCH
135git_clone $NOVNC_REPO $DEST/novnc $NOVNC_BRANCH
136git_clone $DASH_REPO $DEST/dash $DASH_BRANCH
137git_clone $NOVACLIENT_REPO $DEST/python-novaclient $NOVACLIENT_BRANCH
138git_clone $OPENSTACKX_REPO $DEST/openstackx $OPENSTACKX_BRANCH
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700139
Dean Troyerb5da5192011-10-17 13:32:06 -0500140# Use this version of devstack
Dean Troyera6466e02011-10-25 17:53:24 -0500141rm -rf $MNTDIR/$DEST/devstack
142cp -pr $CWD $MNTDIR/$DEST/devstack
143chroot $MNTDIR chown -R stack $DEST/devstack
Dean Troyer03412c82011-10-03 09:56:41 -0500144
Dean Troyercf9db8d2011-10-03 13:42:16 -0500145# Configure host network for DHCP
Dean Troyera6466e02011-10-25 17:53:24 -0500146mkdir -p $MNTDIR/etc/network
147cat > $MNTDIR/etc/network/interfaces <<EOF
Dean Troyercf9db8d2011-10-03 13:42:16 -0500148auto lo
149iface lo inet loopback
150
151auto eth0
152iface eth0 inet dhcp
153EOF
154
Dean Troyer288f3bd2011-10-13 15:50:44 -0500155# Set hostname
Dean Troyera6466e02011-10-25 17:53:24 -0500156echo "ramstack" >$MNTDIR/etc/hostname
157echo "127.0.0.1 localhost ramstack" >$MNTDIR/etc/hosts
Dean Troyer288f3bd2011-10-13 15:50:44 -0500158
Dean Troyer8f851e72011-10-11 20:22:23 -0500159# Configure the runner
Dean Troyera6466e02011-10-25 17:53:24 -0500160RUN_SH=$MNTDIR/$DEST/run.sh
Dean Troyer8f851e72011-10-11 20:22:23 -0500161cat > $RUN_SH <<EOF
162#!/usr/bin/env bash
163
Dean Troyer7c076ee2011-10-13 13:20:13 -0500164# Get IP range
165set \`ip addr show dev eth0 | grep inet\`
166PREFIX=\`echo \$2 | cut -d. -f1,2,3\`
167export FLOATING_RANGE="\$PREFIX.224/27"
168
Dean Troyer8f851e72011-10-11 20:22:23 -0500169# Kill any existing screens
170killall screen
171
172# Run stack.sh
173cd $DEST/devstack && \$STACKSH_PARAMS ./stack.sh > $DEST/run.sh.log
174echo >> $DEST/run.sh.log
175echo >> $DEST/run.sh.log
176echo "All done! Time to start clicking." >> $DEST/run.sh.log
177EOF
178
179# Make the run.sh executable
180chmod 755 $RUN_SH
Dean Troyera6466e02011-10-25 17:53:24 -0500181chroot $MNTDIR chown stack $DEST/run.sh
Dean Troyer8f851e72011-10-11 20:22:23 -0500182
Dean Troyera6466e02011-10-25 17:53:24 -0500183umount $MNTDIR
184rmdir $MNTDIR
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700185
Dean Troyera6466e02011-10-25 17:53:24 -0500186gzip -1 $IMG_FILE