~smoser/+junk/uec-on-ec2

1 by Scott Moser
initial functional version
1
#!/bin/bash
2
# this expects to be run as root
3
# run the commands that follow on one of the following:
4
#
5
# us-east-1 ami-4b4ba522 ebs/ubuntu-lucid-10.04-amd64-server-20100427.1
6
# us-east-1 ami-fd4aa494 ubuntu-lucid-10.04-amd64-server-20100427.1
7
#
8
## launch an instance:
9
## $ ec2-run-instances ami-fd4aa494 --instance-type m1.large
10
11
# on the instance
12
IFACE=${IFACE:-eth0}
13
# stolen from /etc/eucalyptus/eucalyptus-ipaddr.conf
14
addr_withprefix=$(ip addr show label ${IFACE} scope global | awk '$1 == "inet" { print $2 }')
15
IPADDR=${addr_withprefix%%/*}
16
17
while read tok1 tok2 rest ; do
18
   [ "${tok1}" = "nameserver" ] && NAMESERVER=${tok2} && break
19
done < /etc/resolv.conf
20
21
cat <<EOF | debconf-set-selections
22
postfix postfix/mailname        string  localhost.localdomain
23
postfix postfix/main_mailer_type        select  Internet Site
24
eucalyptus-cc   eucalyptus/mode select  MANAGED
25
eucalyptus-cc   eucalyptus/publicips    string
26
eucalyptus-cc   eucalyptus/dns  string  ${NAMESERVER}
27
eucalyptus-cc   eucalyptus/cluster-name string  cluster1
28
eucalyptus-nc   eucalyptus/cluster-name string  cluster1
29
eucalyptus-sc   eucalyptus/cluster-name string  cluster1
30
grub-pc grub2/linux_cmdline string
31
grub-pc grub-pc/install_devices_empty boolean true
32
EOF
33
34
# mount the second ephemeral storage to /var/lib/eucalyptus for
35
# more space.
36
mkdir /var/lib/eucalyptus
37
printf "/dev/sdc\t/var/lib/eucalyptus\tauto\tdefaults\t0\t0\n" >> /etc/fstab
38
mount /var/lib/eucalyptus
39
5 by Scott Moser
add noninteractive DEBIAN_FRONTEND to commands.txt
40
export DEBIAN_FRONTEND=noninteractive
1 by Scott Moser
initial functional version
41
apt-add-repository ppa:smoser/ppa
42
apt-get update
43
apt-get install --assume-yes libvirt-bin  debconf-utils
44
apt-get upgrade --assume-yes
45
46
# set debconf to critical to avoid the prompt about lack of vt
47
#  eucalyptus-nc eucalyptus-nc/no_vmx error
48
#
49
dc_val=$(debconf-get-selections | awk '$2 == "debconf/priority" { print $4 }')
50
echo "debconf debconf/priority        string critical" | debconf-set-selections
51
52
DEBIAN_FRONTEND=noninteractive apt-get install --assume-yes "eucalyptus-*"
53
54
# reset debconf priority
55
echo "debconf debconf/priority        string ${dc_val}" | debconf-set-selections
56
57
stop eucalyptus CLEAN=1
58
stop eucalyptus-nc
59
60
begin_mark="#==== BEGIN LOCAL_ADMIN_SECTION ===="
61
end_mark="#==== END   LOCAL_ADMIN_SECTION ===="
62
63
lfile=/etc/eucalyptus/eucalyptus.local.conf
64
if [ -e "${lfile}" ]; then
65
   sed -i "/${begin_mark}/,/${end_mark}/d" "${lfile}" ||
66
      fail "failed to edit ${lfile}"
67
fi
68
[ -e ${lfile}.dist ] || cp ${lfile} ${lfile}.dist
69
70
cat > "${lfile}" <<EOF
71
${begin_mark}
72
VNET_INTERFACE="br0"
73
VNET_PRIVINTERFACE="br0"
74
VNET_MODE="MANAGED"
75
VNET_SUBNET="172.19.0.0"
76
VNET_NETMASK="255.255.0.0"
77
VNET_DNS="${NAMESERVER}"
78
VNET_ADDRSPERNET="32"
79
VNET_CLOUDIP="${IPADDR}"
80
VNET_LOCALIP="${IPADDR}"
81
VNET_PUBLICIPS="192.168.1.100-192.168.1.116"
82
MAX_CORES="16"
83
${end_mark}
84
EOF
85
86
ifile=/etc/network/interfaces
87
if [ ! -e "${ifile}.dist" ]; then
88
   cp -a "${ifile}" "${ifile}.dist"
89
   cat > "${ifile}" <<EOF
90
auto lo
91
iface lo inet loopback
92
iface eth0 inet manual
93
auto br0
94
iface br0 inet dhcp
95
    bridge_ports eth0
96
    bridge_fd 9
97
    bridge_hello 2
98
    bridge_maxage 12
99
    bridge_stp off
100
EOF
101
fi
102
103
# TODO: probably better way to handle change to /etc/cloud/cloud-init.conf
104
#       to not have eth0 as we're brining up br0 now
105
( cd /etc/init && for f in cloud-*; do mv $f $f.disabled; done )
106
107
108
# from /usr/sbin/euca_conf
109
su eucalyptus -c 'sh -c "mkdir -p ~eucalyptus/.ssh &&
110
   cat >> ~eucalyptus/.ssh/authorized_keys"' < ~eucalyptus/.ssh/id_rsa.pub
111
su eucalyptus -c "sh -c 'ssh-keyscan ${IPADDR} > ~eucalyptus/.ssh/known_hosts'"
112
113
sed -i.dist "s/domain type='kvm'/domain type='qemu'/" \
114
   /usr/share/eucalyptus/gen_kvm_libvirt_xml 
115
116
# this actually gets eucalyptus started (due to upstart)
117
stop networking ; start networking
118
119
#stop  eucalyptus CLEAN=1
120
#stop  eucalyptus-nc 
121
start eucalyptus CLEAN=1; start eucalyptus-nc 
122
123
echo "sleeping for a bit"
124
euca_conf --deregister-sc cluster1
125
euca_conf --deregister-cluster cluster1
126
euca_conf --register-cluster cluster1 ${IPADDR}
127
euca_conf --register-sc cluster1 ${IPADDR}
128
euca_conf --register-nodes "${IPADDR}"
129
130
#
131
#
132
# i think eucalyptus gets confused by the multiple addresses of the node
133
# (it has 3 at least now).  Deregister the non-real ones
134
euca_conf --deregister-nodes 172.19.1.1
135
euca_conf --deregister-nodes 192.168.122.1
136
137
su ubuntu -c 'sh -c "cd && wget http://smoser.brickies.net/ubuntu/ttylinux-uec/fastboot-amd64-0.11.tar.gz"'
138
139
sudo -u ubuntu sh -c 'cd && mkdir -p euca &&
140
   cd euca && sudo euca_conf --get-credentials mycreds.zip &&
141
   unzip mycreds.zip && ln -s euca/eucarc ~/.eucarc'
142
143
url="http://uec-images.ubuntu.com/releases/lucid/release/ubuntu-10.04-server-uec-amd64.tar.gz"
144
145
( cd ~ubuntu && sudo -u ubuntu wget "${url}" )
146
147
# uec-publish-tarball fastboot-amd64-0.11.tar.gz fastboot-amd64-0.11 amd64
148
# this image has 'password' as default password for 'ubuntu' or 'root'
149
150
# uec-publish-tarball ubuntu-10.04-server-uec-amd64.tar.gz ubuntu-10.04-server-amd64
151
# ( umask 066 ; euca-add-keypair mykey > mykey.pem )
152
# euca-run-instances --addressing private --key mykey emi-4D6C12BF 
153
154
155
#  TODO:
156
#   guests do not have proper outbound networking if not launched with
157
#      "euca-run-instances --addressing private"
158
#      (host -> guest works, though)