use Data::Dump qw/dump/;
sub create {
- my ( $hostname, $ip, $path ) = @_;
+ my ( $hostname, $path, $ip, $netmask, $server_ip ) = @_;
- file::append "$path/etc/initab" => $_ foreach qw(
+ die "$path: $!" unless -d $path;
+
+ file::append "$path/etc/initab" => "$_\n" foreach split(/\n/, qq|
z6:6:respawn:/sbin/sulogin
1:2345:respawn:/sbin/getty 38400 console
c1:12345:respawn:/sbin/getty 38400 tty1 linux
c2:12345:respawn:/sbin/getty 38400 tty2 linux
c3:12345:respawn:/sbin/getty 38400 tty3 linux
c4:12345:respawn:/sbin/getty 38400 tty4 linux
- );
+ |);
file::append '/etc/fstab' => 'cgroup /cgroup cgroup rw 0 0' && mkdir '/cgroup';
system "mount /cgroup";
- system "lxc-stop -n $hostname";
- system "lxc-destroy -n $hostname";
+ system "lxc-stop --name $hostname";
+ system "lxc-destroy --name $hostname";
file::replace "$path/etc/hostname" => $hostname;
- file::append "$path/hosts" => "$ip $hostname";
+ file::append "$path/etc/hosts" => "$ip $hostname";
+
+ file::replace "$path/etc/network/interfaces" => qq|
+auto eth0 lo
+
+iface lo inet loopback
+
+iface eth0 inet static
+ address $ip
+ netmask $netmask
+ gateway $server_ip
+ |;
+
+ file::replace "$path/etc/resolv.conf" => "nameserver $server_ip";
my $conf = "/virtual/$hostname.conf";
lxc.pts = 1024
lxc.network.type = veth
lxc.network.flags = up
-lxc.network.link = br0
+lxc.network.link = virtual
lxc.network.name = eth0
lxc.network.mtu = 1500
#lxc.mount = MNTFILE
lxc.cgroup.devices.allow = c 254:0 rwm
|;
- system "lxc-create -n $hostname -f $conf";
+ system "lxc-create --name $hostname --rcfile $conf";
warn "created $hostname $ip $path";
}