/[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 162 by dpavlin, Thu Aug 6 18:10:31 2009 UTC revision 184 by dpavlin, Sun Aug 9 20:46:00 2009 UTC
# Line 52  use progress_bar; Line 52  use progress_bar;
52  use config;  use config;
53  use client;  use client;
54  use log;  use log;
55    use x11;
56    use amt;
57    
58  sub static {  sub static {
59          my ($client,$path) = @_;          my ($client,$path) = @_;
# Line 111  $SIG{CHLD} = 'IGNORE'; Line 113  $SIG{CHLD} = 'IGNORE';
113    
114  sub start_stop {  sub start_stop {
115          my $daemon = shift;          my $daemon = shift;
         my $pid = $pids->{$daemon} || 'not started';  
116    
117            my $pid = $pids->{$daemon};
118            my $pid_path = "$server::conf/$daemon.pid";
119    
120            if ( ! $pid && -e $pid_path ) {
121                    my $p = read_file $pid_path;
122                    if ( kill 0, $p ) {
123                            warn "adopted $daemon $p\n";
124                            return $pids->{$daemon} = $p;
125                    } else {
126                            warn "old $daemon $p not running";
127                            unlink $pid_path;
128                    }
129            }
130    
131            $pid ||= 'not started';
132          warn "start_stop $daemon $pid\n";          warn "start_stop $daemon $pid\n";
133    
134          if ( $pid =~ m{^\d+$} ) {          if ( $pid =~ m{^\d+$} ) {
# Line 126  sub start_stop { Line 142  sub start_stop {
142                  if ( $pid = fork ) {                  if ( $pid = fork ) {
143                          # parent                          # parent
144                          $pids->{$daemon} = $pid;                          $pids->{$daemon} = $pid;
145                            write_file $pid_path, $pid;
146                          warn "forked $daemon $pid\n";                          warn "forked $daemon $pid\n";
147                          return qq|$daemon pid $pid started|;                          return qq|$daemon pid $pid started|;
148                  } elsif ( defined $pid ) {                  } elsif ( defined $pid ) {
# Line 135  sub start_stop { Line 152  sub start_stop {
152                          if ( $daemon =~ m{dhcpd|tftpd|dnsd} ) {                          if ( $daemon =~ m{dhcpd|tftpd|dnsd} ) {
153                                  my $exec = "perl -I$server::base_dir/lib -I$server::base_dir/lib/PXElator -M$daemon -e ${daemon}::${invoke}";                                  my $exec = "perl -I$server::base_dir/lib -I$server::base_dir/lib/PXElator -M$daemon -e ${daemon}::${invoke}";
154                                  warn "exec $exec";                                  warn "exec $exec";
155                                  exec "xterm -T $daemon -n $daemon -e $exec";                                  x11::xterm( $daemon => $exec );
156                          } else {                          } else {
157                                  my $eval = $daemon . '::' . $invoke . '(' . ( @_ ? dump(@_) : '' ) . ')';                                  my $eval = $daemon . '::' . $invoke . '(' . ( @_ ? dump(@_) : '' ) . ')';
158                                  warn "eval $eval";                                  warn "eval $eval";
# Line 173  sub get_request { Line 190  sub get_request {
190                  foreach my $name ( sort keys %$pids ) {                  foreach my $name ( sort keys %$pids ) {
191                          my $pid = $pids->{$name} || next;                          my $pid = $pids->{$name} || next;
192    
193                          my $html = qq|<a href=/start_stop/$name>$pid</a>|;                          my $html;
194    
195                          my $proc = "/proc/$pid/status";                          my $proc = "/proc/$pid/status";
196    
197                          if ( -e $proc ) {                          if ( -e $proc ) {
198                                    $html .= qq|<a href=/start_stop/$name>$pid</a>|;
199                                  if ( $debug ) {                                  if ( $debug ) {
200                                          $html .= qq| <a name=$pid href=#proc-$pid>?</a>|;                                          $html .= qq| <a name=$pid href=#proc-$pid>?</a>|;
201    
# Line 195  sub get_request { Line 213  sub get_request {
213                                  if ( $name->can('actions') ) {                                  if ( $name->can('actions') ) {
214                                          $html .= qq| <a href=/action/kvm/$_>$_</a>| foreach $name->actions;                                          $html .= qq| <a href=/action/kvm/$_>$_</a>| foreach $name->actions;
215                                  }                                  }
216                            } else {
217                                    $html .= qq|<a href=/start_stop/$name>restart</a> $pid exited|;
218                          }                          }
219    
220                          push @rows, ( $name => $html );                          push @rows, ( $name => $html );
# Line 235  sub get_request { Line 255  sub get_request {
255                                  , qq|<form method=get>|                                  , qq|<form method=get>|
256                                  , html::table( 2,                                  , html::table( 2,
257                                          'ip' => $ip,                                          'ip' => $ip,
258                                            'mac' => client::mac( $ip ),
259                                          'hostname' => qq|<input type=text name=hostname value=$hostname>|,                                          'hostname' => qq|<input type=text name=hostname value=$hostname>|,
260                                          'deploy' => html::select( 'deploy', $deploy, config::available ),                                          'deploy' => html::select( 'deploy', $deploy, config::available ),
261                                  )                                  )
# Line 243  sub get_request { Line 264  sub get_request {
264                                  , config::for_ip( $ip )                                  , config::for_ip( $ip )
265                                  , qq|</pre>|                                  , qq|</pre>|
266                                  ;                                  ;
267    
268                            if ( my $amt = client::conf( $ip, 'amt' ) ) {
269                                    print $client amt::info( $amt );
270                            }
271                  } else {                  } else {
272                          print $client $ok                          print $client $ok
273                                  , qq|<h2>Clients on $server::ip</h2>|                                  , qq|<h2>Clients on $server::ip</h2>|
274                                  , qq|<ul>|                                  , html::table( -4,
275                                  , join("\n",                                          'ip', 'mac', 'hostname', 'deploy',
276                                          map {                                          map {
277                                                  my $ip = $_;                                                  my $ip = $_;
278                                                  $ip =~ s{^.+/ip/}{};                                                  $ip =~ s{^.+/ip/}{};
279                                                  qq|<li><a href=/client/$ip>$ip</a></li>|                                                  ( qq|<a href=/client/$ip>$ip</a>|, client::mac($ip), client::conf( $ip, 'hostname' ), client::conf( $ip, 'deploy' ) );
280                                          }                                          }
281                                          glob("$server::conf/ip/*")                                          glob("$server::conf/ip/*")
282                                  )                                  )
                                 , qq|</ul>|  
283                                  ;                                  ;
284                  }                  }
285          } elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) {          } elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) {
# Line 298  sub start { Line 322  sub start {
322          start_stop 'dhcpd';          start_stop 'dhcpd';
323          start_stop 'tftpd';          start_stop 'tftpd';
324          start_stop 'dnsd';          start_stop 'dnsd';
325          start_stop 'kvm';          start_stop 'kvm' unless $ENV{DEV}; # skip kvm statup when running on real device
326    
327          while (1) {          while (1) {
328                  my $client = $server->accept() || next; # ALARM trickle us                  my $client = $server->accept() || next; # ALARM trickle us

Legend:
Removed from v.162  
changed lines
  Added in v.184

  ViewVC Help
Powered by ViewVC 1.1.26