--- lib/PXElator/httpd.pm 2009/07/30 11:47:16 52
+++ lib/PXElator/httpd.pm 2009/07/30 12:10:53 53
@@ -18,10 +18,15 @@
#use JSON;
use IO::Socket::INET;
use Module::Refresh;
+use Parallel::ForkManager;
our $port = 7777;
our $debug = 1;
+my $pm = Parallel::ForkManager->new(10);
+
+our $screen_pid;
+
use server;
our $url = "http://$server::ip:$port/";
@@ -54,25 +59,51 @@
my $ok = "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n";
use boolean;
+use screen;
sub get_request {
my ( $client, $path, $param ) = @_;
- warn "get_request $client $path $param";
+ warn "get_request $client $path ",dump( $param );
if ( my $found = static( $client,$path ) ) {
warn "static $found" if $debug;
} elsif ( $path eq '/' ) {
+
+ my $screen = $screen_pid ? qq|stop $screen_pid| : 'start';
+
print $client $ok,
html::table( 2,
'pid', $$,
'debug', qq|$debug|,
+ 'screen', qq|$screen|,
);
} elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) {
eval 'our $' . $1 . ' = ' . $2;
warn $@ if $@;
print $client qq|HTTP/1.1 302 Found\r\nLocation: $url\r\nContent-type: text/html\r\n\r\n$1 = $2
Location: $url|;
+ } elsif ( $path =~ m{^/screen} ) {
+
+ if ( $screen_pid ) {
+ if ( ! kill $screen_pid ) {
+ warn "kill -9 $screen_pid";
+ if ( kill 9, $screen_pid ) {
+ print $client $ok, qq|screen pid $screen_pid stopped|;
+ $screen_pid = 0;
+ } else {
+ print $client $ok, qq|can't stop screen $screen_pid: $!|;
+ }
+ }
+ } else {
+ if ( $screen_pid = $pm->start ) {
+ print $client $ok, qq|screen started pid $screen_pid|;
+ } else {
+ screen::start;
+ $pm->finish;
+ }
+ }
+
} elsif ( $path =~ m{/boot} ) {
print $client qq{$ok
#!gpxe
@@ -87,6 +118,7 @@
}
}
+
sub start {
my $server = IO::Socket::INET->new(