From 7c3e5ed0552d30f9be052b55d6e6a98b9b45682a Mon Sep 17 00:00:00 2001 From: Anthony Young Date: Tue, 13 Sep 2011 09:57:31 -0700 Subject: [PATCH] more lxc cleanup - better stack user configuration --- build_lxc.sh | 51 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/build_lxc.sh b/build_lxc.sh index 628ac85..d3dd7ad 100755 --- a/build_lxc.sh +++ b/build_lxc.sh @@ -12,13 +12,12 @@ WARMCACHE=${WARMCACHE:-0} # Shutdown any existing container lxc-stop -n $CONTAINER -sleep 1 + # This prevents zombie containers cgdelete -r cpu,net_cls:$CONTAINER -sleep 1 + # Destroy the old container lxc-destroy -n $CONTAINER -sleep 1 # Warm the base image on first run or when WARMCACHE=1 CACHEDIR=/var/cache/lxc/natty/rootfs-amd64 @@ -42,13 +41,27 @@ lxc.network.ipv4 = $CONTAINER_CIDR lxc.cgroup.devices.allow = c 10:200 rwm EOF -# Configure the network +# Create the container lxc-create -n $CONTAINER -t natty -f $LXC_CONF -sleep 2 -# Where our container lives +# Specify where our container lives ROOTFS=/var/lib/lxc/$CONTAINER/rootfs/ +# set root password to password +echo root:pass | chroot $ROOTFS chpasswd + +# Create a stack user that is a member of the libvirtd group so that stack +# is able to interact with libvirt. +chroot $ROOTFS groupadd libvirtd +chroot $ROOTFS useradd stack -s /bin/bash -d /opt -G libvirtd + +# a simple password - pass +echo stack:pass | chroot $ROOTFS chpasswd + +# and has sudo ability (in the future this should be limited to only what +# stack requires) +echo "stack ALL=(ALL) NOPASSWD: ALL" >> $ROOTFS/etc/sudoers + # Copy over your ssh keys and env if desired if [ "$COPYENV" = "1" ]; then cp -pr ~/.ssh $ROOTFS/root/.ssh @@ -56,8 +69,17 @@ if [ "$COPYENV" = "1" ]; then cp -pr ~/.gitconfig $ROOTFS/root/.gitconfig cp -pr ~/.vimrc $ROOTFS/root/.vimrc cp -pr ~/.bashrc $ROOTFS/root/.bashrc + + cp -pr ~/.ssh $ROOTFS/opt/.ssh + cp -p ~/.ssh/id_rsa.pub $ROOTFS/opt/.ssh/authorized_keys + cp -pr ~/.gitconfig $ROOTFS/opt/.gitconfig + cp -pr ~/.vimrc $ROOTFS/opt/.vimrc + cp -pr ~/.bashrc $ROOTFS/opt/.bashrc fi +# give stack ownership over /opt so it may do the work needed +chroot $ROOTFS chown -R stack /opt + # Configure instance network INTERFACES=$ROOTFS/etc/network/interfaces cat > $INTERFACES < $INSTALL_SH < /etc/rc.local +# Make sure dns is set up echo "nameserver $NAMESERVER" | resolvconf -a eth0 sleep 1 -# Create a stack user that is a member of the libvirtd group so that stack -# is able to interact with libvirt. -groupadd libvirtd -useradd stack -s /bin/bash -d /opt -G libvirtd - -# a simple password - pass -echo stack:pass | chpasswd - -# give stack ownership over /opt so it may do the work needed -chown -R stack /opt - -# and has sudo ability (in the future this should be limited to only what -# stack requires) - -echo "stack ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers # Install and run stack.sh apt-get update