/[pxelator]/lib/PXElator/lxc.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /lib/PXElator/lxc.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 436 - (show annotations)
Sun Sep 20 15:10:31 2009 UTC (14 years, 7 months ago) by dpavlin
File size: 1616 byte(s)
create Linux container using lxc
1 package lxc;
2
3 use warnings;
4 use strict;
5 use autodie;
6
7 use file;
8
9 use Data::Dump qw/dump/;
10
11 sub create {
12 my ( $hostname, $ip, $path ) = @_;
13
14 file::append "$path/etc/initab" => $_ foreach qw(
15 z6:6:respawn:/sbin/sulogin
16 1:2345:respawn:/sbin/getty 38400 console
17 c1:12345:respawn:/sbin/getty 38400 tty1 linux
18 c2:12345:respawn:/sbin/getty 38400 tty2 linux
19 c3:12345:respawn:/sbin/getty 38400 tty3 linux
20 c4:12345:respawn:/sbin/getty 38400 tty4 linux
21 );
22
23 file::append '/etc/fstab' => 'cgroup /cgroup cgroup rw 0 0' && mkdir '/cgroup';
24 system "mount /cgroup";
25
26 system "lxc-stop -n $hostname";
27 system "lxc-destroy -n $hostname";
28
29 file::replace "$path/etc/hostname" => $hostname;
30 file::append "$path/hosts" => "$ip $hostname";
31
32 my $conf = "/virtual/$hostname.conf";
33
34 file::replace $conf => qq|
35 lxc.utsname = $hostname
36 lxc.tty = 4
37 lxc.pts = 1024
38 lxc.network.type = veth
39 lxc.network.flags = up
40 lxc.network.link = br0
41 lxc.network.name = eth0
42 lxc.network.mtu = 1500
43 #lxc.mount = MNTFILE
44 lxc.rootfs = $path
45 lxc.cgroup.devices.deny = a
46 # /dev/null and zero
47 lxc.cgroup.devices.allow = c 1:3 rwm
48 lxc.cgroup.devices.allow = c 1:5 rwm
49 # consoles
50 lxc.cgroup.devices.allow = c 5:1 rwm
51 lxc.cgroup.devices.allow = c 5:0 rwm
52 lxc.cgroup.devices.allow = c 4:0 rwm
53 lxc.cgroup.devices.allow = c 4:1 rwm
54 # /dev/{,u}random
55 lxc.cgroup.devices.allow = c 1:9 rwm
56 lxc.cgroup.devices.allow = c 1:8 rwm
57 lxc.cgroup.devices.allow = c 136:* rwm
58 lxc.cgroup.devices.allow = c 5:2 rwm
59 # rtc
60 lxc.cgroup.devices.allow = c 254:0 rwm
61 |;
62
63 system "lxc-create -n $hostname -f $conf";
64
65 warn "created $hostname $ip $path";
66 }
67
68 warn 'loaded';
69
70 1;

  ViewVC Help
Powered by ViewVC 1.1.26