Re: [Lxc-users] [lxc-devel] template-script for ubuntu [lucid] containers

2010-06-01 Thread Wilhelm

Am 01.06.2010 16:06, schrieb Daniel Lezcano:

On 06/01/2010 06:04 PM, Daniel Lezcano wrote:

On 05/30/2010 07:07 PM, Wilhelm wrote:

Hi,

for all interested: attached you'll find a template script for ubuntu
containers.


Hi Willem,

thanks a lot for the script, I fixed some nasty things but I was happy
to play with it :)

Do you mind to modify the script in order to have '/var/tmp' not being


sorry, I meant '/var/run'


ok, changed it in the attached script (and added the patches you posted 
and some other tweaks)




mounted as a tmpfs, so the mechanism within lxc can 'shutdown' /
'reboot' properly ?
but a halt from inside the container isn't handled properly: the 
init-process still remains ...

Any ideas?


Thanks
-- Daniel



--
Wilhelm

#!/bin/bash

#
# template script for generating ubuntu/lucid container for LXC
#
# This script is based on lxc-debian (Daniel Lezcano daniel.lezc...@free.fr)
#

# Copyright © 2010 Wilhelm Meier
# Author: Wilhelm Meier wilhelm.me...@fh-kl.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2, as
# published by the Free Software Foundation.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

