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

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

revision 67 by dpavlin, Thu Jul 30 21:31:30 2009 UTC revision 72 by dpavlin, Thu Jul 30 23:57:19 2009 UTC
# Line 19  use File::Slurp; Line 19  use File::Slurp;
19  use IO::Socket::INET;  use IO::Socket::INET;
20  use Module::Refresh;  use Module::Refresh;
21    
22  our $pids = { httpd => $$ };  our $pids;
23    $pids = { httpd => $$ } unless defined $pids; # keep pids on refresh
24    
25  sub DESTROY {  sub DESTROY {
26          warn "pids ",dump( $pids );          warn "pids ",dump( $pids );
# Line 36  our $debug = server::debug; Line 37  our $debug = server::debug;
37  our $url = "http://$server::ip:$port";  our $url = "http://$server::ip:$port";
38    
39  use html;  use html;
40    our $static_pids;
41    
42  sub static {  sub static {
43          my ($client,$path) = @_;          my ($client,$path) = @_;
# Line 44  sub static { Line 46  sub static {
46    
47          return if ! -f $full;          return if ! -f $full;
48    
49            if ( my $pid = fork ) {
50                    # parent
51                    close($client);
52                    print "http static child $pid\n";
53                    $static_pids->{$pid} = $path;
54                    return 1;
55            }
56    
57          my $type = 'application/octet-stream';          my $type = 'application/octet-stream';
58          $type = 'text/html' if $path =~ m{\.htm};          $type = 'text/html' if $path =~ m{\.htm};
59          $type = 'application/javascript' if $path =~ m{\.js};          $type = 'application/javascript' if $path =~ m{\.js};
# Line 70  sub static { Line 80  sub static {
80    
81          print "$path $pos == $size OK\n";          print "$path $pos == $size OK\n";
82    
83          return $path;          exit;
84  }  }
85    
86  use boolean;  use boolean;
# Line 132  sub get_request { Line 142  sub get_request {
142    
143                          'debug',        qq|<a href=/our/debug/| . boolean::toggle($debug) . qq|>$debug</a>|,                          'debug',        qq|<a href=/our/debug/| . boolean::toggle($debug) . qq|>$debug</a>|,
144                  );                  );
145                  foreach my $name ( %$pids ) {  
146                    my $debug_proc;
147    
148                    warn 'pids: ', dump( $pids );
149                    foreach my $name ( keys %$pids ) {
150                          my $pid = $pids->{$name} || next;                          my $pid = $pids->{$name} || next;
                         my $proc = "/proc/$pid/status";  
151    
152                          my $html = qq|<a href=/$name>$pid</a>|;                          my $html = qq|<a href=/$name>$pid</a>|;
153                          $html   .= qq|<pre style="font-size: 10%">|  
154                                          .  ( $debug && -e $proc ? read_file($proc) : '' )                          if ( $debug ) {
155                                          .  qq|</pre>| if $debug;                                  $html .= qq| <a name=$pid href=#proc-$pid>?</a>|;
156    
157                                    my $proc = "/proc/$pid/status";
158                                    $debug_proc
159                                            .= qq|<a name=proc-$pid href=#$pid>$proc</a><pre style="font-size: 10%">|
160                                            .  read_file($proc)
161                                            .  qq|</pre>|
162                                            if -e $proc;
163                            }
164    
165                          push @rows, ( $name => $html );                          push @rows, ( $name => $html );
166                  }                  }
167    
168                  print $client $ok, html::table( 2, @rows );                  warn 'static_pids: ', dump( $static_pids );
169                    foreach my $pid ( keys %$static_pids ) {
170                            my $path = $static_pids->{$pid};
171                            if ( -d "/proc/$pid" ) {
172                                    push @rows, ( $path => qq|<a href=/kill/static/$pid>$pid</a>| );
173                            } else {
174                                    push @rows, ( $path => "$pid competed" );
175                            }
176                    }
177    
178                    print $client $ok
179                            , html::table( 2, @rows )
180                            , html::tabs( log::mac_changes )
181                            , $debug_proc
182                            ;
183    
184          } elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) {          } elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) {
185                  eval 'our $' . $1 . ' = ' . $2;                  eval 'our $' . $1 . ' = ' . $2;
# Line 153  sub get_request { Line 188  sub get_request {
188                  server::debug( $debug ) if $1 eq 'debug';                  server::debug( $debug ) if $1 eq 'debug';
189          } elsif ( $path =~ m{^/(screen|kvm)} ) {          } elsif ( $path =~ m{^/(screen|kvm)} ) {
190                  print $client $redirect, start_stop($1);                  print $client $redirect, start_stop($1);
191            } elsif ( $path =~ m{^/kill/static/(\d+)} ) {
192                    print $client $redirect;
193                    kill 9, $1 && warn "killed $1";
194          } elsif ( $path eq '/exit' ) {          } elsif ( $path eq '/exit' ) {
195  #               DESTROY;  #               DESTROY;
196                  exit 0;                  exit 0;

Legend:
Removed from v.67  
changed lines
  Added in v.72

  ViewVC Help
Powered by ViewVC 1.1.26