--- lib/PXElator/httpd.pm 2009/08/06 18:51:57 165 +++ lib/PXElator/httpd.pm 2009/08/09 20:46:00 184 @@ -52,6 +52,8 @@ use config; use client; use log; +use x11; +use amt; sub static { my ($client,$path) = @_; @@ -106,14 +108,27 @@ use boolean; use kvm; -use qemu; $pids->{qemu} = 'stopped'; $SIG{CHLD} = 'IGNORE'; sub start_stop { my $daemon = shift; - my $pid = $pids->{$daemon} || 'not started'; + my $pid = $pids->{$daemon}; + my $pid_path = "$server::conf/$daemon.pid"; + + if ( ! $pid && -e $pid_path ) { + my $p = read_file $pid_path; + if ( kill 0, $p ) { + warn "adopted $daemon $p\n"; + return $pids->{$daemon} = $p; + } else { + warn "old $daemon $p not running"; + unlink $pid_path; + } + } + + $pid ||= 'not started'; warn "start_stop $daemon $pid\n"; if ( $pid =~ m{^\d+$} ) { @@ -127,6 +142,7 @@ if ( $pid = fork ) { # parent $pids->{$daemon} = $pid; + write_file $pid_path, $pid; warn "forked $daemon $pid\n"; return qq|$daemon pid $pid started|; } elsif ( defined $pid ) { @@ -136,7 +152,7 @@ if ( $daemon =~ m{dhcpd|tftpd|dnsd} ) { my $exec = "perl -I$server::base_dir/lib -I$server::base_dir/lib/PXElator -M$daemon -e ${daemon}::${invoke}"; warn "exec $exec"; - exec "xterm -T $daemon -n $daemon -e $exec"; + x11::xterm( $daemon => $exec ); } else { my $eval = $daemon . '::' . $invoke . '(' . ( @_ ? dump(@_) : '' ) . ')'; warn "eval $eval"; @@ -174,11 +190,12 @@ foreach my $name ( sort keys %$pids ) { my $pid = $pids->{$name} || next; - my $html = qq|$pid|; + my $html; my $proc = "/proc/$pid/status"; if ( -e $proc ) { + $html .= qq|$pid|; if ( $debug ) { $html .= qq| ?|; @@ -196,6 +213,8 @@ if ( $name->can('actions') ) { $html .= qq| $_| foreach $name->actions; } + } else { + $html .= qq|restart $pid exited|; } push @rows, ( $name => $html ); @@ -245,19 +264,22 @@ , config::for_ip( $ip ) , qq|| ; + + if ( my $amt = client::conf( $ip, 'amt' ) ) { + print $client amt::info( $amt ); + } } else { print $client $ok , qq|

Clients on $server::ip

| - , qq|| ; } } elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) { @@ -300,7 +322,7 @@ start_stop 'dhcpd'; start_stop 'tftpd'; start_stop 'dnsd'; - start_stop 'kvm'; + start_stop 'kvm' unless $ENV{DEV}; # skip kvm statup when running on real device while (1) { my $client = $server->accept() || next; # ALARM trickle us