38 |
|
|
39 |
use html; |
use html; |
40 |
our $static_pids; |
our $static_pids; |
41 |
|
use progress_bar; |
42 |
|
|
43 |
sub static { |
sub static { |
44 |
my ($client,$path) = @_; |
my ($client,$path) = @_; |
65 |
print $client "HTTP/1.0 200 OK\r\nContent-Type: $type\r\nContent-Length: $size\r\nConnection: close\r\n\r\n"; |
print $client "HTTP/1.0 200 OK\r\nContent-Type: $type\r\nContent-Length: $size\r\nConnection: close\r\n\r\n"; |
66 |
|
|
67 |
open(my $fh, $full); |
open(my $fh, $full); |
|
print "static $path $type $size\n"; |
|
68 |
|
|
69 |
my $block = 8192; |
my $block = 1400; # try not to fragment packages (pxelinux seems to have problems with it) |
70 |
my $buff; |
my $buff; |
71 |
my $pos = 0; |
my $pos = 0; |
72 |
|
|
73 |
|
warn "static $path $type $size block: $block\n"; |
74 |
|
|
75 |
|
progress_bar::start; |
76 |
|
|
77 |
while( my $len = read $fh, $buff, $block ) { |
while( my $len = read $fh, $buff, $block ) { |
78 |
print $client $buff; |
print $client $buff; |
79 |
|
$client->flush; |
80 |
$pos += $len; |
$pos += $len; |
81 |
printf "%s %d/%d %.2f%%\r", $path, $pos, $size, $pos * 100 / $size; |
progress_bar::tick( $path, $pos, $size ); |
82 |
} |
} |
83 |
close($fh); |
close($fh); |
84 |
close($client); |
close($client); |
85 |
|
|
86 |
print "$path $pos == $size OK\n"; |
print STDERR "\n"; |
87 |
|
|
88 |
exit; |
warn "exit static child"; |
89 |
|
|
90 |
|
exit(0); |
91 |
} |
} |
92 |
|
|
93 |
use boolean; |
use boolean; |
101 |
my $daemon = shift; |
my $daemon = shift; |
102 |
my $pid = $pids->{$daemon}; |
my $pid = $pids->{$daemon}; |
103 |
|
|
104 |
warn "start_stop $daemon $pid pids: ",dump( $pids ); |
warn "start_stop $daemon $pid\n"; |
105 |
|
|
106 |
if ( $pid =~ m{^\d+$} ) { |
if ( $pid =~ m{^\d+$} ) { |
107 |
my $pstree = `pstree -p $pid`; |
my $pstree = `pstree -p $pid`; |
114 |
if ( $pid = fork ) { |
if ( $pid = fork ) { |
115 |
# parent |
# parent |
116 |
$pids->{$daemon} = $pid; |
$pids->{$daemon} = $pid; |
117 |
warn "forked $daemon $pid"; |
warn "forked $daemon $pid\n"; |
118 |
return qq|$daemon pid $pid started|; |
return qq|$daemon pid $pid started|; |
119 |
} elsif ( defined $pid ) { |
} elsif ( defined $pid ) { |
120 |
# child |
# child |
137 |
sub get_request { |
sub get_request { |
138 |
my ( $client, $path, $param ) = @_; |
my ( $client, $path, $param ) = @_; |
139 |
|
|
140 |
warn "get_request $client $path ",dump( $param ); |
warn "get_request $path ", $param ? dump( $param ) : '', "\n"; |
141 |
|
|
142 |
if ( my $found = static( $client,$path ) ) { |
if ( my $found = static( $client,$path ) ) { |
143 |
warn "static $found" if $debug; |
warn "static $found" if $debug; |
154 |
'debug', qq|<a href=/our/debug/| . boolean::toggle($debug) . qq|>$debug</a>|, |
'debug', qq|<a href=/our/debug/| . boolean::toggle($debug) . qq|>$debug</a>|, |
155 |
); |
); |
156 |
|
|
157 |
my $debug_proc; |
my $debug_proc = ''; |
158 |
|
|
159 |
warn 'pids: ', dump( $pids ) if $debug; |
warn 'pids: ', dump( $pids ) if $debug; |
160 |
foreach my $name ( keys %$pids ) { |
foreach my $name ( sort keys %$pids ) { |
161 |
my $pid = $pids->{$name} || next; |
my $pid = $pids->{$name} || next; |
162 |
|
|
163 |
my $html = qq|<a href=/$name>$pid</a>|; |
my $html = qq|<a href=/start_stop/$name>$pid</a>|; |
164 |
|
|
165 |
my $proc = "/proc/$pid/status"; |
my $proc = "/proc/$pid/status"; |
166 |
|
|
175 |
; |
; |
176 |
} |
} |
177 |
|
|
178 |
if ( $name->can('start_options') ) { |
if ( $name->can('start_fork') ) { |
179 |
$html .= qq| <a href=/kvm/$_>$_</a>| foreach $name->start_options; |
$html .= qq| <a href=/start_stop/kvm/$_>$_</a>| foreach $name->start_fork; |
180 |
|
} |
181 |
|
|
182 |
|
if ( $name->can('actions') ) { |
183 |
|
$html .= qq| <a href=/action/kvm/$_>$_</a>| foreach $name->actions; |
184 |
} |
} |
185 |
} |
} |
186 |
|
|
187 |
push @rows, ( $name => $html ); |
push @rows, ( $name => $html ); |
188 |
} |
} |
189 |
|
|
190 |
|
my $below_table = ''; |
191 |
|
|
192 |
warn 'static_pids: ', dump( $static_pids ) if $debug; |
warn 'static_pids: ', dump( $static_pids ) if $debug; |
193 |
foreach my $pid ( keys %$static_pids ) { |
foreach my $pid ( keys %$static_pids ) { |
194 |
my $path = $static_pids->{$pid}; |
my $path = $static_pids->{$pid}; |
195 |
if ( -d "/proc/$pid" ) { |
if ( -d "/proc/$pid" ) { |
196 |
push @rows, ( $path => qq|<a href=/kill/static/$pid>$pid</a>| ); |
push @rows, ( $path => qq|<a href=/kill/static/$pid>$pid</a>| ); |
197 |
|
} elsif ( $param->{clean_completed_downloads} ) { |
198 |
|
delete $static_pids->{$pid} |
199 |
} else { |
} else { |
200 |
push @rows, ( $path => "$pid competed" ); |
push @rows, ( $path => "$pid competed" ); |
201 |
|
$below_table = qq|<a href="/?clean_completed_downloads=1">clean completed downloads</a>|; |
202 |
} |
} |
203 |
} |
} |
204 |
|
|
205 |
print $client $ok |
print $client $ok |
206 |
, html::table( 2, @rows ) |
, html::table( 2, @rows ) |
207 |
|
, $below_table |
208 |
, html::tabs( log::mac_changes ) |
, html::tabs( log::mac_changes ) |
209 |
, $debug_proc |
, $debug_proc |
210 |
; |
; |
214 |
warn $@ if $@; |
warn $@ if $@; |
215 |
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>|; |
216 |
server::debug( $debug ) if $1 eq 'debug'; |
server::debug( $debug ) if $1 eq 'debug'; |
217 |
} elsif ( $path =~ m{^/((?:screen|kvm).*)} ) { |
} elsif ( $path =~ m{^/start_stop/((?:screen|kvm).*)} ) { # XXX we don't want to stop all classes |
218 |
print $client $redirect, start_stop($1); |
print $client $redirect, start_stop($1); |
219 |
|
} elsif ( $path =~ m{^/action/([^/]+)/(.+)} ) { |
220 |
|
$1->$2(); |
221 |
|
print $client $redirect; |
222 |
} elsif ( $path =~ m{^/kill/static/(\d+)} ) { |
} elsif ( $path =~ m{^/kill/static/(\d+)} ) { |
223 |
print $client $redirect; |
print $client $redirect; |
224 |
kill 9, $1 && warn "killed $1"; |
kill 1, $1 || kill 9, $2 && warn "killed $1"; |
225 |
} elsif ( $path eq '/exit' ) { |
} elsif ( $path eq '/exit' ) { |
226 |
# DESTROY; |
# DESTROY; |
227 |
exit 0; |
exit 0; |
275 |
} |
} |
276 |
warn "param: ",dump( $param ) if $debug; |
warn "param: ",dump( $param ) if $debug; |
277 |
} |
} |
|
warn "path $path param: ",dump( $param ); |
|
278 |
get_request $client, $path, $param; |
get_request $client, $path, $param; |
279 |
} else { |
} else { |
280 |
print $client "HTTP/1.0 500 No method\r\nConnection: close\r\nContent-type: text/plain\r\n\r\n500 $request"; |
print $client "HTTP/1.0 500 No method\r\nConnection: close\r\nContent-type: text/plain\r\n\r\n500 $request"; |