summaryrefslogtreecommitdiffstats
path: root/main/lxc
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2013-02-08 12:31:54 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2013-02-08 12:31:54 +0000
commit7295e430353ba1187da268f2167aaced0bce342b (patch)
treea1c3379f6491847e838a1588508154b35a51e548 /main/lxc
parentd4c29909a98bd939bf6443fcc7e8d1613ffc3a61 (diff)
downloadaports-7295e430353ba1187da268f2167aaced0bce342b.tar.bz2
aports-7295e430353ba1187da268f2167aaced0bce342b.tar.xz
main/lxc: provide lxc-alpine template
Diffstat (limited to 'main/lxc')
-rw-r--r--main/lxc/APKBUILD14
-rwxr-xr-xmain/lxc/lxc-alpine190
2 files changed, 200 insertions, 4 deletions
diff --git a/main/lxc/APKBUILD b/main/lxc/APKBUILD
index e30f8a671..53c73044e 100644
--- a/main/lxc/APKBUILD
+++ b/main/lxc/APKBUILD
@@ -3,7 +3,7 @@
pkgname=lxc
pkgver=0.8.0
_mypkgver=${pkgver/_rc/-rc}
-pkgrel=2
+pkgrel=3
pkgdesc="linux containers - tools"
url="http://lxc.sourceforge.net/"
arch="all"
@@ -38,16 +38,22 @@ build() {
--sysconfdir=/etc \
--localstatedir=/var \
--disable-apparmor \
- || reeturn 1
+ || return 1
make || return 1
}
package() {
+ set -e
cd "$_builddir"
- make DESTDIR="$pkgdir" install || return 1
+ make DESTDIR="$pkgdir" install
+ install -d "$pkgdir"/var/lib/lxc
+ install -Dm755 "$srcdir"/lxc-alpine \
+ "$pkgdir"/usr/share/lxc/templates/lxc-alpine
install -Dm755 "$srcdir"/lxc.initd "$pkgdir"/etc/init.d/lxc
- install -Dm755 "$srcdir"/setup-lxc-template "$pkgdir"/usr/bin/setup-lxc-template
+ install -Dm755 "$srcdir"/setup-lxc-template \
+ "$pkgdir"/usr/bin/setup-lxc-template
install -Dm755 "$srcdir"/setup-lxc-guest "$pkgdir"/usr/bin/setup-lxc-guest
+ set +e
}
md5sums="7304fa57146ce687f749b5df876bb20d lxc-0.8.0.tar.gz
diff --git a/main/lxc/lxc-alpine b/main/lxc/lxc-alpine
new file mode 100755
index 000000000..a9b1de2f1
--- /dev/null
+++ b/main/lxc/lxc-alpine
@@ -0,0 +1,190 @@
+#!/bin/sh
+
+install_alpine() {
+ rootfs="$1"
+ mkdir -p "$rootfs"/etc/apk || return 1
+ cp -r ${keys_dir:-/etc/apk/keys} "$rootfs"/etc/apk/
+ if [ -n "$repository" ]; then
+ echo "$repository" > "$rootfs"/etc/apk/repositories
+ else
+ cp /etc/apk/repositories "$rootfs"/etc/apk/repositories || return 1
+ fi
+ ${APK:-apk} add -U --initdb --root $rootfs alpine-base
+}
+
+configure_alpine() {
+ rootfs="$1"
+ echo "Setting up /etc/inittab"
+ cat >"$rootfs"/etc/inittab<<EOF
+::sysinit:/sbin/rc sysinit
+::wait:/sbin/rc default
+tty1:12345:respawn:/sbin/getty 38400 tty1
+::ctrlaltdel:/sbin/reboot
+::shutdown:/sbin/rc shutdown
+EOF
+ # set up nameserver
+ grep nameserver /etc/resolv.conf > "$rootfs/etc/resolv.conf"
+
+ # configure the network using the dhcp
+ # note that lxc will set up lo interface
+ cat <<EOF > $rootfs/etc/network/interfaces
+#auto lo
+iface lo inet loopback
+
+auto eth0
+iface eth0 inet dhcp
+EOF
+
+ # set the hostname
+ echo $hostname > $rootfs/etc/hostname
+
+ # missing device nodes
+ echo "Setting up device nodes"
+ mkdir -p -m 755 "$rootfs/dev/pts"
+ mkdir -p -m 1777 "$rootfs/dev/shm"
+ mknod -m 666 "$rootfs/dev/full" c 1 7
+ mknod -m 666 "$rootfs/dev/random" c 1 8
+ mknod -m 666 "$rootfs/dev/urandom" c 1 9
+ mknod -m 666 "$rootfs/dev/tty0" c 4 0
+ mknod -m 666 "$rootfs/dev/tty1" c 4 1
+ mknod -m 666 "$rootfs/dev/tty2" c 4 2
+ mknod -m 666 "$rootfs/dev/tty3" c 4 3
+ mknod -m 666 "$rootfs/dev/tty4" c 4 4
+# mknod -m 600 "$rootfs/dev/initctl" p
+ mknod -m 666 "$rootfs/dev/tty" c 5 0
+ mknod -m 666 "$rootfs/dev/console" c 5 1
+ mknod -m 666 "$rootfs/dev/ptmx" c 5 2
+
+ # start services
+ ln -s /etc/init.d/syslog "$rootfs"/etc/runlevels/default/syslog
+
+ return 0
+}
+
+copy_configuration() {
+ path=$1
+ rootfs=$2
+ hostname=$3
+
+ grep -q "^lxc.rootfs" $path/config 2>/dev/null \
+ || echo "lxc.rootfs = $rootfs" >> $path/config
+ cat <<EOF >> $path/config
+lxc.tty = 4
+lxc.pts = 1024
+lxc.utsname = $hostname
+
+# When using LXC with apparmor, uncomment the next line to run unconfined:
+#lxc.aa_profile = unconfined
+
+# network interface
+lxc.network.name = eth0
+lxc.network.type = veth
+lxc.network.flags = up
+# enable for bridging
+#lxc.network.link = br0
+#lxc.network.ipv4 = n.n.n.n
+#lxc.network.ipv4.gateway = auto
+
+# devices
+lxc.cgroup.devices.deny = a
+# /dev/null and zero
+lxc.cgroup.devices.allow = c 1:3 rwm
+lxc.cgroup.devices.allow = c 1:5 rwm
+# consoles
+lxc.cgroup.devices.allow = c 5:1 rwm
+lxc.cgroup.devices.allow = c 5:0 rwm
+lxc.cgroup.devices.allow = c 4:0 rwm
+lxc.cgroup.devices.allow = c 4:1 rwm
+# /dev/{,u}random
+lxc.cgroup.devices.allow = c 1:9 rwm
+lxc.cgroup.devices.allow = c 1:8 rwm
+lxc.cgroup.devices.allow = c 136:* rwm
+lxc.cgroup.devices.allow = c 5:2 rwm
+# rtc
+lxc.cgroup.devices.allow = c 254:0 rwm
+
+# mounts point
+lxc.mount.entry=proc proc proc nodev,noexec,nosuid 0 0
+lxc.mount.entry=run run tmpfs nodev,noexec,nosuid,relatime,size=1m,mode=0755 0 0
+lxc.mount.entry=none dev/pts devpts gid=5,mode=620 0 0
+
+EOF
+
+ return 0
+}
+
+die() {
+ echo "$@" >&2
+ exit 1
+}
+
+usage() {
+ echo "Usage: $(basename $0) [-h|--help] -p|--path <path> -n|--name <name>" >&2
+}
+
+usage_err() {
+ usage
+ exit 1
+}
+
+optarg_check() {
+ if [ -z "$2" ]; then
+ usage_err "option '$1' requires an argument"
+ fi
+}
+
+default_path=/var/lib/lxc
+
+while [ $# -gt 0 ]; do
+ opt="$1"
+ shift
+ case "$opt" in
+ -h|--help)
+ usage
+ exit 0
+ ;;
+ -n|--name)
+ optarg_check $opt "$1"
+ name=$1
+ shift
+ ;;
+ -p|--path)
+ optarg_check $opt "$1"
+ path=$1
+ shift
+ ;;
+ --)
+ break;;
+ --*=*)
+ # split --myopt=foo=bar into --myopt foo=bar
+ set -- ${opt%=*} ${opt#*=} "$@"
+ ;;
+ -?)
+ usage_err "unknown option '$opt'"
+ ;;
+ -*)
+ # split opts -abc into -a -b -c
+ set -- $(echo "${opt#-}" | sed 's/\(.\)/ -\1/g') "$@"
+ ;;
+ *)
+ usage
+ exit 1
+ ;;
+ esac
+done
+
+
+[ -z "$name" ] && usage_err
+
+if [ -z "${path}" ]; then
+ path="${default_path}/${name}"
+fi
+
+rootfs=`awk -F= '$1 ~ /^lxc.rootfs/ { print $2 }' "$path/config" 2>/dev/null`
+if [ -z "$rootfs" ]; then
+ rootfs="${path}/rootfs"
+fi
+
+install_alpine "$rootfs" || die "Failed to install rootfs for $name"
+configure_alpine "$rootfs" "$name" || die "Failed to configure $name"
+copy_configuration "$path" "$rootfs" "$name"