line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FCGI::Restarter; |
2
|
1
|
|
|
1
|
|
24570
|
use 5.008001; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
40
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
4
|
1
|
|
|
1
|
|
1145
|
use Class::Accessor::Tiny qw( new poll_interval watch_file script onidle onaccept); |
|
1
|
|
|
|
|
14
|
|
|
1
|
|
|
|
|
7
|
|
5
|
1
|
|
|
1
|
|
860
|
use FCGI; |
|
1
|
|
|
|
|
1225
|
|
|
1
|
|
|
|
|
601
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.12'; |
7
|
|
|
|
|
|
|
our @expect_file; |
8
|
|
|
|
|
|
|
our %file; |
9
|
|
|
|
|
|
|
our $restart_file = "/home/sites/combats.ru/web/start.pl"; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $STDIN_fileno = fileno STDIN; |
12
|
|
|
|
|
|
|
my $count; |
13
|
|
|
|
|
|
|
my $start; |
14
|
|
|
|
|
|
|
sub new_request{ |
15
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
16
|
0
|
0
|
|
|
|
|
-t STDIN && return FCGI::accept() >= 0; |
17
|
0
|
|
|
|
|
|
my $wait = 0; |
18
|
0
|
0
|
|
|
|
|
FCGI::finish() if $start; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
do { |
21
|
0
|
|
|
|
|
|
my @vector = ( '', '', '' ); |
22
|
0
|
|
|
|
|
|
vec( $_, $STDIN_fileno, 1) = 1 for ( $vector[0] ); |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
0
|
|
|
|
my $found = select $vector[0], $vector[1], $vector[2], $self->get_poll_interval() ||5; |
25
|
0
|
0
|
|
|
|
|
if ( vec( $vector[0], $STDIN_fileno, 1 )){ |
26
|
0
|
|
|
|
|
|
my $onaccept = $self->get_onaccept(); |
27
|
0
|
0
|
|
|
|
|
$onaccept->() if ref $onaccept eq 'CODE'; |
28
|
0
|
|
|
|
|
|
$wait = 1; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
else { |
31
|
0
|
0
|
|
|
|
|
exit 1 if $found < 0 ; |
32
|
0
|
|
|
|
|
|
my $onidle = $self->get_onidle(); |
33
|
0
|
0
|
|
|
|
|
$onidle->() if ref $onidle eq 'CODE'; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
until( $wait > 0); |
37
|
|
|
|
|
|
|
|
38
|
0
|
0
|
|
|
|
|
if ( ! if_modified ( $self ) ){ |
39
|
0
|
|
|
|
|
|
$start = 1; |
40
|
0
|
|
|
|
|
|
return FCGI::accept()>=0; |
41
|
|
|
|
|
|
|
} |
42
|
0
|
|
|
|
|
|
my $restart_file = $self->get_script(); |
43
|
0
|
|
|
|
|
|
exec "$restart_file"; |
44
|
|
|
|
|
|
|
}; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my %watch_file; |
47
|
|
|
|
|
|
|
sub if_modified{ |
48
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
49
|
0
|
0
|
|
|
|
|
if ( $start ){ |
50
|
0
|
|
|
|
|
|
my $files = $self->get_watch_file(); |
51
|
0
|
0
|
|
|
|
|
my $afiles = ref $files ? $files : [ $files ]; |
52
|
0
|
|
|
|
|
|
for ( @$afiles ){ |
53
|
0
|
|
|
|
|
|
my ( $mtime ) = (stat $_)[9]; |
54
|
0
|
0
|
|
|
|
|
if ( $mtime != $watch_file{ $_ }{mtime} ){ |
55
|
0
|
|
|
|
|
|
return 1; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
0
|
|
|
|
|
|
return ! $files; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
else { |
61
|
0
|
|
|
|
|
|
my $files = $self->get_watch_file(); |
62
|
0
|
0
|
|
|
|
|
$files = [ $files ] if ! ref $files; |
63
|
0
|
|
|
|
|
|
for ( @$files ){ |
64
|
0
|
|
|
|
|
|
my ( $mtime ) = (stat $_)[9]; |
65
|
0
|
|
|
|
|
|
$watch_file{ $_ }{mtime} = $mtime; |
66
|
|
|
|
|
|
|
} |
67
|
0
|
|
|
|
|
|
return 0; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
__END__ |