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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 264 - (show annotations)
Wed Aug 19 12:45:07 2009 UTC (14 years, 7 months ago) by dpavlin
File size: 1135 byte(s)
refresh $package::debug from shared state on filesystem
1 package server;
2
3 use warnings;
4 use strict;
5
6
7 our $ip = '172.16.10.1';
8 our $netmask = '255.255.255.0';
9 our $bcast = '172.16.10.255';
10
11 if ( my $dev = $ENV{DEV} ) {
12 my $ifconfig = `ifconfig $dev`;
13 ( $ip, $bcast, $netmask ) = ( $1, $2, $3 ) if $ifconfig =~ m{inet addr:(\S+)\s+Bcast:(\S+)\s+Mask:(\S+)}s;
14 warn "DEV $dev $ip $bcast $netmask";
15 }
16
17 our ( $ip_from, $ip_to ) = ( 10, 100 );
18
19 our $domain_name = 'pxelator.lan';
20
21 our $base_dir = '/srv/pxelator';
22
23 our $conf = "$base_dir/conf/$ip";
24 mkdir $conf unless -e $conf;
25
26 use Module::Refresh qw//;
27 sub refresh {
28 Module::Refresh->refresh;
29 my $from = (caller(1))[3];
30 $from =~ s{^(\w+)::.+$}{$1};
31 my $eval = '$' . $from . '::debug = server::debug();';
32 warn "refresh $eval\n";
33 eval $eval;
34 warn $@ if $@;
35 };
36
37 mkdir $_ foreach grep { ! -d $_ } map { "$conf/$_" } ( 'ip', 'mac' );
38
39 use File::Slurp;
40 sub shared {
41 my ($name, $value) = @_;
42
43 my $path ="$conf/$name";
44 if ( defined $value ) {
45 write_file $path, $value;
46 warn "update $path = $value";
47 } else {
48 $value = read_file $path if -e $path;
49 }
50 return $value;
51 }
52
53 sub debug { shared('debug', @_) || 0 }
54
55 warn "loaded";
56
57 1;

  ViewVC Help
Powered by ViewVC 1.1.26