1
Description: add lxc-ubuntu-cloud template
2
Author: Serge Hallyn <serge.hallyn@canonical.com>
5
Index: lxc-0.7.5/configure
6
===================================================================
7
--- lxc-0.7.5.orig/configure 2012-02-08 14:17:32.000000000 -0600
8
+++ lxc-0.7.5/configure 2012-02-08 14:17:32.000000000 -0600
10
CFLAGS="$CFLAGS -Wall"
13
-ac_config_files="$ac_config_files Makefile lxc.pc lxc.spec config/Makefile doc/Makefile doc/lxc-create.sgml doc/lxc-destroy.sgml doc/lxc-execute.sgml doc/lxc-start.sgml doc/lxc-checkpoint.sgml doc/lxc-restart.sgml doc/lxc-stop.sgml doc/lxc-console.sgml doc/lxc-freeze.sgml doc/lxc-unfreeze.sgml doc/lxc-monitor.sgml doc/lxc-wait.sgml doc/lxc-ls.sgml doc/lxc-ps.sgml doc/lxc-cgroup.sgml doc/lxc-kill.sgml doc/lxc.conf.sgml doc/lxc.sgml doc/common_options.sgml doc/see_also.sgml doc/rootfs/Makefile doc/examples/Makefile doc/examples/lxc-macvlan.conf doc/examples/lxc-vlan.conf doc/examples/lxc-no-netns.conf doc/examples/lxc-empty-netns.conf doc/examples/lxc-phys.conf doc/examples/lxc-veth.conf doc/examples/lxc-complex.conf templates/Makefile templates/lxc-lenny templates/lxc-debian templates/lxc-ubuntu templates/lxc-opensuse templates/lxc-busybox templates/lxc-fedora templates/lxc-sshd src/Makefile src/lxc/Makefile src/lxc/lxc-ps src/lxc/lxc-ls src/lxc/lxc-netstat src/lxc/lxc-checkconfig src/lxc/lxc-setcap src/lxc/lxc-setuid src/lxc/lxc-version src/lxc/lxc-create src/lxc/lxc-clone src/lxc/lxc-destroy"
14
+ac_config_files="$ac_config_files Makefile lxc.pc lxc.spec config/Makefile doc/Makefile doc/lxc-create.sgml doc/lxc-destroy.sgml doc/lxc-execute.sgml doc/lxc-start.sgml doc/lxc-checkpoint.sgml doc/lxc-restart.sgml doc/lxc-stop.sgml doc/lxc-console.sgml doc/lxc-freeze.sgml doc/lxc-unfreeze.sgml doc/lxc-monitor.sgml doc/lxc-wait.sgml doc/lxc-ls.sgml doc/lxc-ps.sgml doc/lxc-cgroup.sgml doc/lxc-kill.sgml doc/lxc.conf.sgml doc/lxc.sgml doc/common_options.sgml doc/see_also.sgml doc/rootfs/Makefile doc/examples/Makefile doc/examples/lxc-macvlan.conf doc/examples/lxc-vlan.conf doc/examples/lxc-no-netns.conf doc/examples/lxc-empty-netns.conf doc/examples/lxc-phys.conf doc/examples/lxc-veth.conf doc/examples/lxc-complex.conf templates/Makefile templates/lxc-lenny templates/lxc-debian templates/lxc-ubuntu templates/lxc-ubuntu-cloud templates/lxc-opensuse templates/lxc-busybox templates/lxc-fedora templates/lxc-sshd src/Makefile src/lxc/Makefile src/lxc/lxc-ps src/lxc/lxc-ls src/lxc/lxc-netstat src/lxc/lxc-checkconfig src/lxc/lxc-setcap src/lxc/lxc-setuid src/lxc/lxc-version src/lxc/lxc-create src/lxc/lxc-clone src/lxc/lxc-destroy"
16
ac_config_commands="$ac_config_commands default"
19
"templates/lxc-lenny") CONFIG_FILES="$CONFIG_FILES templates/lxc-lenny" ;;
20
"templates/lxc-debian") CONFIG_FILES="$CONFIG_FILES templates/lxc-debian" ;;
21
"templates/lxc-ubuntu") CONFIG_FILES="$CONFIG_FILES templates/lxc-ubuntu" ;;
22
+ "templates/lxc-ubuntu-cloud") CONFIG_FILES="$CONFIG_FILES templates/lxc-ubuntu-cloud" ;;
23
"templates/lxc-opensuse") CONFIG_FILES="$CONFIG_FILES templates/lxc-opensuse" ;;
24
"templates/lxc-busybox") CONFIG_FILES="$CONFIG_FILES templates/lxc-busybox" ;;
25
"templates/lxc-fedora") CONFIG_FILES="$CONFIG_FILES templates/lxc-fedora" ;;
26
Index: lxc-0.7.5/configure.ac
27
===================================================================
28
--- lxc-0.7.5.orig/configure.ac 2012-02-08 14:17:32.000000000 -0600
29
+++ lxc-0.7.5/configure.ac 2012-02-08 14:17:32.000000000 -0600
34
+ templates/lxc-ubuntu-cloud
35
templates/lxc-opensuse
38
Index: lxc-0.7.5/templates/Makefile.am
39
===================================================================
40
--- lxc-0.7.5.orig/templates/Makefile.am 2011-08-09 11:01:07.000000000 -0500
41
+++ lxc-0.7.5/templates/Makefile.am 2012-02-08 14:17:32.000000000 -0600
50
Index: lxc-0.7.5/templates/Makefile.in
51
===================================================================
52
--- lxc-0.7.5.orig/templates/Makefile.in 2011-08-11 12:02:19.000000000 -0500
53
+++ lxc-0.7.5/templates/Makefile.in 2012-02-08 14:17:32.000000000 -0600
55
$(srcdir)/lxc-busybox.in $(srcdir)/lxc-debian.in \
56
$(srcdir)/lxc-fedora.in $(srcdir)/lxc-lenny.in \
57
$(srcdir)/lxc-opensuse.in $(srcdir)/lxc-sshd.in \
58
- $(srcdir)/lxc-ubuntu.in
59
+ $(srcdir)/lxc-ubuntu.in $(srcdir)/lxc-ubuntu-cloud.in
60
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
61
am__aclocal_m4_deps = $(top_srcdir)/config/acinclude.m4 \
62
$(top_srcdir)/config/linux.m4 $(top_srcdir)/configure.ac
64
mkinstalldirs = $(install_sh) -d
65
CONFIG_HEADER = $(top_builddir)/src/config.h
66
CONFIG_CLEAN_FILES = lxc-lenny lxc-debian lxc-ubuntu lxc-opensuse \
67
- lxc-busybox lxc-fedora lxc-sshd
68
+ lxc-busybox lxc-fedora lxc-sshd lxc-ubuntu-cloud
69
CONFIG_CLEAN_VPATH_FILES =
70
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
71
am__vpath_adj = case $$p in \
81
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
82
lxc-ubuntu: $(top_builddir)/config.status $(srcdir)/lxc-ubuntu.in
83
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
84
+lxc-ubuntu-cloud: $(top_builddir)/config.status $(srcdir)/lxc-ubuntu-cloud.in
85
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
86
lxc-opensuse: $(top_builddir)/config.status $(srcdir)/lxc-opensuse.in
87
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
88
lxc-busybox: $(top_builddir)/config.status $(srcdir)/lxc-busybox.in
89
Index: lxc-0.7.5/templates/lxc-ubuntu-cloud.in
90
===================================================================
91
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
92
+++ lxc-0.7.5/templates/lxc-ubuntu-cloud.in 2012-02-08 17:03:07.966139522 -0600
96
+# template script for generating ubuntu container for LXC based on daily cloud
99
+# Copyright © 2012 Serge Hallyn <serge.hallyn@canonical.com>
101
+# This program is free software; you can redistribute it and/or modify
102
+# it under the terms of the GNU General Public License version 2, as
103
+# published by the Free Software Foundation.
105
+# This program is distributed in the hope that it will be useful,
106
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
107
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
108
+# GNU General Public License for more details.
110
+# You should have received a copy of the GNU General Public License along
111
+# with this program; if not, write to the Free Software Foundation, Inc.,
112
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
117
+if [ -r /etc/default/lxc ]; then
121
+copy_configuration()
128
+ if [ $arch = "i386" ]; then
132
+ cat <<EOF >> $path/config
137
+lxc.rootfs = $rootfs
138
+lxc.mount = $path/fstab
140
+lxc.cap.drop = sys_module mac_admin
142
+lxc.cgroup.devices.deny = a
143
+# Allow any mknod (but not using the node)
144
+lxc.cgroup.devices.allow = c *:* m
145
+lxc.cgroup.devices.allow = b *:* m
146
+# /dev/null and zero
147
+lxc.cgroup.devices.allow = c 1:3 rwm
148
+lxc.cgroup.devices.allow = c 1:5 rwm
150
+lxc.cgroup.devices.allow = c 5:1 rwm
151
+lxc.cgroup.devices.allow = c 5:0 rwm
152
+#lxc.cgroup.devices.allow = c 4:0 rwm
153
+#lxc.cgroup.devices.allow = c 4:1 rwm
155
+lxc.cgroup.devices.allow = c 1:9 rwm
156
+lxc.cgroup.devices.allow = c 1:8 rwm
157
+lxc.cgroup.devices.allow = c 136:* rwm
158
+lxc.cgroup.devices.allow = c 5:2 rwm
160
+lxc.cgroup.devices.allow = c 254:0 rwm
162
+lxc.cgroup.devices.allow = c 10:229 rwm
164
+lxc.cgroup.devices.allow = c 10:200 rwm
166
+lxc.cgroup.devices.allow = c 1:7 rwm
168
+lxc.cgroup.devices.allow = c 10:228 rwm
170
+lxc.cgroup.devices.allow = c 10:232 rwm
173
+ cat <<EOF > $path/fstab
174
+proc $rootfs/proc proc nodev,noexec,nosuid 0 0
175
+sysfs $rootfs/sys sysfs defaults 0 0
184
+$1 -h|--help [-a|--arch] [-F | --flush-cache] [-r|--release <release>]
185
+release: lucid | maverick | natty | oneiric | precise
186
+arch: amd64 or i386: defaults to host arch
191
+options=$(getopt -o a:hp:r:n:Fi:C -l arch:,help,path:,release:,name:,flush-cache,hostid:,cloud -- "$@")
192
+if [ $? -ne 0 ]; then
193
+ usage $(basename $0)
196
+eval set -- "$options"
199
+if [ -f /etc/lsb-release ]; then
201
+ case "$DISTRIB_CODENAME" in
202
+ lucid|maverick|natty|oneiric|precise)
203
+ release=$DISTRIB_CODENAME
210
+# Code taken from debootstrap
211
+if [ -x /usr/bin/dpkg ] && /usr/bin/dpkg --print-architecture >/dev/null 2>&1; then
212
+ arch=`/usr/bin/dpkg --print-architecture`
213
+elif type udpkg >/dev/null 2>&1 && udpkg --print-architecture >/dev/null 2>&1; then
214
+ arch=`/usr/bin/udpkg --print-architecture`
217
+ if [ "$arch" = "i686" ]; then
219
+ elif [ "$arch" = "x86_64" ]; then
221
+ elif [ "$arch" = "armv7l" ]; then
232
+ -h|--help) usage $0 && exit 0;;
233
+ -p|--path) path=$2; shift 2;;
234
+ -n|--name) name=$2; shift 2;;
235
+ -F|--flush-cache) flushcache=1; shift 1;;
236
+ -r|--release) release=$2; shift 2;;
237
+ -a|--arch) arch=$2; shift 2;;
238
+ -i|--hostid) host_id=$2; shift 2;;
239
+ -u|--userdata) userdata=$2; shift 2;;
240
+ -C|--cloud) cloud=1; shift 1;;
241
+ --) shift 1; break ;;
246
+if [ "$arch" == "i686" ]; then
250
+if [ $hostarch = "i386" -a $arch = "amd64" ]; then
251
+ echo "can't create amd64 container on i386"
255
+if [ $arch != "i386" -a $arch != "amd64" ]; then
256
+ echo "Only i386 and amd64 are supported by the ubuntu cloud template."
260
+if [ -z "$path" ]; then
261
+ echo "'path' parameter is required"
265
+if [ "$(id -u)" != "0" ]; then
266
+ echo "This script should be run as 'root'"
272
+type ubuntu-cloudimg-query
275
+# determine the url, tarball, and directory names
276
+# download if needed
277
+cache="/var/cache/lxc/cloud-$release"
281
+url1=`ubuntu-cloudimg-query precise daily $arch --format "%{url}\n"`
282
+url2=`echo $url1 | sed -e 's/.tar.gz/-root\0/'`
283
+filename=`basename $url2`
285
+mkdir -p /var/lock/subsys/
290
+ if [ $flushcache -eq 1 ]; then
291
+ echo "Clearing the cached images"
295
+ if [ ! -f $filename ]; then
299
+ echo "Extracting rootfs"
302
+ tar -zxf $cache/$filename
305
+ if [ $cloud -eq 0 ]; then
306
+ echo "Configuring for running outside of a cloud environment"
307
+ echo "If you want to configure for a cloud evironment, please use '-- -C' to create the container"
309
+ seed_d=$rootfs/var/lib/cloud/seed/nocloud-net
310
+ rhostid=$(uuidgen | cut -c -8)
311
+ host_id=${hostid:-$rhostid}
314
+ cat > "$seed_d/meta-data" <<EOF
315
+instance_id: lxc-$host_id
318
+ if [ ! -f $userdata ]; then
319
+ cp $userdata $seed_d/user-data
321
+ echo "#cloud-config" > $seed_d/user-data
322
+ if [ -z "$MIRROR" ]; then
323
+ MIRROR="http://archive.ubuntu.com/ubuntu"
325
+ echo "apt-mirror: $MIRROR" >> $seed_d/user-data
328
+ chroot $rootfs /usr/sbin/usermod -U ubuntu
329
+ echo "Please login as user ubuntu with password ubuntu."
333
+ echo "Configured for running in a cloud environment."
334
+ echo "If you do not have a meta-data service, this container will likely be useless."
338
+) 200>/var/lock/subsys/lxc-ubucloud
340
+copy_configuration $path $rootfs $name $arch
342
+echo "Container $name created."