/[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 70 by dpavlin, Thu Jul 30 22:44:55 2009 UTC revision 86 by dpavlin, Fri Jul 31 17:41:19 2009 UTC
# Line 97  sub start_stop { Line 97  sub start_stop {
97          warn "start_stop $daemon $pid pids: ",dump( $pids );          warn "start_stop $daemon $pid pids: ",dump( $pids );
98    
99          if ( $pid =~ m{^\d+$} ) {          if ( $pid =~ m{^\d+$} ) {
100                  warn "kill 9 $pid";                  my $pstree = `pstree -p $pid`;
101                  kill 9, $pid;                  my @pids = $pstree =~ m{\((\d+)\)}g;
102                    warn "pstree $pstree pids ",dump( @pids );
103                    kill 1, $_ foreach reverse @pids;
104                  $pids->{$daemon} = 'stopped';                  $pids->{$daemon} = 'stopped';
105                  return qq|$daemon pid $pid stopped|;                  return qq|$daemon pid $pid stopped|;
106          } else {          } else {
# Line 109  sub start_stop { Line 111  sub start_stop {
111                          return qq|$daemon pid $pid started|;                          return qq|$daemon pid $pid started|;
112                  } elsif ( defined $pid ) {                  } elsif ( defined $pid ) {
113                          # child                          # child
114                          my $eval = $daemon . '::start(' . ( @_ ? dump(@_) : '' ) . ')';                          my $invoke = 'start';
115                            $invoke = $1 if $daemon =~ s{/(.+)}{};
116                            my $eval = $daemon . '::' . $invoke . '(' . ( @_ ? dump(@_) : '' ) . ')';
117                          warn "eval $eval";                          warn "eval $eval";
118                          eval $eval;                          eval $eval;
119                          warn "can't start $daemon: $@" if $@;                          warn "can't start $daemon: $@" if $@;
# Line 143  sub get_request { Line 147  sub get_request {
147                          'debug',        qq|<a href=/our/debug/| . boolean::toggle($debug) . qq|>$debug</a>|,                          'debug',        qq|<a href=/our/debug/| . boolean::toggle($debug) . qq|>$debug</a>|,
148                  );                  );
149    
150                  warn 'pids: ', dump( $pids );                  my $debug_proc;
151    
152                    warn 'pids: ', dump( $pids ) if $debug;
153                  foreach my $name ( keys %$pids ) {                  foreach my $name ( keys %$pids ) {
154                          my $pid = $pids->{$name} || next;                          my $pid = $pids->{$name} || next;
                         my $proc = "/proc/$pid/status";  
155    
156                          my $html = qq|<a href=/$name>$pid</a>|;                          my $html = qq|<a href=/$name>$pid</a>|;
157                          $html   .= qq|<pre style="font-size: 10%">|  
158                                          .  ( $debug && -e $proc ? read_file($proc) : '' )                          my $proc = "/proc/$pid/status";
159                                          .  qq|</pre>| if $debug;  
160                            if ( -e $proc ) {
161                                    if ( $debug ) {
162                                            $html .= qq| <a name=$pid href=#proc-$pid>?</a>|;
163    
164                                            $debug_proc
165                                                    .= qq|<a name=proc-$pid href=#$pid>$proc</a><pre style="font-size: 10%">|
166                                                    .  read_file($proc)
167                                                    .  qq|</pre>|
168                                                    ;
169                                    }
170    
171                                    if ( $name->can('start_options') ) {
172                                            $html .= qq| <a href=/kvm/$_>$_</a>| foreach $name->start_options;
173                                    }
174                            }
175    
176                          push @rows, ( $name => $html );                          push @rows, ( $name => $html );
177                  }                  }
178    
179                  warn 'static_pids: ', dump( $static_pids );                  warn 'static_pids: ', dump( $static_pids ) if $debug;
180                  foreach my $pid ( keys %$static_pids ) {                  foreach my $pid ( keys %$static_pids ) {
181                          my $path = $static_pids->{$pid};                          my $path = $static_pids->{$pid};
182                          if ( -d "/proc/$pid" ) {                          if ( -d "/proc/$pid" ) {
# Line 166  sub get_request { Line 186  sub get_request {
186                          }                          }
187                  }                  }
188    
189                  print $client $ok, html::table( 2, @rows );                  print $client $ok
190                            , html::table( 2, @rows )
191                            , html::tabs( log::mac_changes )
192                            , $debug_proc
193                            ;
194    
195          } elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) {          } elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) {
196                  eval 'our $' . $1 . ' = ' . $2;                  eval 'our $' . $1 . ' = ' . $2;
197                  warn $@ if $@;                  warn $@ if $@;
198                  print $client $redirect, qq|<big>$1 = $2</big><br>Location: <a href="$url">$url</a>|;                  print $client $redirect, qq|<big>$1 = $2</big><br>Location: <a href="$url">$url</a>|;
199                  server::debug( $debug ) if $1 eq 'debug';                  server::debug( $debug ) if $1 eq 'debug';
200          } elsif ( $path =~ m{^/(screen|kvm)} ) {          } elsif ( $path =~ m{^/((?:screen|kvm).*)} ) {
201                  print $client $redirect, start_stop($1);                  print $client $redirect, start_stop($1);
202          } elsif ( $path =~ m{^/kill/static/(\d+)} ) {          } elsif ( $path =~ m{^/kill/static/(\d+)} ) {
203                  print $client $redirect;                  print $client $redirect;
204                  kill 9, $1 && warn "killed $1";                  kill 1, $1 || kill 9, $2 && warn "killed $1";
205          } elsif ( $path eq '/exit' ) {          } elsif ( $path eq '/exit' ) {
206  #               DESTROY;  #               DESTROY;
207                  exit 0;                  exit 0;

Legend:
Removed from v.70  
changed lines
  Added in v.86

  ViewVC Help
Powered by ViewVC 1.1.26