ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-Watchdog/Watchdog.pm
(Generate patch)

Comparing AnyEvent-Watchdog/Watchdog.pm (file contents):
Revision 1.5 by root, Fri Aug 14 23:08:54 2009 UTC vs.
Revision 1.6 by root, Sun Aug 30 17:20:27 2009 UTC

38Use AnyEvent::Watchdog to automatically restart the program 38Use AnyEvent::Watchdog to automatically restart the program
39when it fails to handle events for longer than 5 minutes: 39when it fails to handle events for longer than 5 minutes:
40 40
41 use AnyEvent::Watchdog qw(autorestart heartbeat=300); 41 use AnyEvent::Watchdog qw(autorestart heartbeat=300);
42 42
43=head1 FUNCTIONS 43=head1 VARIABLES/FUNCTIONS
44 44
45The module supports the following functions: 45The module supports the following variables and functions:
46 46
47=over 4 47=over 4
48 48
49=cut 49=cut
50 50
55 55
56use Carp (); 56use Carp ();
57 57
58our $VERSION = '0.9'; 58our $VERSION = '0.9';
59 59
60=item $AnyEvent::Watchdog::ENABLED
61
62This is true when the program is running under the regime of
63AnyEvent::Watchdog. Semi-obviously, you should I<NOT> C<use> or C<require>
64this module before looking at this variable, and neither should you try
65to load this module unless in the main program, rather use an idiom like
66this:
67
68 $AnyEvent::Watchdog::ENABLED
69 or die "watchdog not enabled...";
70 AnyEvent::Watchdog::restart (60); # MUST use ()
71
72Note that if this variable is defined, but false, then AnyEvent::Watchdog
73is running, but you are in the watchdog process - you probably did
74something very wrong in this case.
75
76=cut
77
60our $PID; # child pid 78our $PID; # child pid
61our $ENABLED = 1; 79our $ENABLED = 0;
62our $AUTORESTART; # actually exit 80our $AUTORESTART; # actually exit
63our $HEARTBEAT; 81our $HEARTBEAT;
64our ($P, $C); 82our ($P, $C);
65 83
66sub poll($) { 84sub poll($) {
203 221
204 unless (defined $PID) { 222 unless (defined $PID) {
205 warn "AnyEvent::Watchdog: '$!', retrying in one second...\n"; 223 warn "AnyEvent::Watchdog: '$!', retrying in one second...\n";
206 sleep 1; 224 sleep 1;
207 } elsif ($PID) { 225 } elsif ($PID) {
226 # parent code
208 close $C; 227 close $C;
209 server; 228 server;
210 } else { 229 } else {
230 # child code
231 $ENABLED = 1;
232
211 # restore seek offsets 233 # restore seek offsets
212 while (my ($k, $v) = each %SEEKPOS) { 234 while (my ($k, $v) = each %SEEKPOS) {
213 open my $fh, "<&$k" or next; 235 open my $fh, "<&$k" or next;
214 sysseek $fh, $v, 0; 236 sysseek $fh, $v, 0;
215 } 237 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines