61 |
|
|
62 |
my $size = -s $full || return; |
my $size = -s $full || return; |
63 |
|
|
64 |
|
$client->autoflush(1); |
65 |
|
|
66 |
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"; |
67 |
|
|
68 |
open(my $fh, $full); |
open(my $fh, $full); |
|
print "static $path $type $size\n"; |
|
69 |
|
|
70 |
my $block = 8192; |
my $block = 1400; # try not to fragment packages (pxelinux seems to have problems with it) |
71 |
my $buff; |
my $buff; |
72 |
my $pos = 0; |
my $pos = 0; |
73 |
|
|
74 |
|
print "static $path $type $size block: $block\n"; |
75 |
|
|
76 |
while( my $len = read $fh, $buff, $block ) { |
while( my $len = read $fh, $buff, $block ) { |
77 |
print $client $buff; |
print $client $buff; |
78 |
$pos += $len; |
$pos += $len; |
81 |
close($fh); |
close($fh); |
82 |
close($client); |
close($client); |
83 |
|
|
84 |
print "$path $pos == $size OK\n"; |
print "\n"; |
85 |
|
|
86 |
exit; |
exit; |
87 |
} |
} |
97 |
my $daemon = shift; |
my $daemon = shift; |
98 |
my $pid = $pids->{$daemon}; |
my $pid = $pids->{$daemon}; |
99 |
|
|
100 |
warn "start_stop $daemon $pid pids: ",dump( $pids ); |
warn "start_stop $daemon $pid\n"; |
101 |
|
|
102 |
if ( $pid =~ m{^\d+$} ) { |
if ( $pid =~ m{^\d+$} ) { |
103 |
my $pstree = `pstree -p $pid`; |
my $pstree = `pstree -p $pid`; |
110 |
if ( $pid = fork ) { |
if ( $pid = fork ) { |
111 |
# parent |
# parent |
112 |
$pids->{$daemon} = $pid; |
$pids->{$daemon} = $pid; |
113 |
warn "forked $daemon $pid"; |
warn "forked $daemon $pid\n"; |
114 |
return qq|$daemon pid $pid started|; |
return qq|$daemon pid $pid started|; |
115 |
} elsif ( defined $pid ) { |
} elsif ( defined $pid ) { |
116 |
# child |
# child |
117 |
my $eval = $daemon . '::start(' . ( @_ ? dump(@_) : '' ) . ')'; |
my $invoke = 'start'; |
118 |
|
$invoke = $1 if $daemon =~ s{/(.+)}{}; |
119 |
|
my $eval = $daemon . '::' . $invoke . '(' . ( @_ ? dump(@_) : '' ) . ')'; |
120 |
warn "eval $eval"; |
warn "eval $eval"; |
121 |
eval $eval; |
eval $eval; |
122 |
warn "can't start $daemon: $@" if $@; |
warn "can't start $daemon: $@" if $@; |
133 |
sub get_request { |
sub get_request { |
134 |
my ( $client, $path, $param ) = @_; |
my ( $client, $path, $param ) = @_; |
135 |
|
|
136 |
warn "get_request $client $path ",dump( $param ); |
warn "get_request $path ", $param ? dump( $param ) : '', "\n"; |
137 |
|
|
138 |
if ( my $found = static( $client,$path ) ) { |
if ( my $found = static( $client,$path ) ) { |
139 |
warn "static $found" if $debug; |
warn "static $found" if $debug; |
150 |
'debug', qq|<a href=/our/debug/| . boolean::toggle($debug) . qq|>$debug</a>|, |
'debug', qq|<a href=/our/debug/| . boolean::toggle($debug) . qq|>$debug</a>|, |
151 |
); |
); |
152 |
|
|
153 |
my $debug_proc; |
my $debug_proc = ''; |
154 |
|
|
155 |
warn 'pids: ', dump( $pids ) if $debug; |
warn 'pids: ', dump( $pids ) if $debug; |
156 |
foreach my $name ( keys %$pids ) { |
foreach my $name ( sort keys %$pids ) { |
157 |
my $pid = $pids->{$name} || next; |
my $pid = $pids->{$name} || next; |
158 |
|
|
159 |
my $html = qq|<a href=/$name>$pid</a>|; |
my $html = qq|<a href=/start_stop/$name>$pid</a>|; |
160 |
|
|
161 |
if ( $debug ) { |
my $proc = "/proc/$pid/status"; |
|
$html .= qq| <a name=$pid href=#proc-$pid>?</a>|; |
|
162 |
|
|
163 |
my $proc = "/proc/$pid/status"; |
if ( -e $proc ) { |
164 |
$debug_proc |
if ( $debug ) { |
165 |
.= qq|<a name=proc-$pid href=#$pid>$proc</a><pre style="font-size: 10%">| |
$html .= qq| <a name=$pid href=#proc-$pid>?</a>|; |
166 |
. read_file($proc) |
|
167 |
. qq|</pre>| |
$debug_proc |
168 |
if -e $proc; |
.= qq|<a name=proc-$pid href=#$pid>$proc</a><pre style="font-size: 10%">| |
169 |
|
. read_file($proc) |
170 |
|
. qq|</pre>| |
171 |
|
; |
172 |
|
} |
173 |
|
|
174 |
|
if ( $name->can('start_fork') ) { |
175 |
|
$html .= qq| <a href=/start_stop/kvm/$_>$_</a>| foreach $name->start_fork; |
176 |
|
} |
177 |
|
|
178 |
|
if ( $name->can('actions') ) { |
179 |
|
$html .= qq| <a href=/action/kvm/$_>$_</a>| foreach $name->actions; |
180 |
|
} |
181 |
} |
} |
182 |
|
|
183 |
push @rows, ( $name => $html ); |
push @rows, ( $name => $html ); |
184 |
} |
} |
185 |
|
|
186 |
|
my $below_table = ''; |
187 |
|
|
188 |
warn 'static_pids: ', dump( $static_pids ) if $debug; |
warn 'static_pids: ', dump( $static_pids ) if $debug; |
189 |
foreach my $pid ( keys %$static_pids ) { |
foreach my $pid ( keys %$static_pids ) { |
190 |
my $path = $static_pids->{$pid}; |
my $path = $static_pids->{$pid}; |
191 |
if ( -d "/proc/$pid" ) { |
if ( -d "/proc/$pid" ) { |
192 |
push @rows, ( $path => qq|<a href=/kill/static/$pid>$pid</a>| ); |
push @rows, ( $path => qq|<a href=/kill/static/$pid>$pid</a>| ); |
193 |
|
} elsif ( $param->{clean_completed_downloads} ) { |
194 |
|
delete $static_pids->{$pid} |
195 |
} else { |
} else { |
196 |
push @rows, ( $path => "$pid competed" ); |
push @rows, ( $path => "$pid competed" ); |
197 |
|
$below_table = qq|<a href="/?clean_completed_downloads=1">clean completed downloads</a>|; |
198 |
} |
} |
199 |
} |
} |
200 |
|
|
201 |
print $client $ok |
print $client $ok |
202 |
, html::table( 2, @rows ) |
, html::table( 2, @rows ) |
203 |
|
, $below_table |
204 |
, html::tabs( log::mac_changes ) |
, html::tabs( log::mac_changes ) |
205 |
, $debug_proc |
, $debug_proc |
206 |
; |
; |
210 |
warn $@ if $@; |
warn $@ if $@; |
211 |
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>|; |
212 |
server::debug( $debug ) if $1 eq 'debug'; |
server::debug( $debug ) if $1 eq 'debug'; |
213 |
} elsif ( $path =~ m{^/(screen|kvm)} ) { |
} elsif ( $path =~ m{^/start_stop/((?:screen|kvm).*)} ) { # XXX we don't want to stop all classes |
214 |
print $client $redirect, start_stop($1); |
print $client $redirect, start_stop($1); |
215 |
|
} elsif ( $path =~ m{^/action/([^/]+)/(.+)} ) { |
216 |
|
$1->$2(); |
217 |
|
print $client $redirect; |
218 |
} elsif ( $path =~ m{^/kill/static/(\d+)} ) { |
} elsif ( $path =~ m{^/kill/static/(\d+)} ) { |
219 |
print $client $redirect; |
print $client $redirect; |
220 |
kill 9, $1 && warn "killed $1"; |
kill 1, $1 || kill 9, $2 && warn "killed $1"; |
221 |
} elsif ( $path eq '/exit' ) { |
} elsif ( $path eq '/exit' ) { |
222 |
# DESTROY; |
# DESTROY; |
223 |
exit 0; |
exit 0; |
271 |
} |
} |
272 |
warn "param: ",dump( $param ) if $debug; |
warn "param: ",dump( $param ) if $debug; |
273 |
} |
} |
|
warn "path $path param: ",dump( $param ); |
|
274 |
get_request $client, $path, $param; |
get_request $client, $path, $param; |
275 |
} else { |
} else { |
276 |
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"; |