configure_ubuntu()
{
rootfs=$1
hostname=$2

# disable selinux in ubuntu
mkdir -p $rootfs/selinux
echo 0  $rootfs/selinux/enforce

   # configure the network using the dhcp
cat EOF  $rootfs/etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp
EOF

# set the hostname
cat EOF  $rootfs/etc/hostname
$hostname
EOF
# set minimal hosts
cat EOF  $rootfs/etc/hosts
127.0.0.1 localhost $hostname
EOF

# provide the lxc service 
cat EOF  $rootfs/etc/init/lxc.conf
# fake some events needed for correct startup other services

description Container Upstart

start on startup

script
rm -rf /var/run/*.pid
rm -rf /var/run/network/*
/sbin/initctl emit stopped JOB=udevtrigger --no-wait
/sbin/initctl emit started JOB=udev --no-wait
end script
EOF

cat EOF  $rootfs/lib/init/fstab
# /lib/init/fstab: lxc system fstab
none/spu  spufs   gid=spu,optional  
0 0
none/tmp  nonedefaults  
0 0
#none/var/run  tmpfs   
mode=0755,nosuid,showthrough  0 0
none/var/lock tmpfs   
nodev,noexec,nosuid,showthrough   0 0
none/lib/init/rw  tmpfs   
mode=0755,nosuid,optional 0 0
EOF

# reconfigure some services
if [ -z $LANG ]; then
chroot $rootfs locale-gen en_US.UTF-8
chroot $rootfs update-locale LANG=en_US.UTF-8
else
chroot $rootfs locale-gen $LANG
chroot $rootfs update-locale LANG=$LANG
fi

# remove pointless services in a container
chroot $rootfs /usr/sbin/update-rc.d -f ondemand remove

chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls u*.conf); do mv $f 
$f.orig; done'
chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls tty[2-9].conf); do 
mv $f $f.orig; done'
chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls plymouth*.conf); 
do mv $f $f.orig; done'
chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls hwclock*.conf); do 
mv $f $f.orig; done'
chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls module*.conf); do 
mv $f $f.orig; done'

echo Please change root-password !
echo root:root | chroot $rootfs chpasswd

return 0
}

download_ubuntu()
{

packages=dialog,apt,apt-utils,resolvconf,iproute,inetutils-ping,vim,dhcp3-client,ssh,lsb-release

cache=$1
arch=$2

# check the mini ubuntu was not already downloaded
mkdir -p $cache/partial-$arch
if [ $? -ne 0 ]; then
echo Failed to create '$cache/partial-$arch' directory
return 1
fi

# download a mini ubuntu into a cache
echo Downloading ubuntu minimal ...
debootstrap --verbose --variant=minbase --components=main,universe 
--arch=$arch --include=$packages lucid $cache/partial-$arch
if [ $? -ne 0 ]; then
echo Failed to download the rootfs, aborting.
return 1
fi

mv $1/partial-$arch $1/rootfs-$arch
echo Download complete.

return 0
}

copy_ubuntu()
{
cache=$1
arch=$2
rootfs=$3

# make a local copy of the miniubuntu
echo -n Copying rootfs to $rootfs ...
cp -a $cache/rootfs-$arch $rootfs || return 1
return 

Re: [Lxc-users] [lxc-devel] template-script for ubuntu [lucid] containers

2010-06-01 Thread Daniel Lezcano
On 06/01/2010 09:50 PM, Wilhelm wrote:
 Am 01.06.2010 16:06, schrieb Daniel Lezcano:
 On 06/01/2010 06:04 PM, Daniel Lezcano wrote:
 On 05/30/2010 07:07 PM, Wilhelm wrote:
 Hi,

 for all interested: attached you'll find a template script for ubuntu
 containers.

 Hi Willem,

 thanks a lot for the script, I fixed some nasty things but I was happy
 to play with it :)

 Do you mind to modify the script in order to have '/var/tmp' not being

 sorry, I meant '/var/run'

 ok, changed it in the attached script (and added the patches you 
 posted and some other tweaks)


 mounted as a tmpfs, so the mechanism within lxc can 'shutdown' /
 'reboot' properly ?
 but a halt from inside the container isn't handled properly: the 
 init-process still remains ...
 Any ideas?

I added a mechanism to watch the utmp file in the container's rootfs in lxc.
This is not available for lxc 0.6.5, do you have this version ?


--

___
Lxc-users mailing list
Lxc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-users


Re: [Lxc-users] [lxc-devel] template-script for ubuntu [lucid] containers

2010-06-01 Thread Wilhelm
Am 01.06.2010 20:05, schrieb Daniel Lezcano:
 On 06/01/2010 09:50 PM, Wilhelm wrote:
 Am 01.06.2010 16:06, schrieb Daniel Lezcano:
 On 06/01/2010 06:04 PM, Daniel Lezcano wrote:
 On 05/30/2010 07:07 PM, Wilhelm wrote:
 Hi,

 for all interested: attached you'll find a template script for ubuntu
 containers.

 Hi Willem,

 thanks a lot for the script, I fixed some nasty things but I was happy
 to play with it :)

 Do you mind to modify the script in order to have '/var/tmp' not being

 sorry, I meant '/var/run'

 ok, changed it in the attached script (and added the patches you 
 posted and some other tweaks)


 mounted as a tmpfs, so the mechanism within lxc can 'shutdown' /
 'reboot' properly ?
 but a halt from inside the container isn't handled properly: the 
 init-process still remains ...
 Any ideas?

 I added a mechanism to watch the utmp file in the container's rootfs 
 in lxc.
 This is not available for lxc 0.6.5, do you have this version ?

No, I used latest git.

-- 
Wilhelm



--

___
Lxc-users mailing list
Lxc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-users


Re: [Lxc-users] [lxc-devel] template-script for ubuntu [lucid] containers

2010-06-01 Thread Wilhelm
Am 01.06.2010 20:05, schrieb Daniel Lezcano:
 On 06/01/2010 09:50 PM, Wilhelm wrote:
 Am 01.06.2010 16:06, schrieb Daniel Lezcano:
 On 06/01/2010 06:04 PM, Daniel Lezcano wrote:
 On 05/30/2010 07:07 PM, Wilhelm wrote:
 Hi,

 for all interested: attached you'll find a template script for ubuntu
 containers.

 Hi Willem,

 thanks a lot for the script, I fixed some nasty things but I was happy
 to play with it :)

 Do you mind to modify the script in order to have '/var/tmp' not being

 sorry, I meant '/var/run'

 ok, changed it in the attached script (and added the patches you 
 posted and some other tweaks)


 mounted as a tmpfs, so the mechanism within lxc can 'shutdown' /
 'reboot' properly ?
 but a halt from inside the container isn't handled properly: the 
 init-process still remains ...
 Any ideas?

 I added a mechanism to watch the utmp file in the container's rootfs 
 in lxc.
 This is not available for lxc 0.6.5, do you have this version ?

latest git and here ist the log with issuing halt insige the container:

r...@ubuntu01:~# lxc-start -n test2 --logfile=/dev/stderr 
--logpriority=TRACE
   lxc-start 1275423291.064 DEBUGlxc_conf - allocated pty 
'/dev/pts/1' (4/5)
   lxc-start 1275423291.065 DEBUGlxc_conf - allocated pty 
'/dev/pts/2' (6/7)
   lxc-start 1275423291.065 DEBUGlxc_conf - allocated pty 
'/dev/pts/3' (8/9)
   lxc-start 1275423291.065 DEBUGlxc_conf - allocated pty 
'/dev/pts/4' (10/11)
   lxc-start 1275423291.065 INFO lxc_conf - tty's configured
   lxc-start 1275423291.066 DEBUGlxc_start - sigchild handler set
   lxc-start 1275423291.066 INFO lxc_start - 'test2' is initialized
   lxc-start 1275423291.076 DEBUGlxc_conf - instanciated macvlan 
'mcPR3qjD', index is '8' and mode '2'
   lxc-start 1275423291.089 DEBUGlxc_cgroup - using cgroup 
mounted at '/lxc-cgroup'
   lxc-start 1275423291.089 DEBUGlxc_cgroup - '/lxc-cgroup/4052' 
renamed to '/lxc-cgroup/test2'
   lxc-start 1275423291.092 DEBUGlxc_conf - move 'eth0' to '4052'
   lxc-start 1275423291.092 INFO lxc_conf - 'test2' hostname has 
been setup
   lxc-start 1275423291.094 DEBUGlxc_conf - mac address 
'4a:49:43:49:79:03' on 'eth0' has been setup
   lxc-start 1275423291.095 DEBUGlxc_conf - 'eth0' has been setup
   lxc-start 1275423291.095 INFO lxc_conf - network has been setup
   lxc-start 1275423291.099 DEBUGlxc_cgroup - using cgroup 
mounted at '/lxc-cgroup'
   lxc-start 1275423291.105 DEBUGlxc_conf - cgroup 
'devices.deny' set to 'a'
   lxc-start 1275423291.105 DEBUGlxc_conf - cgroup 
'devices.allow' set to 'c 1:3 rwm'
   lxc-start 1275423291.105 DEBUGlxc_conf - cgroup 
'devices.allow' set to 'c 1:5 rwm'
   lxc-start 1275423291.105 DEBUGlxc_conf - cgroup 
'devices.allow' set to 'c 5:1 rwm'
   lxc-start 1275423291.105 DEBUGlxc_conf - cgroup 
'devices.allow' set to 'c 5:0 rwm'
   lxc-start 1275423291.105 DEBUGlxc_conf - cgroup 
'devices.allow' set to 'c 4:0 rwm'
   lxc-start 1275423291.105 DEBUGlxc_conf - cgroup 
'devices.allow' set to 'c 4:1 rwm'
   lxc-start 1275423291.105 DEBUGlxc_conf - cgroup 
'devices.allow' set to 'c 1:9 rwm'
   lxc-start 1275423291.105 DEBUGlxc_conf - cgroup 
'devices.allow' set to 'c 1:8 rwm'
   lxc-start 1275423291.105 DEBUGlxc_conf - cgroup 
'devices.allow' set to 'c 136:* rwm'
   lxc-start 1275423291.105 DEBUGlxc_conf - cgroup 
'devices.allow' set to 'c 5:2 rwm'
   lxc-start 1275423291.105 DEBUGlxc_conf - cgroup 
'devices.allow' set to 'c 254:0 rwm'
   lxc-start 1275423291.105 INFO lxc_conf - cgroup has been setup
   lxc-start 1275423291.106 DEBUGlxc_conf - mounted proc on 
/usr/local/var/lib/lxc/test2/rootfs/proc, type proc
   lxc-start 1275423291.106 DEBUGlxc_conf - mounted devpts on 
/usr/local/var/lib/lxc/test2/rootfs/dev/pts, type devpts
   lxc-start 1275423291.107 DEBUGlxc_conf - mounted sysfs on 
/usr/local/var/lib/lxc/test2/rootfs/sys, type sysfs
   lxc-start 1275423291.107 INFO lxc_conf - mount points have 
been setup
   lxc-start 1275423291.110 INFO lxc_conf - mount points have 
been setup
   lxc-start 1275423291.110 INFO lxc_conf - no console output 
required
   lxc-start 1275423291.110 INFO lxc_conf - 4 tty(s) has been setup
   lxc-start 1275423291.111 DEBUGlxc_conf - mounted 
'/usr/local/var/lib/lxc/test2/rootfs' on '/usr/local/lib/lxc/rootfs'
   lxc-start 1275423291.111 DEBUGlxc_conf - created 
'/usr/local/lib/lxc/rootfs/oldrootfs' directory
   lxc-start 1275423291.111 DEBUGlxc_conf - mountpoint for old 
rootfs is '/usr/local/lib/lxc/rootfs/oldrootfs'
   lxc-start 1275423291.116 DEBUGlxc_conf - pivot_root syscall 
to '/usr/local/lib/lxc/rootfs' successful
   lxc-start 1275423291.117 DEBUGlxc_conf - umounted 
'/oldrootfs/dev/pts'
   lxc-start 1275423291.117 DEBUG

Re: [Lxc-users] [lxc-devel] template-script for ubuntu [lucid] containers

2010-06-01 Thread Daniel Lezcano
On 06/01/2010 10:12 PM, Wilhelm wrote:
 Am 01.06.2010 20:05, schrieb Daniel Lezcano:
 On 06/01/2010 09:50 PM, Wilhelm wrote:
 Am 01.06.2010 16:06, schrieb Daniel Lezcano:
 On 06/01/2010 06:04 PM, Daniel Lezcano wrote:
 On 05/30/2010 07:07 PM, Wilhelm wrote:
 Hi,

 for all interested: attached you'll find a template script for 
 ubuntu
 containers.

 Hi Willem,

 thanks a lot for the script, I fixed some nasty things but I was 
 happy
 to play with it :)

 Do you mind to modify the script in order to have '/var/tmp' not 
 being

 sorry, I meant '/var/run'

 ok, changed it in the attached script (and added the patches you 
 posted and some other tweaks)


 mounted as a tmpfs, so the mechanism within lxc can 'shutdown' /
 'reboot' properly ?
 but a halt from inside the container isn't handled properly: the 
 init-process still remains ...
 Any ideas?

 I added a mechanism to watch the utmp file in the container's rootfs 
 in lxc.
 This is not available for lxc 0.6.5, do you have this version ?

 No, I used latest git.

Ok, I suppose something is missing somewhere, will try to have a look at 
that tomorrow.

Thanks
   -- Daniel

--

___
Lxc-users mailing list
Lxc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-users


Re: [Lxc-users] [lxc-devel] template-script for ubuntu [lucid] containers

2010-05-30 Thread Wilhelm

Am 30.05.2010 20:19, schrieb Michel Normand:

On 30/05/2010 19:07, Wilhelm wrote:

Hi,

for all interested: attached you'll find a template script for ubuntu
containers.


interesting attachment.
could we take it in lxc as a new template exemple
in scripts/lxc-ubuntu.in ?


Sure!

Attached I have the polished version with GPL, author and based-on ...
Please feel free to include it into LXC.


It will need few adaptations using some @xxx@ but easy to change.


ok.

--
Wilhelm


#!/bin/bash

# 
# template script for generating ubuntu/lucid container for LXC
#
# This script is based on lxc-debian (Daniel Lezcano daniel.lezc...@free.fr)
#

# Copyright © 2010 Wilhelm Meier
# Author: Wilhelm Meier wilhelm.me...@fh-kl.de 
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2, as
# published by the Free Software Foundation.
 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

configure_ubuntu()
{
rootfs=$1
hostname=$2

# disable selinux in ubuntu
mkdir -p $rootfs/selinux
echo 0  $rootfs/selinux/enforce

   # configure the network using the dhcp
cat EOF  $rootfs/etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp
EOF

# set the hostname
cat EOF  $rootfs/etc/hostname
$hostname
EOF
# set minimal hosts
cat EOF  $rootfs/etc/hosts
127.0.0.1 localhost $hostname
EOF

# provide the lxc service 
cat EOF  $rootfs/etc/init/lxc.conf
# fake some events needed for correct startup other services

description Container Upstart

start on startup

script
rm -rf /var/run/*
/sbin/initctl emit stopped JOB=udevtrigger
/sbin/initctl emit started JOB=udev
end script
EOF

cat EOF  $rootfs/lib/init/fstab
# /lib/init/fstab: lxc system fstab
none/spu  spufs   gid=spu,optional  
0 0
none/tmp  nonedefaults  
0 0
none/var/run  tmpfs   
mode=0755,nosuid,showthrough  0 0
none/var/lock tmpfs   
nodev,noexec,nosuid,showthrough   0 0
none/lib/init/rw  tmpfs   
mode=0755,nosuid,optional 0 0
EOF

# reconfigure some services
chroot $rootfs locale-gen de_DE.UTF-8

# remove pointless services in a container
chroot $rootfs /usr/sbin/update-rc.d -f ondemand remove

chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls u*.conf); do echo 
$f; mv $f $f.orig; done'
chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls tty[2-9].conf); do 
echo $f; mv $f $f.orig; done'
chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls plymouth*.conf); 
do echo $f; mv $f $f.orig; done'
chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls hwclock*.conf); do 
echo $f; mv $f $f.orig; done'
chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls module*.conf); do 
echo $f; mv $f $f.orig; done'

echo Please change root-password !

echo root:root | chroot /usr/local/var/lib/lxc/test/rootfs chpasswd
}

download_ubuntu()
{

packages=dialog,apt,resolvconf,iproute,inetutils-ping,vim,dhcp3-client,ssh,lsb-release

cache=$1
arch=$2

# check the mini ubuntu was not already downloaded
mkdir -p $cache/partial-$arch
if [ $? -ne 0 ]; then
echo Failed to create '$cache/partial-$arch' directory
return 1
fi

# download a mini ubuntu into a cache
echo Downloading ubuntu minimal ...
debootstrap --verbose --variant=minbase --components=main,universe 
--arch=$arch --include=$packages lucid $cache/partial-$arch
if [ $? -ne 0 ]; then
echo Failed to download the rootfs, aborting.
return 1
fi

mv $1/partial-$arch $1/rootfs-$arch
echo Download complete.

return 0
}

copy_ubuntu()
{
cache=$1
arch=$2
rootfs=$3

# make a local copy of the miniubuntu
echo -n Copying rootfs to $rootfs ...
cp -a $cache/rootfs-$arch $rootfs || return 1
return 0
}

install_ubuntu()
{
cache=/var/cache/lxc/ubuntu
rootfs=$1
mkdir -p /var/lock/subsys/
(
flock -n -x 200
if [ $? -ne 0 ]; then
echo Cache repository is busy.
return 1
fi

arch=$(arch)
if [ $arch == x86_64 ]; then
arch=amd64
fi

if [ $arch == i686 ]; then
arch=i386
fi

echo Checking cache download in $cache/rootfs-$arch ...