1 | 1 |
deleted file mode 100755 |
... | ... |
@@ -1,258 +0,0 @@ |
1 |
-#!/usr/bin/env bash |
|
2 |
- |
|
3 |
-# Sanity check |
|
4 |
-if [ "$EUID" -ne "0" ]; then |
|
5 |
- echo "This script must be run with root privileges." |
|
6 |
- exit 1 |
|
7 |
-fi |
|
8 |
- |
|
9 |
-# Warn users who aren't on natty |
|
10 |
-if ! grep -q natty /etc/lsb-release; then |
|
11 |
- echo "WARNING: this script has only been tested on natty" |
|
12 |
-fi |
|
13 |
- |
|
14 |
-# Abort if localrc is not set |
|
15 |
-if [ ! -e ./localrc ]; then |
|
16 |
- echo "You must have a localrc with ALL necessary passwords defined before proceeding." |
|
17 |
- echo "See stack.sh for required passwords." |
|
18 |
- exit 1 |
|
19 |
-fi |
|
20 |
- |
|
21 |
-# Source params |
|
22 |
-source ./stackrc |
|
23 |
- |
|
24 |
-# Store cwd |
|
25 |
-CWD=`pwd` |
|
26 |
- |
|
27 |
-# Configurable params |
|
28 |
-BRIDGE=${BRIDGE:-br0} |
|
29 |
-CONTAINER=${CONTAINER:-STACK} |
|
30 |
-CONTAINER_IP=${CONTAINER_IP:-192.168.1.50} |
|
31 |
-CONTAINER_CIDR=${CONTAINER_CIDR:-$CONTAINER_IP/24} |
|
32 |
-CONTAINER_NETMASK=${CONTAINER_NETMASK:-255.255.255.0} |
|
33 |
-CONTAINER_GATEWAY=${CONTAINER_GATEWAY:-192.168.1.1} |
|
34 |
-NAMESERVER=${NAMESERVER:-$CONTAINER_GATEWAY} |
|
35 |
-COPYENV=${COPYENV:-1} |
|
36 |
-DEST=${DEST:-/opt/stack} |
|
37 |
- |
|
38 |
-# Param string to pass to stack.sh. Like "EC2_DMZ_HOST=192.168.1.1 MYSQL_USER=nova" |
|
39 |
-STACKSH_PARAMS=${STACKSH_PARAMS:-} |
|
40 |
- |
|
41 |
-# Option to use the version of devstack on which we are currently working |
|
42 |
-USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1} |
|
43 |
- |
|
44 |
- |
|
45 |
-# Install deps |
|
46 |
-apt-get install -y lxc debootstrap |
|
47 |
- |
|
48 |
-# Install cgroup-bin from source, since the packaging is buggy and possibly incompatible with our setup |
|
49 |
-if ! which cgdelete | grep -q cgdelete; then |
|
50 |
- apt-get install -y g++ bison flex libpam0g-dev make |
|
51 |
- wget http://sourceforge.net/projects/libcg/files/libcgroup/v0.37.1/libcgroup-0.37.1.tar.bz2/download -O /tmp/libcgroup-0.37.1.tar.bz2 |
|
52 |
- cd /tmp && bunzip2 libcgroup-0.37.1.tar.bz2 && tar xfv libcgroup-0.37.1.tar |
|
53 |
- cd libcgroup-0.37.1 |
|
54 |
- ./configure |
|
55 |
- make install |
|
56 |
- ldconfig |
|
57 |
-fi |
|
58 |
- |
|
59 |
-# Create lxc configuration |
|
60 |
-LXC_CONF=/tmp/$CONTAINER.conf |
|
61 |
-cat > $LXC_CONF <<EOF |
|
62 |
-lxc.network.type = veth |
|
63 |
-lxc.network.link = $BRIDGE |
|
64 |
-lxc.network.flags = up |
|
65 |
-lxc.network.ipv4 = $CONTAINER_CIDR |
|
66 |
-# allow tap/tun devices |
|
67 |
-lxc.cgroup.devices.allow = c 10:200 rwm |
|
68 |
-EOF |
|
69 |
- |
|
70 |
-# Shutdown any existing container |
|
71 |
-lxc-stop -n $CONTAINER |
|
72 |
- |
|
73 |
-# This kills zombie containers |
|
74 |
-if [ -d /cgroup/$CONTAINER ]; then |
|
75 |
- cgdelete -r cpu,net_cls:$CONTAINER |
|
76 |
-fi |
|
77 |
- |
|
78 |
-# git clone only if directory doesn't exist already. Since ``DEST`` might not |
|
79 |
-# be owned by the installation user, we create the directory and change the |
|
80 |
-# ownership to the proper user. |
|
81 |
-function git_clone { |
|
82 |
- if [ ! -d $2 ]; then |
|
83 |
- sudo mkdir $2 |
|
84 |
- sudo chown `whoami` $2 |
|
85 |
- git clone $1 $2 |
|
86 |
- cd $2 |
|
87 |
- # This checkout syntax works for both branches and tags |
|
88 |
- git checkout $3 |
|
89 |
- fi |
|
90 |
-} |
|
91 |
- |
|
92 |
-# Location of the base image directory |
|
93 |
-CACHEDIR=/var/cache/lxc/natty/rootfs-amd64 |
|
94 |
- |
|
95 |
-# Provide option to do totally clean install |
|
96 |
-if [ "$CLEAR_LXC_CACHE" = "1" ]; then |
|
97 |
- rm -rf $CACHEDIR |
|
98 |
-fi |
|
99 |
- |
|
100 |
-# Warm the base image on first install |
|
101 |
-if [ ! -f $CACHEDIR/bootstrapped ]; then |
|
102 |
- # by deleting the container, we force lxc-create to re-bootstrap (lxc is |
|
103 |
- # lazy and doesn't do anything if a container already exists) |
|
104 |
- lxc-destroy -n $CONTAINER |
|
105 |
- # trigger the initial debootstrap |
|
106 |
- lxc-create -n $CONTAINER -t natty -f $LXC_CONF |
|
107 |
- chroot $CACHEDIR apt-get update |
|
108 |
- chroot $CACHEDIR apt-get install -y --force-yes `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"` |
|
109 |
- chroot $CACHEDIR pip install `cat files/pips/*` |
|
110 |
- touch $CACHEDIR/bootstrapped |
|
111 |
-fi |
|
112 |
- |
|
113 |
-# Clean out code repos if directed to do so |
|
114 |
-if [ "$CLEAN" = "1" ]; then |
|
115 |
- rm -rf $CACHEDIR/$DEST |
|
116 |
-fi |
|
117 |
- |
|
118 |
-# Cache openstack code |
|
119 |
-mkdir -p $CACHEDIR/$DEST |
|
120 |
-git_clone $NOVA_REPO $CACHEDIR/$DEST/nova $NOVA_BRANCH |
|
121 |
-git_clone $GLANCE_REPO $CACHEDIR/$DEST/glance $GLANCE_BRANCH |
|
122 |
-git_clone $KEYSTONE_REPO $CACHEDIR/$DESTkeystone $KEYSTONE_BRANCH |
|
123 |
-git_clone $NOVNC_REPO $CACHEDIR/$DEST/novnc $NOVNC_BRANCH |
|
124 |
-git_clone $DASH_REPO $CACHEDIR/$DEST/dash $DASH_BRANCH $DASH_TAG |
|
125 |
-git_clone $NOVACLIENT_REPO $CACHEDIR/$DEST/python-novaclient $NOVACLIENT_BRANCH |
|
126 |
-git_clone $OPENSTACKX_REPO $CACHEDIR/$DEST/openstackx $OPENSTACKX_BRANCH |
|
127 |
- |
|
128 |
-# Use this version of devstack? |
|
129 |
-if [ "$USE_CURRENT_DEVSTACK" = "1" ]; then |
|
130 |
- rm -rf $CACHEDIR/$DEST/devstack |
|
131 |
- cp -pr $CWD $CACHEDIR/$DEST/devstack |
|
132 |
-fi |
|
133 |
- |
|
134 |
-# Destroy the old container |
|
135 |
-lxc-destroy -n $CONTAINER |
|
136 |
- |
|
137 |
-# If this call is to TERMINATE the container then exit |
|
138 |
-if [ "$TERMINATE" = "1" ]; then |
|
139 |
- exit |
|
140 |
-fi |
|
141 |
- |
|
142 |
-# Create the container |
|
143 |
-lxc-create -n $CONTAINER -t natty -f $LXC_CONF |
|
144 |
- |
|
145 |
-# Specify where our container rootfs lives |
|
146 |
-ROOTFS=/var/lib/lxc/$CONTAINER/rootfs/ |
|
147 |
- |
|
148 |
-# Create a stack user that is a member of the libvirtd group so that stack |
|
149 |
-# is able to interact with libvirt. |
|
150 |
-chroot $ROOTFS groupadd libvirtd |
|
151 |
-chroot $ROOTFS useradd stack -s /bin/bash -d $DEST -G libvirtd |
|
152 |
- |
|
153 |
-# a simple password - pass |
|
154 |
-echo stack:pass | chroot $ROOTFS chpasswd |
|
155 |
- |
|
156 |
-# and has sudo ability (in the future this should be limited to only what |
|
157 |
-# stack requires) |
|
158 |
-echo "stack ALL=(ALL) NOPASSWD: ALL" >> $ROOTFS/etc/sudoers |
|
159 |
- |
|
160 |
-# Copy kernel modules |
|
161 |
-mkdir -p $ROOTFS/lib/modules/`uname -r`/kernel |
|
162 |
-cp -p /lib/modules/`uname -r`/modules.dep $ROOTFS/lib/modules/`uname -r`/ |
|
163 |
-cp -pR /lib/modules/`uname -r`/kernel/net $ROOTFS/lib/modules/`uname -r`/kernel/ |
|
164 |
- |
|
165 |
-# Gracefully cp only if source file/dir exists |
|
166 |
-function cp_it { |
|
167 |
- if [ -e $1 ] || [ -d $1 ]; then |
|
168 |
- cp -pRL $1 $2 |
|
169 |
- fi |
|
170 |
-} |
|
171 |
- |
|
172 |
-# Copy over your ssh keys and env if desired |
|
173 |
-if [ "$COPYENV" = "1" ]; then |
|
174 |
- cp_it ~/.ssh $ROOTFS/$DEST/.ssh |
|
175 |
- cp_it ~/.ssh/id_rsa.pub $ROOTFS/$DEST/.ssh/authorized_keys |
|
176 |
- cp_it ~/.gitconfig $ROOTFS/$DEST/.gitconfig |
|
177 |
- cp_it ~/.vimrc $ROOTFS/$DEST/.vimrc |
|
178 |
- cp_it ~/.bashrc $ROOTFS/$DEST/.bashrc |
|
179 |
-fi |
|
180 |
- |
|
181 |
-# Make our ip address hostnames look nice at the command prompt |
|
182 |
-echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS/$DEST/.bashrc |
|
183 |
-echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS/etc/profile |
|
184 |
- |
|
185 |
-# Give stack ownership over $DEST so it may do the work needed |
|
186 |
-chroot $ROOTFS chown -R stack $DEST |
|
187 |
- |
|
188 |
-# Configure instance network |
|
189 |
-INTERFACES=$ROOTFS/etc/network/interfaces |
|
190 |
-cat > $INTERFACES <<EOF |
|
191 |
-auto lo |
|
192 |
-iface lo inet loopback |
|
193 |
- |
|
194 |
-auto eth0 |
|
195 |
-iface eth0 inet static |
|
196 |
- address $CONTAINER_IP |
|
197 |
- netmask $CONTAINER_NETMASK |
|
198 |
- gateway $CONTAINER_GATEWAY |
|
199 |
-EOF |
|
200 |
- |
|
201 |
-# Configure the runner |
|
202 |
-RUN_SH=$ROOTFS/$DEST/run.sh |
|
203 |
-cat > $RUN_SH <<EOF |
|
204 |
-#!/usr/bin/env bash |
|
205 |
-# Make sure dns is set up |
|
206 |
-echo "nameserver $NAMESERVER" | sudo resolvconf -a eth0 |
|
207 |
-sleep 1 |
|
208 |
- |
|
209 |
-# Kill any existing screens |
|
210 |
-killall screen |
|
211 |
- |
|
212 |
-# Install and run stack.sh |
|
213 |
-sudo apt-get update |
|
214 |
-sudo apt-get -y --force-yes install git-core vim-nox sudo |
|
215 |
-if [ ! -d "$DEST/devstack" ]; then |
|
216 |
- git clone git://github.com/cloudbuilders/devstack.git $DEST/devstack |
|
217 |
-fi |
|
218 |
-cd $DEST/devstack && $STACKSH_PARAMS ./stack.sh > /$DEST/run.sh.log |
|
219 |
-echo >> /$DEST/run.sh.log |
|
220 |
-echo >> /$DEST/run.sh.log |
|
221 |
-echo "All done! Time to start clicking." >> /$DEST/run.sh.log |
|
222 |
-EOF |
|
223 |
- |
|
224 |
-# Make the run.sh executable |
|
225 |
-chmod 755 $RUN_SH |
|
226 |
- |
|
227 |
-# Make runner launch on boot |
|
228 |
-RC_LOCAL=$ROOTFS/etc/rc.local |
|
229 |
-cat > $RC_LOCAL <<EOF |
|
230 |
-#!/bin/sh -e |
|
231 |
-su -c "$DEST/run.sh" stack |
|
232 |
-EOF |
|
233 |
- |
|
234 |
-# Configure cgroup directory |
|
235 |
-if ! mount | grep -q cgroup; then |
|
236 |
- mkdir -p /cgroup |
|
237 |
- mount none -t cgroup /cgroup |
|
238 |
-fi |
|
239 |
- |
|
240 |
-# Start our container |
|
241 |
-lxc-start -d -n $CONTAINER |
|
242 |
- |
|
243 |
-# Done creating the container, let's tail the log |
|
244 |
-echo |
|
245 |
-echo "=============================================================" |
|
246 |
-echo " -- YAY! --" |
|
247 |
-echo "=============================================================" |
|
248 |
-echo |
|
249 |
-echo "We're done creating the container, about to start tailing the" |
|
250 |
-echo "stack.sh log. It will take a second or two to start." |
|
251 |
-echo |
|
252 |
-echo "Just CTRL-C at any time to stop tailing." |
|
253 |
- |
|
254 |
-while [ ! -e "$ROOTFS/$DEST/run.sh.log" ]; do |
|
255 |
- sleep 1 |
|
256 |
-done |
|
257 |
- |
|
258 |
-tail -F $ROOTFS/$DEST/run.sh.log |
259 | 1 |
deleted file mode 100755 |
... | ... |
@@ -1,39 +0,0 @@ |
1 |
-#!/usr/bin/env bash |
|
2 |
-# Head node host, which runs glance, api, keystone |
|
3 |
-HEAD_HOST=${HEAD_HOST:-192.168.1.52} |
|
4 |
-COMPUTE_HOSTS=${COMPUTE_HOSTS:-192.168.1.53,192.168.1.54} |
|
5 |
- |
|
6 |
-# Networking params |
|
7 |
-NAMESERVER=${NAMESERVER:-192.168.1.1} |
|
8 |
-GATEWAY=${GATEWAY:-192.168.1.1} |
|
9 |
-NETMASK=${NETMASK:-255.255.255.0} |
|
10 |
-FLOATING_RANGE=${FLOATING_RANGE:-192.168.1.196/30} |
|
11 |
- |
|
12 |
-# Setting this to 1 shuts down and destroys our containers without relaunching. |
|
13 |
-TERMINATE=${TERMINATE:-0} |
|
14 |
- |
|
15 |
-# Variables common amongst all hosts in the cluster |
|
16 |
-COMMON_VARS="MYSQL_HOST=$HEAD_HOST RABBIT_HOST=$HEAD_HOST GLANCE_HOSTPORT=$HEAD_HOST:9292 NET_MAN=FlatDHCPManager FLAT_INTERFACE=eth0 FLOATING_RANGE=$FLOATING_RANGE MULTI_HOST=1" |
|
17 |
- |
|
18 |
-# Helper to launch containers |
|
19 |
-function run_lxc { |
|
20 |
- # For some reason container names with periods can cause issues :/ |
|
21 |
- CONTAINER=$1 CONTAINER_IP=$2 CONTAINER_NETMASK=$NETMASK CONTAINER_GATEWAY=$GATEWAY NAMESERVER=$NAMESERVER TERMINATE=$TERMINATE STACKSH_PARAMS="$COMMON_VARS $3" ./build_lxc.sh |
|
22 |
-} |
|
23 |
- |
|
24 |
-# Launch the head node - headnode uses a non-ip domain name, |
|
25 |
-# because rabbit won't launch with an ip addr hostname :( |
|
26 |
-run_lxc STACKMASTER $HEAD_HOST "ENABLED_SERVICES=g-api,g-reg,key,n-api,n-sch,n-vnc,dash,mysql,rabbit" |
|
27 |
- |
|
28 |
-# Wait till the head node is up |
|
29 |
-if [ ! "$TERMINATE" = "1" ]; then |
|
30 |
- while ! wget -q -O- http://$HEAD_HOST | grep -q username; do |
|
31 |
- echo "Waiting for head node ($HEAD_HOST) to start..." |
|
32 |
- sleep 5 |
|
33 |
- done |
|
34 |
-fi |
|
35 |
- |
|
36 |
-# Launch the compute hosts |
|
37 |
-for compute_host in ${COMPUTE_HOSTS//,/ }; do |
|
38 |
- run_lxc $compute_host $compute_host "ENABLED_SERVICES=n-cpu,n-net,n-api" |
|
39 |
-done |
40 | 1 |
deleted file mode 100755 |
... | ... |
@@ -1,93 +0,0 @@ |
1 |
-#!/bin/bash |
|
2 |
- |
|
3 |
-# Print some usage info |
|
4 |
-function usage { |
|
5 |
- echo "Usage: $0 [OPTION] [host_ip]" |
|
6 |
- echo "Set up temporary networking for LXC" |
|
7 |
- echo "" |
|
8 |
- echo " -n, --dry-run Just print the commands that would execute." |
|
9 |
- echo " -h, --help Print this usage message." |
|
10 |
- echo "" |
|
11 |
- exit |
|
12 |
-} |
|
13 |
- |
|
14 |
-# Allow passing the ip address on the command line. |
|
15 |
-function process_option { |
|
16 |
- case "$1" in |
|
17 |
- -h|--help) usage;; |
|
18 |
- -n|--dry-run) dry_run=1;; |
|
19 |
- *) host_ip="$1" |
|
20 |
- esac |
|
21 |
-} |
|
22 |
- |
|
23 |
-# Set up some defaults |
|
24 |
-host_ip= |
|
25 |
-dry_run=0 |
|
26 |
-bridge=br0 |
|
27 |
-DRIER= |
|
28 |
- |
|
29 |
-# Process the args |
|
30 |
-for arg in "$@"; do |
|
31 |
- process_option $arg |
|
32 |
-done |
|
33 |
- |
|
34 |
-if [ $dry_run ]; then |
|
35 |
- DRIER=echo |
|
36 |
-fi |
|
37 |
- |
|
38 |
-if [ "$UID" -ne "0" ]; then |
|
39 |
- echo "This script must be run with root privileges." |
|
40 |
- exit 1 |
|
41 |
-fi |
|
42 |
- |
|
43 |
-# Check for bridge-utils. |
|
44 |
-BRCTL=`which brctl` |
|
45 |
-if [ ! -x "$BRCTL" ]; then |
|
46 |
- echo "This script requires you to install bridge-utils." |
|
47 |
- echo "Try: sudo apt-get install bridge-utils." |
|
48 |
- exit 1 |
|
49 |
-fi |
|
50 |
- |
|
51 |
-# Scare off the nubs. |
|
52 |
-echo "=====================================================" |
|
53 |
-echo |
|
54 |
-echo "WARNING" |
|
55 |
-echo |
|
56 |
-echo "This script will modify your current network setup," |
|
57 |
-echo "this can be a scary thing and it is recommended that" |
|
58 |
-echo "you have something equivalent to physical access to" |
|
59 |
-echo "this machine before continuing in case your network" |
|
60 |
-echo "gets all funky." |
|
61 |
-echo |
|
62 |
-echo "If you don't want to continue, hit CTRL-C now." |
|
63 |
- |
|
64 |
-if [ -z "$host_ip" ]; |
|
65 |
-then |
|
66 |
- echo "Otherwise, please type in your host's ip address and" |
|
67 |
- echo "hit enter." |
|
68 |
- echo |
|
69 |
- echo "=====================================================" |
|
70 |
- read host_ip |
|
71 |
-else |
|
72 |
- echo "Otherwise hit enter." |
|
73 |
- echo |
|
74 |
- echo "=====================================================" |
|
75 |
- read accept |
|
76 |
-fi |
|
77 |
- |
|
78 |
- |
|
79 |
-# Add a bridge interface, this will choke if there is already |
|
80 |
-# a bridge named $bridge |
|
81 |
-$DRIER $BRCTL addbr $bridge |
|
82 |
-$DRIER ip addr add 192.168.1.1/24 dev $bridge |
|
83 |
-if [ $dry_run ]; then |
|
84 |
- echo "echo 1 > /proc/sys/net/ipv4/ip_forward" |
|
85 |
-else |
|
86 |
- echo 1 > /proc/sys/net/ipv4/ip_forward |
|
87 |
-fi |
|
88 |
-$DRIER ifconfig $bridge up |
|
89 |
- |
|
90 |
-# Set up the NAT for the instances |
|
91 |
-$DRIER iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j SNAT --to-source $host_ip |
|
92 |
-$DRIER iptables -I FORWARD -s 192.168.1.0/24 -j ACCEPT |
|
93 |
- |
94 | 1 |
new file mode 100755 |
... | ... |
@@ -0,0 +1,261 @@ |
0 |
+#!/usr/bin/env bash |
|
1 |
+ |
|
2 |
+# Sanity check |
|
3 |
+if [ "$EUID" -ne "0" ]; then |
|
4 |
+ echo "This script must be run with root privileges." |
|
5 |
+ exit 1 |
|
6 |
+fi |
|
7 |
+ |
|
8 |
+# Warn users who aren't on natty |
|
9 |
+if ! grep -q natty /etc/lsb-release; then |
|
10 |
+ echo "WARNING: this script has only been tested on natty" |
|
11 |
+fi |
|
12 |
+ |
|
13 |
+# Move to top devstack dir |
|
14 |
+cd .. |
|
15 |
+ |
|
16 |
+# Abort if localrc is not set |
|
17 |
+if [ ! -e ./localrc ]; then |
|
18 |
+ echo "You must have a localrc with ALL necessary passwords defined before proceeding." |
|
19 |
+ echo "See stack.sh for required passwords." |
|
20 |
+ exit 1 |
|
21 |
+fi |
|
22 |
+ |
|
23 |
+# Source params |
|
24 |
+source ./stackrc |
|
25 |
+ |
|
26 |
+# Store cwd |
|
27 |
+CWD=`pwd` |
|
28 |
+ |
|
29 |
+# Configurable params |
|
30 |
+BRIDGE=${BRIDGE:-br0} |
|
31 |
+CONTAINER=${CONTAINER:-STACK} |
|
32 |
+CONTAINER_IP=${CONTAINER_IP:-192.168.1.50} |
|
33 |
+CONTAINER_CIDR=${CONTAINER_CIDR:-$CONTAINER_IP/24} |
|
34 |
+CONTAINER_NETMASK=${CONTAINER_NETMASK:-255.255.255.0} |
|
35 |
+CONTAINER_GATEWAY=${CONTAINER_GATEWAY:-192.168.1.1} |
|
36 |
+NAMESERVER=${NAMESERVER:-$CONTAINER_GATEWAY} |
|
37 |
+COPYENV=${COPYENV:-1} |
|
38 |
+DEST=${DEST:-/opt/stack} |
|
39 |
+ |
|
40 |
+# Param string to pass to stack.sh. Like "EC2_DMZ_HOST=192.168.1.1 MYSQL_USER=nova" |
|
41 |
+STACKSH_PARAMS=${STACKSH_PARAMS:-} |
|
42 |
+ |
|
43 |
+# Option to use the version of devstack on which we are currently working |
|
44 |
+USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1} |
|
45 |
+ |
|
46 |
+ |
|
47 |
+# Install deps |
|
48 |
+apt-get install -y lxc debootstrap |
|
49 |
+ |
|
50 |
+# Install cgroup-bin from source, since the packaging is buggy and possibly incompatible with our setup |
|
51 |
+if ! which cgdelete | grep -q cgdelete; then |
|
52 |
+ apt-get install -y g++ bison flex libpam0g-dev make |
|
53 |
+ wget http://sourceforge.net/projects/libcg/files/libcgroup/v0.37.1/libcgroup-0.37.1.tar.bz2/download -O /tmp/libcgroup-0.37.1.tar.bz2 |
|
54 |
+ cd /tmp && bunzip2 libcgroup-0.37.1.tar.bz2 && tar xfv libcgroup-0.37.1.tar |
|
55 |
+ cd libcgroup-0.37.1 |
|
56 |
+ ./configure |
|
57 |
+ make install |
|
58 |
+ ldconfig |
|
59 |
+fi |
|
60 |
+ |
|
61 |
+# Create lxc configuration |
|
62 |
+LXC_CONF=/tmp/$CONTAINER.conf |
|
63 |
+cat > $LXC_CONF <<EOF |
|
64 |
+lxc.network.type = veth |
|
65 |
+lxc.network.link = $BRIDGE |
|
66 |
+lxc.network.flags = up |
|
67 |
+lxc.network.ipv4 = $CONTAINER_CIDR |
|
68 |
+# allow tap/tun devices |
|
69 |
+lxc.cgroup.devices.allow = c 10:200 rwm |
|
70 |
+EOF |
|
71 |
+ |
|
72 |
+# Shutdown any existing container |
|
73 |
+lxc-stop -n $CONTAINER |
|
74 |
+ |
|
75 |
+# This kills zombie containers |
|
76 |
+if [ -d /cgroup/$CONTAINER ]; then |
|
77 |
+ cgdelete -r cpu,net_cls:$CONTAINER |
|
78 |
+fi |
|
79 |
+ |
|
80 |
+# git clone only if directory doesn't exist already. Since ``DEST`` might not |
|
81 |
+# be owned by the installation user, we create the directory and change the |
|
82 |
+# ownership to the proper user. |
|
83 |
+function git_clone { |
|
84 |
+ if [ ! -d $2 ]; then |
|
85 |
+ sudo mkdir $2 |
|
86 |
+ sudo chown `whoami` $2 |
|
87 |
+ git clone $1 $2 |
|
88 |
+ cd $2 |
|
89 |
+ # This checkout syntax works for both branches and tags |
|
90 |
+ git checkout $3 |
|
91 |
+ fi |
|
92 |
+} |
|
93 |
+ |
|
94 |
+# Location of the base image directory |
|
95 |
+CACHEDIR=/var/cache/lxc/natty/rootfs-amd64 |
|
96 |
+ |
|
97 |
+# Provide option to do totally clean install |
|
98 |
+if [ "$CLEAR_LXC_CACHE" = "1" ]; then |
|
99 |
+ rm -rf $CACHEDIR |
|
100 |
+fi |
|
101 |
+ |
|
102 |
+# Warm the base image on first install |
|
103 |
+if [ ! -f $CACHEDIR/bootstrapped ]; then |
|
104 |
+ # by deleting the container, we force lxc-create to re-bootstrap (lxc is |
|
105 |
+ # lazy and doesn't do anything if a container already exists) |
|
106 |
+ lxc-destroy -n $CONTAINER |
|
107 |
+ # trigger the initial debootstrap |
|
108 |
+ lxc-create -n $CONTAINER -t natty -f $LXC_CONF |
|
109 |
+ chroot $CACHEDIR apt-get update |
|
110 |
+ chroot $CACHEDIR apt-get install -y --force-yes `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"` |
|
111 |
+ chroot $CACHEDIR pip install `cat files/pips/*` |
|
112 |
+ touch $CACHEDIR/bootstrapped |
|
113 |
+fi |
|
114 |
+ |
|
115 |
+# Clean out code repos if directed to do so |
|
116 |
+if [ "$CLEAN" = "1" ]; then |
|
117 |
+ rm -rf $CACHEDIR/$DEST |
|
118 |
+fi |
|
119 |
+ |
|
120 |
+# Cache openstack code |
|
121 |
+mkdir -p $CACHEDIR/$DEST |
|
122 |
+git_clone $NOVA_REPO $CACHEDIR/$DEST/nova $NOVA_BRANCH |
|
123 |
+git_clone $GLANCE_REPO $CACHEDIR/$DEST/glance $GLANCE_BRANCH |
|
124 |
+git_clone $KEYSTONE_REPO $CACHEDIR/$DESTkeystone $KEYSTONE_BRANCH |
|
125 |
+git_clone $NOVNC_REPO $CACHEDIR/$DEST/novnc $NOVNC_BRANCH |
|
126 |
+git_clone $DASH_REPO $CACHEDIR/$DEST/dash $DASH_BRANCH $DASH_TAG |
|
127 |
+git_clone $NOVACLIENT_REPO $CACHEDIR/$DEST/python-novaclient $NOVACLIENT_BRANCH |
|
128 |
+git_clone $OPENSTACKX_REPO $CACHEDIR/$DEST/openstackx $OPENSTACKX_BRANCH |
|
129 |
+ |
|
130 |
+# Use this version of devstack? |
|
131 |
+if [ "$USE_CURRENT_DEVSTACK" = "1" ]; then |
|
132 |
+ rm -rf $CACHEDIR/$DEST/devstack |
|
133 |
+ cp -pr $CWD $CACHEDIR/$DEST/devstack |
|
134 |
+fi |
|
135 |
+ |
|
136 |
+# Destroy the old container |
|
137 |
+lxc-destroy -n $CONTAINER |
|
138 |
+ |
|
139 |
+# If this call is to TERMINATE the container then exit |
|
140 |
+if [ "$TERMINATE" = "1" ]; then |
|
141 |
+ exit |
|
142 |
+fi |
|
143 |
+ |
|
144 |
+# Create the container |
|
145 |
+lxc-create -n $CONTAINER -t natty -f $LXC_CONF |
|
146 |
+ |
|
147 |
+# Specify where our container rootfs lives |
|
148 |
+ROOTFS=/var/lib/lxc/$CONTAINER/rootfs/ |
|
149 |
+ |
|
150 |
+# Create a stack user that is a member of the libvirtd group so that stack |
|
151 |
+# is able to interact with libvirt. |
|
152 |
+chroot $ROOTFS groupadd libvirtd |
|
153 |
+chroot $ROOTFS useradd stack -s /bin/bash -d $DEST -G libvirtd |
|
154 |
+ |
|
155 |
+# a simple password - pass |
|
156 |
+echo stack:pass | chroot $ROOTFS chpasswd |
|
157 |
+ |
|
158 |
+# and has sudo ability (in the future this should be limited to only what |
|
159 |
+# stack requires) |
|
160 |
+echo "stack ALL=(ALL) NOPASSWD: ALL" >> $ROOTFS/etc/sudoers |
|
161 |
+ |
|
162 |
+# Copy kernel modules |
|
163 |
+mkdir -p $ROOTFS/lib/modules/`uname -r`/kernel |
|
164 |
+cp -p /lib/modules/`uname -r`/modules.dep $ROOTFS/lib/modules/`uname -r`/ |
|
165 |
+cp -pR /lib/modules/`uname -r`/kernel/net $ROOTFS/lib/modules/`uname -r`/kernel/ |
|
166 |
+ |
|
167 |
+# Gracefully cp only if source file/dir exists |
|
168 |
+function cp_it { |
|
169 |
+ if [ -e $1 ] || [ -d $1 ]; then |
|
170 |
+ cp -pRL $1 $2 |
|
171 |
+ fi |
|
172 |
+} |
|
173 |
+ |
|
174 |
+# Copy over your ssh keys and env if desired |
|
175 |
+if [ "$COPYENV" = "1" ]; then |
|
176 |
+ cp_it ~/.ssh $ROOTFS/$DEST/.ssh |
|
177 |
+ cp_it ~/.ssh/id_rsa.pub $ROOTFS/$DEST/.ssh/authorized_keys |
|
178 |
+ cp_it ~/.gitconfig $ROOTFS/$DEST/.gitconfig |
|
179 |
+ cp_it ~/.vimrc $ROOTFS/$DEST/.vimrc |
|
180 |
+ cp_it ~/.bashrc $ROOTFS/$DEST/.bashrc |
|
181 |
+fi |
|
182 |
+ |
|
183 |
+# Make our ip address hostnames look nice at the command prompt |
|
184 |
+echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS/$DEST/.bashrc |
|
185 |
+echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS/etc/profile |
|
186 |
+ |
|
187 |
+# Give stack ownership over $DEST so it may do the work needed |
|
188 |
+chroot $ROOTFS chown -R stack $DEST |
|
189 |
+ |
|
190 |
+# Configure instance network |
|
191 |
+INTERFACES=$ROOTFS/etc/network/interfaces |
|
192 |
+cat > $INTERFACES <<EOF |
|
193 |
+auto lo |
|
194 |
+iface lo inet loopback |
|
195 |
+ |
|
196 |
+auto eth0 |
|
197 |
+iface eth0 inet static |
|
198 |
+ address $CONTAINER_IP |
|
199 |
+ netmask $CONTAINER_NETMASK |
|
200 |
+ gateway $CONTAINER_GATEWAY |
|
201 |
+EOF |
|
202 |
+ |
|
203 |
+# Configure the runner |
|
204 |
+RUN_SH=$ROOTFS/$DEST/run.sh |
|
205 |
+cat > $RUN_SH <<EOF |
|
206 |
+#!/usr/bin/env bash |
|
207 |
+# Make sure dns is set up |
|
208 |
+echo "nameserver $NAMESERVER" | sudo resolvconf -a eth0 |
|
209 |
+sleep 1 |
|
210 |
+ |
|
211 |
+# Kill any existing screens |
|
212 |
+killall screen |
|
213 |
+ |
|
214 |
+# Install and run stack.sh |
|
215 |
+sudo apt-get update |
|
216 |
+sudo apt-get -y --force-yes install git-core vim-nox sudo |
|
217 |
+if [ ! -d "$DEST/devstack" ]; then |
|
218 |
+ git clone git://github.com/cloudbuilders/devstack.git $DEST/devstack |
|
219 |
+fi |
|
220 |
+cd $DEST/devstack && $STACKSH_PARAMS ./stack.sh > /$DEST/run.sh.log |
|
221 |
+echo >> /$DEST/run.sh.log |
|
222 |
+echo >> /$DEST/run.sh.log |
|
223 |
+echo "All done! Time to start clicking." >> /$DEST/run.sh.log |
|
224 |
+EOF |
|
225 |
+ |
|
226 |
+# Make the run.sh executable |
|
227 |
+chmod 755 $RUN_SH |
|
228 |
+ |
|
229 |
+# Make runner launch on boot |
|
230 |
+RC_LOCAL=$ROOTFS/etc/rc.local |
|
231 |
+cat > $RC_LOCAL <<EOF |
|
232 |
+#!/bin/sh -e |
|
233 |
+su -c "$DEST/run.sh" stack |
|
234 |
+EOF |
|
235 |
+ |
|
236 |
+# Configure cgroup directory |
|
237 |
+if ! mount | grep -q cgroup; then |
|
238 |
+ mkdir -p /cgroup |
|
239 |
+ mount none -t cgroup /cgroup |
|
240 |
+fi |
|
241 |
+ |
|
242 |
+# Start our container |
|
243 |
+lxc-start -d -n $CONTAINER |
|
244 |
+ |
|
245 |
+# Done creating the container, let's tail the log |
|
246 |
+echo |
|
247 |
+echo "=============================================================" |
|
248 |
+echo " -- YAY! --" |
|
249 |
+echo "=============================================================" |
|
250 |
+echo |
|
251 |
+echo "We're done creating the container, about to start tailing the" |
|
252 |
+echo "stack.sh log. It will take a second or two to start." |
|
253 |
+echo |
|
254 |
+echo "Just CTRL-C at any time to stop tailing." |
|
255 |
+ |
|
256 |
+while [ ! -e "$ROOTFS/$DEST/run.sh.log" ]; do |
|
257 |
+ sleep 1 |
|
258 |
+done |
|
259 |
+ |
|
260 |
+tail -F $ROOTFS/$DEST/run.sh.log |
0 | 261 |
new file mode 100755 |
... | ... |
@@ -0,0 +1,39 @@ |
0 |
+#!/usr/bin/env bash |
|
1 |
+# Head node host, which runs glance, api, keystone |
|
2 |
+HEAD_HOST=${HEAD_HOST:-192.168.1.52} |
|
3 |
+COMPUTE_HOSTS=${COMPUTE_HOSTS:-192.168.1.53,192.168.1.54} |
|
4 |
+ |
|
5 |
+# Networking params |
|
6 |
+NAMESERVER=${NAMESERVER:-192.168.1.1} |
|
7 |
+GATEWAY=${GATEWAY:-192.168.1.1} |
|
8 |
+NETMASK=${NETMASK:-255.255.255.0} |
|
9 |
+FLOATING_RANGE=${FLOATING_RANGE:-192.168.1.196/30} |
|
10 |
+ |
|
11 |
+# Setting this to 1 shuts down and destroys our containers without relaunching. |
|
12 |
+TERMINATE=${TERMINATE:-0} |
|
13 |
+ |
|
14 |
+# Variables common amongst all hosts in the cluster |
|
15 |
+COMMON_VARS="MYSQL_HOST=$HEAD_HOST RABBIT_HOST=$HEAD_HOST GLANCE_HOSTPORT=$HEAD_HOST:9292 NET_MAN=FlatDHCPManager FLAT_INTERFACE=eth0 FLOATING_RANGE=$FLOATING_RANGE MULTI_HOST=1" |
|
16 |
+ |
|
17 |
+# Helper to launch containers |
|
18 |
+function run_lxc { |
|
19 |
+ # For some reason container names with periods can cause issues :/ |
|
20 |
+ CONTAINER=$1 CONTAINER_IP=$2 CONTAINER_NETMASK=$NETMASK CONTAINER_GATEWAY=$GATEWAY NAMESERVER=$NAMESERVER TERMINATE=$TERMINATE STACKSH_PARAMS="$COMMON_VARS $3" ./build_lxc.sh |
|
21 |
+} |
|
22 |
+ |
|
23 |
+# Launch the head node - headnode uses a non-ip domain name, |
|
24 |
+# because rabbit won't launch with an ip addr hostname :( |
|
25 |
+run_lxc STACKMASTER $HEAD_HOST "ENABLED_SERVICES=g-api,g-reg,key,n-api,n-sch,n-vnc,dash,mysql,rabbit" |
|
26 |
+ |
|
27 |
+# Wait till the head node is up |
|
28 |
+if [ ! "$TERMINATE" = "1" ]; then |
|
29 |
+ while ! wget -q -O- http://$HEAD_HOST | grep -q username; do |
|
30 |
+ echo "Waiting for head node ($HEAD_HOST) to start..." |
|
31 |
+ sleep 5 |
|
32 |
+ done |
|
33 |
+fi |
|
34 |
+ |
|
35 |
+# Launch the compute hosts |
|
36 |
+for compute_host in ${COMPUTE_HOSTS//,/ }; do |
|
37 |
+ run_lxc $compute_host $compute_host "ENABLED_SERVICES=n-cpu,n-net,n-api" |
|
38 |
+done |
0 | 39 |
new file mode 100755 |
... | ... |
@@ -0,0 +1,93 @@ |
0 |
+#!/bin/bash |
|
1 |
+ |
|
2 |
+# Print some usage info |
|
3 |
+function usage { |
|
4 |
+ echo "Usage: $0 [OPTION] [host_ip]" |
|
5 |
+ echo "Set up temporary networking for LXC" |
|
6 |
+ echo "" |
|
7 |
+ echo " -n, --dry-run Just print the commands that would execute." |
|
8 |
+ echo " -h, --help Print this usage message." |
|
9 |
+ echo "" |
|
10 |
+ exit |
|
11 |
+} |
|
12 |
+ |
|
13 |
+# Allow passing the ip address on the command line. |
|
14 |
+function process_option { |
|
15 |
+ case "$1" in |
|
16 |
+ -h|--help) usage;; |
|
17 |
+ -n|--dry-run) dry_run=1;; |
|
18 |
+ *) host_ip="$1" |
|
19 |
+ esac |
|
20 |
+} |
|
21 |
+ |
|
22 |
+# Set up some defaults |
|
23 |
+host_ip= |
|
24 |
+dry_run=0 |
|
25 |
+bridge=br0 |
|
26 |
+DRIER= |
|
27 |
+ |
|
28 |
+# Process the args |
|
29 |
+for arg in "$@"; do |
|
30 |
+ process_option $arg |
|
31 |
+done |
|
32 |
+ |
|
33 |
+if [ $dry_run ]; then |
|
34 |
+ DRIER=echo |
|
35 |
+fi |
|
36 |
+ |
|
37 |
+if [ "$UID" -ne "0" ]; then |
|
38 |
+ echo "This script must be run with root privileges." |
|
39 |
+ exit 1 |
|
40 |
+fi |
|
41 |
+ |
|
42 |
+# Check for bridge-utils. |
|
43 |
+BRCTL=`which brctl` |
|
44 |
+if [ ! -x "$BRCTL" ]; then |
|
45 |
+ echo "This script requires you to install bridge-utils." |
|
46 |
+ echo "Try: sudo apt-get install bridge-utils." |
|
47 |
+ exit 1 |
|
48 |
+fi |
|
49 |
+ |
|
50 |
+# Scare off the nubs. |
|
51 |
+echo "=====================================================" |
|
52 |
+echo |
|
53 |
+echo "WARNING" |
|
54 |
+echo |
|
55 |
+echo "This script will modify your current network setup," |
|
56 |
+echo "this can be a scary thing and it is recommended that" |
|
57 |
+echo "you have something equivalent to physical access to" |
|
58 |
+echo "this machine before continuing in case your network" |
|
59 |
+echo "gets all funky." |
|
60 |
+echo |
|
61 |
+echo "If you don't want to continue, hit CTRL-C now." |
|
62 |
+ |
|
63 |
+if [ -z "$host_ip" ]; |
|
64 |
+then |
|
65 |
+ echo "Otherwise, please type in your host's ip address and" |
|
66 |
+ echo "hit enter." |
|
67 |
+ echo |
|
68 |
+ echo "=====================================================" |
|
69 |
+ read host_ip |
|
70 |
+else |
|
71 |
+ echo "Otherwise hit enter." |
|
72 |
+ echo |
|
73 |
+ echo "=====================================================" |
|
74 |
+ read accept |
|
75 |
+fi |
|
76 |
+ |
|
77 |
+ |
|
78 |
+# Add a bridge interface, this will choke if there is already |
|
79 |
+# a bridge named $bridge |
|
80 |
+$DRIER $BRCTL addbr $bridge |
|
81 |
+$DRIER ip addr add 192.168.1.1/24 dev $bridge |
|
82 |
+if [ $dry_run ]; then |
|
83 |
+ echo "echo 1 > /proc/sys/net/ipv4/ip_forward" |
|
84 |
+else |
|
85 |
+ echo 1 > /proc/sys/net/ipv4/ip_forward |
|
86 |
+fi |
|
87 |
+$DRIER ifconfig $bridge up |
|
88 |
+ |
|
89 |
+# Set up the NAT for the instances |
|
90 |
+$DRIER iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j SNAT --to-source $host_ip |
|
91 |
+$DRIER iptables -I FORWARD -s 192.168.1.0/24 -j ACCEPT |
|
92 |
+ |