/[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

Diff of /lib/PXElator/server.pm

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

revision 118 by dpavlin, Mon Aug 3 08:52:32 2009 UTC revision 288 by dpavlin, Tue Aug 25 17:09:52 2009 UTC
# Line 3  package server; Line 3  package server;
3  use warnings;  use warnings;
4  use strict;  use strict;
5    
 use Module::Refresh;  
6    
7  our $ip      = '172.16.10.1';  our $ip      = '172.16.10.1';
8  our $netmask = '255.255.255.0';  our $netmask = '255.255.255.0';
9    our $bcast   = '172.16.10.255';
10    
11    sub setup_from_dev {
12            my $dev = shift || return;
13            my $ifconfig = `/sbin/ifconfig $dev`;
14            ( $ip, $bcast, $netmask ) = ( $1, $2, $3 ) if $ifconfig =~ m{inet addr:(\S+)\s+Bcast:(\S+)\s+Mask:(\S+)}s;
15            warn "DEV $dev $ip $bcast $netmask";
16    }
17    
18    setup_from_dev( $ENV{DEV} || 'virtual' );
19    
20  our ( $ip_from, $ip_to ) = ( 10, 100 );  our ( $ip_from, $ip_to ) = ( 10, 100 );
21    
22  our $base_dir = '/home/dpavlin/llin/pxelator';  our $domain_name = 'pxelator.lan';
23    
24  use config;  our $base_dir = '/srv/pxelator';
25    
26  our $debug;  our $conf = "$base_dir/conf/$ip";
27  sub debug { $debug = config::shared('debug', @_) || 0 }  mkdir $conf unless -e $conf;
28    
29  my $timestamp_interval = 3;  use Module::Refresh qw//;
30  my $stderr_tell = 0;  sub refresh {
31            Module::Refresh->refresh;
32  $SIG{ALRM} = sub {          my $from = (caller(1))[3];
33      if ( tell(STDERR) != $stderr_tell ) {          $from =~ s{^(\w+)::.+$}{$1};
34          warn "\nTIMESTAMP: " . localtime() . "\n\n";          my $eval = '$' . $from . '::debug = server::debug();';
35          $stderr_tell = tell(STDERR);          warn "refresh $eval\n";
36                  Module::Refresh->refresh;          eval $eval;
37      }          warn $@ if $@;
     alarm $timestamp_interval;  
38  };  };
39  alarm $timestamp_interval;  
40    mkdir $_ foreach grep { ! -d $_ } map { "$conf/$_" } ( 'ip', 'mac' );
41    
42    use File::Slurp;
43    sub shared {
44            my ($name, $value) = @_;
45    
46            my $path ="$conf/$name";
47            if ( defined $value ) {
48                    write_file $path, $value;
49                    warn "update $path = $value";
50            } else {
51                    $value = read_file $path if -e $path;
52            }
53            return $value;
54    }
55    
56    sub conf_default { shared($_[0]) || $_[1] }
57    
58    sub debug { shared('debug', @_) || 0 }
59    
60  warn "loaded";  warn "loaded";
61    
62    1;

Legend:
Removed from v.118  
changed lines
  Added in v.288

  ViewVC Help
Powered by ViewVC 1.1.26