forked from openstack/devstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_ramdisk.sh
More file actions
executable file
·167 lines (132 loc) · 4.79 KB
/
Copy pathbuild_ramdisk.sh
File metadata and controls
executable file
·167 lines (132 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/bash
# build_ramdisk.sh - Build RAM disk images
if [ ! "$#" -eq "1" ]; then
echo "$0 builds a gziped natty openstack install"
echo "usage: $0 dest"
exit 1
fi
PROGDIR=`dirname $0`
CHROOTCACHE=${CHROOTCACHE:-/var/cache/devstack}
# Source params
source ./stackrc
# Store cwd
CWD=`pwd`
DEST=${DEST:-/opt/stack}
# Param string to pass to stack.sh. Like "EC2_DMZ_HOST=192.168.1.1 MYSQL_USER=nova"
STACKSH_PARAMS=${STACKSH_PARAMS:-}
# Option to use the version of devstack on which we are currently working
USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1}
# clean install of natty
if [ ! -d $CHROOTCACHE/natty-base ]; then
$PROGDIR/make_image.sh -C natty $CHROOTCACHE/natty-base
# copy kernel modules...
# NOTE(ja): is there a better way to do this?
cp -pr /lib/modules/`uname -r` $CHROOTCACHE/natty-base/lib/modules
# a simple password - pass
echo root:pass | chroot $CHROOTCACHE/natty-base chpasswd
fi
# prime natty with as many apt/pips as we can
if [ ! -d $CHROOTCACHE/natty-dev ]; then
rsync -azH $CHROOTCACHE/natty-base/ $CHROOTCACHE/natty-dev/
chroot $CHROOTCACHE/natty-dev apt-get install -y `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
chroot $CHROOTCACHE/natty-dev pip install `cat files/pips/*`
# Create a stack user that is a member of the libvirtd group so that stack
# is able to interact with libvirt.
chroot $CHROOTCACHE/natty-dev groupadd libvirtd
chroot $CHROOTCACHE/natty-dev useradd stack -s /bin/bash -d $DEST -G libvirtd
mkdir -p $CHROOTCACHE/natty-dev/$DEST
chroot $CHROOTCACHE/natty-dev chown stack $DEST
# a simple password - pass
echo stack:pass | chroot $CHROOTCACHE/natty-dev chpasswd
# and has sudo ability (in the future this should be limited to only what
# stack requires)
echo "stack ALL=(ALL) NOPASSWD: ALL" >> $CHROOTCACHE/natty-dev/etc/sudoers
fi
# clone git repositories onto the system
# ======================================
if [ ! -d $CHROOTCACHE/natty-stack ]; then
rsync -azH $CHROOTCACHE/natty-dev/ $CHROOTCACHE/natty-stack/
fi
# git clone only if directory doesn't exist already. Since ``DEST`` might not
# be owned by the installation user, we create the directory and change the
# ownership to the proper user.
function git_clone {
# clone new copy or fetch latest changes
CHECKOUT=$CHROOTCACHE/natty-stack$2
if [ ! -d $CHECKOUT ]; then
mkdir -p $CHECKOUT
git clone $1 $CHECKOUT
else
pushd $CHECKOUT
git fetch
popd
fi
# FIXME(ja): checkout specified version (should works for branches and tags)
pushd $CHECKOUT
# checkout the proper branch/tag
git checkout $3
# force our local version to be the same as the remote version
git reset --hard origin/$3
popd
# give ownership to the stack user
chroot $CHROOTCACHE/natty-stack/ chown -R stack $2
}
git_clone $NOVA_REPO $DEST/nova $NOVA_BRANCH
git_clone $GLANCE_REPO $DEST/glance $GLANCE_BRANCH
git_clone $KEYSTONE_REPO $DEST/keystone $KEYSTONE_BRANCH
git_clone $NOVNC_REPO $DEST/novnc $NOVNC_BRANCH
git_clone $DASH_REPO $DEST/dash $DASH_BRANCH
git_clone $NOVACLIENT_REPO $DEST/python-novaclient $NOVACLIENT_BRANCH
git_clone $OPENSTACKX_REPO $DEST/openstackx $OPENSTACKX_BRANCH
# Use this version of devstack?
if [ "$USE_CURRENT_DEVSTACK" = "1" ]; then
rm -rf $CHROOTCACHE/natty-stack/$DEST/devstack
cp -pr $CWD $CHROOTCACHE/natty-stack/$DEST/devstack
fi
# Configure host network for DHCP
mkdir -p $CHROOTCACHE/natty-stack/etc/network
cat > $CHROOTCACHE/natty-stack/etc/network/interfaces <<EOF
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
EOF
# Set hostname
echo "ramstack" >$CHROOTCACHE/natty-stack/etc/hostname
echo "127.0.0.1 localhost ramstack" >$CHROOTCACHE/natty-stack/etc/hosts
# Configure the runner
RUN_SH=$CHROOTCACHE/natty-stack/$DEST/run.sh
cat > $RUN_SH <<EOF
#!/usr/bin/env bash
# Get IP range
set \`ip addr show dev eth0 | grep inet\`
PREFIX=\`echo \$2 | cut -d. -f1,2,3\`
export FLOATING_RANGE="\$PREFIX.224/27"
# Kill any existing screens
killall screen
# Run stack.sh
cd $DEST/devstack && \$STACKSH_PARAMS ./stack.sh > $DEST/run.sh.log
echo >> $DEST/run.sh.log
echo >> $DEST/run.sh.log
echo "All done! Time to start clicking." >> $DEST/run.sh.log
EOF
# Make the run.sh executable
chmod 755 $RUN_SH
chroot $CHROOTCACHE/natty-stack chown stack $DEST/run.sh
# build a new image
BASE=$CHROOTCACHE/build.$$
IMG=$BASE.img
MNT=$BASE/
# (quickly) create a 2GB blank filesystem
dd bs=1 count=1 seek=$((2*1024*1024*1024)) if=/dev/zero of=$IMG
# force it to be initialized as ext2
mkfs.ext2 -F $IMG
# mount blank image loopback and load it
mkdir -p $MNT
mount -o loop $IMG $MNT
rsync -azH $CHROOTCACHE/natty-stack/ $MNT
# umount and cleanup
umount $MNT
rmdir $MNT
# gzip into final location
gzip -1 $IMG -c > $1