/[pxelator]/lib/PXElator/config.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

Diff of /lib/PXElator/config.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 271 by dpavlin, Wed Aug 19 22:48:54 2009 UTC revision 499 by dpavlin, Tue Feb 16 17:50:11 2010 UTC
# Line 8  use server; Line 8  use server;
8  use pxelinux;  use pxelinux;
9  use client;  use client;
10  use file;  use file;
11    use ssh;
12    
13  use File::Slurp;  use File::Slurp;
14    
15  sub available { qw/debian_live webconverger debirf tinycore nfsroot/ };  our $mounted;
16    
17    our $server;
18    our $server_ip;
19    
20    sub available { qw/katalog debian_live webconverger debirf tinycore nfsroot openvz printer wrt/ };
21    
22  sub debian_live {  sub debian_live {
23          my ($ip) = @_;          my ($ip) = @_;
# Line 30  sub debian_live { Line 36  sub debian_live {
36  default debian_live  default debian_live
37  label debian_live  label debian_live
38          kernel vmlinuz1          kernel vmlinuz1
39          append initrd=initrd1.img fetch=http://${server::ip}:7777/debian_live/debian-live-501-i386-standard.squashfs boot=live nopersistent hostname=$hostname union=aufs          append initrd=initrd1.img fetch=http://$server_ip:7777/debian_live/debian-live-501-i386-standard.squashfs boot=live nopersistent hostname=$hostname union=aufs noprompt
40          });          });
41    
42  }  }
# Line 48  L<http://webconverger.org/> Line 54  L<http://webconverger.org/>
54  sub webconverger {  sub webconverger {
55          my ($ip) = @_;          my ($ip) = @_;
56    
57          upstream::iso( 'http://download.webconverger.com/webc-5.2.iso' );          $mounted->{"webconverger/$ip"} ||= upstream::iso( 'http://download.webconverger.com/webc-5.5.iso' );
58    
         my $homepage = client::conf( $ip => 'homepage', default => "http://${server::ip}:7777/client" );  
59          my $hostname = client::conf( $ip => 'hostname' ) || 'webconverger';          my $hostname = client::conf( $ip => 'hostname' ) || 'webconverger';
60    
61            my $homepage = client::conf( $ip => 'webconverger/homepage'
62                    , default => "http://$server_ip:7777/client" );
63            my $fetch    = client::conf( $ip => 'webconverger/fetch'
64                    , default => "http://$server_ip:7777/webconverger/iso/live/filesystem.squashfs" );
65    
66          pxelinux::config_for_ip( $ip, qq{          pxelinux::config_for_ip( $ip, qq{
67    
68  default webconverger  default webconverger
69  label webconverger  label webconverger
70          kernel iso/live/vmlinuz-2.6.30-backports.1-486          kernel iso/live/vmlinuz-2.6.30-backports.1-486
71          append initrd=iso/live/initrd.img-2.6.30-backports.1-486 fetch=http://${server::ip}:7777/webconverger/iso/live/filesystem.squashfs boot=live quiet nosudo splash video=vesa:ywrap,mtrr vga=788 nopersistent username=webc hostname=$hostname union=aufs homepage=$homepage locale=hr          append initrd=iso/live/initrd.img-2.6.30-backports.1-486 fetch=$fetch boot=live quiet nosudo splash video=vesa:ywrap,mtrr vga=788 nopersistent username=webc hostname=$hostname union=aufs homepage=$homepage locale=hr noprompt kioskresetstation=10
72    
73          });          });
74    
75  }  }
76    
77    sub katalog {
78            my ($ip) = @_;
79            $mounted->{"webconverger/$ip"} ||= upstream::iso( 'http://download.webconverger.com/webc-5.5.iso' );
80            my $hostname = client::conf( $ip => 'hostname' ) || 'katalog';
81            my $homepage = client::conf( $ip => 'webconverger/homepage' => "http://koha.ffzg.hr" );
82            my $fetch    = client::conf( $ip => 'webconverger/fetch' => "http://$server_ip:7777/webconverger/custom.squashfs" );
83    
84            pxelinux::config_for_ip( $ip, qq{
85    
86    default katalog
87    label katalog
88            kernel iso/live/vmlinuz-2.6.30-backports.1-486
89            append initrd=iso/live/initrd.img-2.6.30-backports.1-486 fetch=$fetch boot=live quiet nosudo splash video=vesa:ywrap,mtrr vga=788 nopersistent username=webc hostname=$hostname union=aufs homepage=$homepage locale=hr noprompt
90    
91            });
92    
93    }
94  =head1 debirf  =head1 debirf
95    
96  debirf is a system that will create diskless, all-in-ram images (kernel and initramfs) that boot entirely into ram and leave the user in a fully functional Debian system.  debirf is a system that will create diskless, all-in-ram images (kernel and initramfs) that boot entirely into ram and leave the user in a fully functional Debian system.
# Line 106  sub in_chroot { Line 133  sub in_chroot {
133          system "sudo chroot $dir sh -x /tmp/inside.sh";          system "sudo chroot $dir sh -x /tmp/inside.sh";
134  }  }
135    
 our $mounted;  
   
