From: dlezcano Date: Fri, 28 Nov 2008 15:36:51 +0000 (+0000) Subject: Added a script directory for containers creation helper scripts X-Git-Tag: lxc_0_5_0~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c9844b873338581bb261aaaeecbb7574ac98af87;p=thirdparty%2Flxc.git Added a script directory for containers creation helper scripts From: Daniel Lezcano Added a directory called 'scripts' where is stored two helpers. The first one allows to create a mini debian container and the second one to create a sshd container. Signed-off-by: Daniel Lezcano --- diff --git a/Makefile.am b/Makefile.am index e35838a44..688fa8dc0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,7 @@ # Makefile.am -SUBDIRS = doc src test etc -DIST_SUBDIRS = config doc src test etc +SUBDIRS = doc src test etc scripts +DIST_SUBDIRS = config doc src test etc scripts EXTRA_DIST = lxc.spec CONTRIBUTING MAINTAINERS ChangeLog ChangeLog:: diff --git a/configure.in b/configure.in index 311f992de..0b65e3482 100644 --- a/configure.in +++ b/configure.in @@ -63,13 +63,17 @@ AC_CONFIG_FILES([ doc/lxc.conf.sgml doc/lxc.sgml + scripts/Makefile + scripts/lxc-debian + scripts/lxc-sshd + src/Makefile src/lxc/Makefile src/lxc/lxc-ps src/lxc/lxc-ls src/lxc/lxc-netstat - src/lxc/lxc-debian src/lxc/lxc-checkconfig + etc/Makefile etc/lxc-macvlan.conf etc/lxc-no-netns.conf @@ -77,6 +81,7 @@ AC_CONFIG_FILES([ etc/lxc-phys.conf etc/lxc-veth.conf etc/lxc-complex-config + test/Makefile ]) AC_CONFIG_COMMANDS([default],[[]],[[]]) diff --git a/scripts/lxc-sshd.in b/scripts/lxc-sshd.in new file mode 100755 index 000000000..f79489bfa --- /dev/null +++ b/scripts/lxc-sshd.in @@ -0,0 +1,480 @@ +#!/bin/bash + +ascii_tarball() { +cat < $CONFFILE +lxc.utsname = $UTSNAME +lxc.network.type = veth +lxc.network.flags = up +lxc.network.link = br0 +lxc.network.ipv4 = $IPV4 +lxc.network.name = eth0 +lxc.mount = $FSTABFILE +lxc.rootfs = $ROOTFS +EOF + +cat < $FSTABFILE +/lib $(pwd)/$ROOTFS/lib none ro,bind 0 0 +/bin $(pwd)/$ROOTFS/bin none ro,bind 0 0 +/usr $(pwd)/$ROOTFS/usr none ro,bind 0 0 +/sbin $(pwd)/$ROOTFS/sbin none ro,bind 0 0 +EOF + +if [ "$(arch)" = "x86_64" ]; then +cat <> $FSTABFILE +/lib64 $(pwd)/$ROOTFS/lib64 none ro,bind 0 0 +EOF +fi + + lxc-create -n $NAME -f $CONFFILE + + rm -f $FSTABFILE + rm -f $CONFFILE + + echo "Done." + echo -e "\nYou can run your container with: \n\t\ +'lxc-execute -n $NAME /usr/sbin/sshd &'\n" +} + +destroy() { + + echo -n "What is the container name ? [$NAME] " + read _NAME_ + + if [ ! -z "$_NAME_" ]; then + NAME=$_NAME_ + fi + + ROOTFS="./rootfs.$NAME" + + echo -n "Shall I remove the rootfs [y/n] ? " + read + if [ "$REPLY" = "y" ]; then + rm -rf $ROOTFS + fi + + lxc-destroy -n $NAME +} + +help() { +cat </var/lock/subsys/lxc - fi - - -######################################## -# lxc configuration files -######################################## - -# lxc mount point - -cat < $MNTFILE -/dev $(pwd)/$ROOTFS/dev none bind 0 0 -/dev/pts $(pwd)/$ROOTFS/dev/pts none bind 0 0 -/etc/resolv.conf $(pwd)/$ROOTFS/etc/resolv.conf none ro,bind 0 0 -EOF - -# lxc configuration - -cat < $CONFFILE -lxc.utsname = $UTSNAME -lxc.network.type = veth -lxc.network.flags = up -lxc.network.link = br0 -lxc.network.name = eth0 -lxc.mount = $MNTFILE -lxc.rootfs = $ROOTFS -EOF - - -######################################## -# rootfs configuration files tweak -######################################## - -# inittab - -cat < $ROOTFS/$INITTAB -id:3:initdefault: -si::sysinit:/etc/init.d/rcS -l0:0:wait:/etc/init.d/rc 0 -l1:1:wait:/etc/init.d/rc 1 -l2:2:wait:/etc/init.d/rc 2 -l3:3:wait:/etc/init.d/rc 3 -l4:4:wait:/etc/init.d/rc 4 -l5:5:wait:/etc/init.d/rc 5 -l6:6:wait:/etc/init.d/rc 6 -# Normally not reached, but fallthrough in case of emergency. -z6:6:respawn:/sbin/sulogin -1:2345:respawn:/sbin/getty 38400 console -EOF - -# hostname -cat < $ROOTFS/$HOSTNAME -$UTSNAME -EOF - -# fstab - -cat < $ROOTFS/$FSTAB -tmpfs /dev/shm tmpfs defaults 0 0 -EOF - -# network - -cat < $ROOTFS/$INTERFACES -auto eth0 lo -iface eth0 inet static -address $IPV4 -netmask 255.255.255.0 -broadcast 0.0.0.0 -up route add default gw $GATEWAY -iface lo inet loopback -EOF - -# create the container object - -lxc-create -n $NAME -f $CONFFILE - -# remove the configuration files - -rm -f $CONFFILE -rm -f $MNTFILE - -echo "Done." -echo -e "\nYou can run your container with the 'lxc-start -n $NAME'\n" -} - -destroy() { - - echo -n "What is the name for the container ? [$NAME] " - read _NAME_ - - if [ ! -z "$_NAME_" ]; then - NAME=$_NAME_ - fi - - lxc-destroy -n $NAME - RETVAL=$? - if [ ! $RETVAL -eq 0 ]; then - echo "Failed to destroyed '$NAME'" - return $RETVAL; - fi - - ROOTFS="./rootfs.$NAME" - - echo -n "Shall I remove the rootfs [y/n] ? " - read - if [ "$REPLY" = "y" ]; then - rm -rf $ROOTFS - fi - - return 0 -} - -help() { - cat </var/lock/subsys/lxc -} - -if [ "$(id -u)" != "0" ]; then - echo "This script should be run as 'root'" - exit 1 -fi - -case "$1" in - create) - create;; - destroy) - destroy;; - help) - help;; - purge) - purge;; - *) - echo "Usage: $0 {create|destroy|purge|help}" - exit 1;; -esac