136  sub nfsroot {  sub nfsroot {
137          my $ip = shift;          my $ip = shift || die "no ip?";
138    
139            my $dist = 'lenny';
140            $dist = 'squeeze';
141    
142          my $nfsroot = "$server::base_dir/tftp/nfsroot";          my $nfsroot = "$server::base_dir/tftp/nfsroot";
143          my $debian_mirror = server::conf_default( 'debian_mirror', 'http://ftp.debian.org/debian' );          my $debian_mirror = server::conf_default( 'debian_mirror', 'http://ftp.debian.org/debian' );
# Line 123  sub nfsroot { Line 151  sub nfsroot {
151    
152          if ( ! -e $debootstrap ) {          if ( ! -e $debootstrap ) {
153    
154                  system "sudo debootstrap --arch i386 lenny $debootstrap $debian_mirror";                  system "sudo debootstrap --arch i386 $dist $debootstrap $debian_mirror";
   
                 file::append "$debootstrap/etc/kernel-img.conf", "do_initrd = Yes\n" &&  
                 in_chroot     $debootstrap => 'apt-get install -y --force-yes atl2-modules-2.6-686';  
                 in_chroot     $debootstrap => 'apt-get -f install -y --force-yes locales';      # linux-image-2.6-686  
   
                 file::append "$debootstrap/etc/initramfs-tools/modules", "atl2\n";  
                 file::change("$debootstrap/etc/initramfs-tools/initramfs.conf",  'BOOT=local' => 'BOOT=nfs' ) &&  
                 in_chroot     $debootstrap => 'update-initramfs -u';  
155    
156                  file::append "$debootstrap/etc/rsyslog.d/pxelator.conf", "*.*\t\@$server::ip\n";                  file::append "$debootstrap/etc/apt/sources.list.d/non-free.list", "deb $debian_mirror $dist non-free\n";
157                  file::append "$debootstrap/etc/network/interfaces", qq{                  in_chroot     $debootstrap => 'apt-get update';
158    
159  auto lo                  file::append "$debootstrap/etc/kernel-img.conf", "do_initrd = Yes\n";
160  iface lo inet loopback                  in_chroot     $debootstrap => 'apt-get -f install -y --force-yes locales linux-image-2.6-686 firmware-bnx2';
161    
162  allow-hotplug eth0                  # this can fails on some distros, so we run it alone
163  iface eth0 inet dhcp                  in_chroot     $debootstrap => 'apt-get install -y --force-yes atl2-modules-2.6-686';
164                    file::append "$debootstrap/etc/initramfs-tools/modules", "atl2\n";
165    
166                  };                  file::change "$debootstrap/etc/initramfs-tools/initramfs.conf",  'BOOT=local' => 'BOOT=nfs';
167                    in_chroot     $debootstrap => 'update-initramfs -u';
168    
169          }          }
170    
171          my $export = "$nfsroot/$ip";          my $export = "$nfsroot/$ip";
172          my $br     = "$nfsroot/br/$ip";          my $br     = "$nfsroot/br/$ip";
173    
174          my $m = $mounted->{$ip} ||= `mount | grep $export`;          $mounted->{"nfsroot/$ip"} ||= `mount | grep $export`;
175          if ( ! $m ) {  
176            if ( ! $mounted->{"nfsroot/$ip"} ) {
177                  warn "mounting $export";                  warn "mounting $export";
178    
179                  mkdir "$nfsroot/br"     unless -e "$nfsroot/br";                  mkdir "$nfsroot/br"     unless -e "$nfsroot/br";
# Line 160  iface eth0 inet dhcp Line 183  iface eth0 inet dhcp
183                  system "sudo mount -t aufs -o br:$br:$debootstrap none $export";                  system "sudo mount -t aufs -o br:$br:$debootstrap none $export";
184                  system "sudo exportfs -i -o rw,async,no_root_squash,no_subtree_check,fsid=999 $ip:$export";                  system "sudo exportfs -i -o rw,async,no_root_squash,no_subtree_check,fsid=999 $ip:$export";
185                    
                 my $hostname = client::conf( $ip => 'hostname' ) || 'nfsroot';  
                 write_file "$export/etc/hostname", $hostname;  
                 file::append "$export/hosts", '127.0.0.1';  
186          }          }
187    
188            my $exported = `exportfs | grep $export`;
189            if ( $exported ne $export ) {
190                    warn "exportfs $exported\n";
191                    system "sudo exportfs -i -o rw,async,no_root_squash,no_subtree_check,fsid=999 $ip:$export";
192            }
193    
194          pxelinux::config_for_ip( $ip, qq{          my $hostname = client::conf( $ip => 'hostname' ) || 'nfsroot';
195            file::replace "$export/etc/hostname", $hostname;
196            file::replace "$export/etc/hosts", "127.0.0.1\tlocalhost $hostname\n";
197            file::replace "$export/etc/resolv.conf", "domain $server->{domain}\nnameserver $server->{ip}\n";
198            file::replace "$export/etc/rsyslog.d/pxelator.conf", "*.*\t\@$server->{ip}\n";
199    
200  default nfsroot          file::append "$debootstrap/etc/network/interfaces", qq{
201  label nfsroot  
202          kernel debootstrap/vmlinuz  auto lo
203          append initrd=debootstrap/initrd.img root=/dev/nfs nfsroot=$server::ip:$export ro ip=dhcp  iface lo inet loopback
204    
205    allow-hotplug eth0
206    iface eth0 inet dhcp
207    
208            };
209    
210            map {
211                    file::copy_once $_ => "$export/$_";
212                    file::append "$export/etc/rc.local", $_;
213            } ( '/srv/sysadmin-cookbook/recepies/amt/serial-console.sh' );
214    
215            pxelinux::config_ip_boot( $ip, "$export/boot", "root=/dev/nfs nfsroot=$server->{ip}:$export ro ip=dhcp" );
216    
         });  
217  }  }
218    
219  sub for_ip {  sub openvz {
220          my $ip = shift;          my $ip = shift;
221          my $deploy = client::conf( $ip => 'deploy', default => 'webconverger' );          ssh::shell( $ip, 'cat /proc/vz/veinfo', 'vzlist -a', 'uptime', 'free', 'df', 'zfs list' );
222          eval $deploy . '($ip)';  }
223  #       $tftp::dir = "$server::base_dir/tftp/$pxelinux::path_prefix";  sub printer     {}
224    sub wrt         {}
225    
226    sub for_ip {
227            my $ip = shift || return;
228            $server = server::as_hash_for $ip;
229            $server_ip = $server->{ip} || die "no server ip";
230            my $config = client::conf( $ip => 'config' ) || return;
231            eval $config . '($ip)'; # must be last
232  }  }
233    
234  warn 'loaded';  warn 'loaded';

Legend:
Removed from v.271  
changed lines
  Added in v.499

  ViewVC Help
Powered by ViewVC 1.1.26