CONNECT: $socket = IO::Socket::INET->new("$host:$port"); unless ($socket) { # Potential Problem here $retry++; if($retry==3) { log_die ("Client : Error connecting to server ... $@\n"); } log_notice ("Client : Retry $retry : Sleeping $timeout Seconds\n"); sleep($timeout); # wait a minute; goto CONNECT; } $retry=0; #Reset in case we disconnect early $connected=1; #So that we know... #Start from beginning, uncomment if you don't want too $recover_from=is_recovery($dbh); $recover_from++; $rec_num=0; $stCnt->finish; if ($recover_mode) { log_notice ("Client : Begin recovery mode from record number $recover_from\n"); } $SIG{TERM}=$SIG{INT}=$SIG{PIPE}=$SIG{CHLD} = sub { my $sig=shift; if (defined $sth) { $sth->finish; } if (defined $dbh ) { $dbh->disconnect; } if (defined $socket) { $socket->shutdown(2); } sleep(5); do { $pid = waitpid(-1,&WNOHANG); } until $pid == -1; log_notice ("Client : Caught signal SIG$sig\n"); if($sig eq 'PIPE') { log_notice ("Connection Ended\n"); } if($sig eq 'TERM' || $sig eq 'HUP' || $sig eq 'INT') { log_notice ("User Cancelling?\n"); exit 1; #User cancelling job ? } if ($connected) { ############################################################# # First check to see if this is early termination # Should only terminate at midnight. If this is # an early termination the assumption is that the # system we were connected to has croaked. If the # current time is less than $midnight then we try # to exec to ourself (RESTART..) where, hopefully # we will reconnect and recover where we left off # or give up after three times the $timeout. ############################################################# $timestamp=time; if($timestamp < $midnight) { log_notice ("Client : Restarting $0\n"); log_error("End Processing $src_cdr_file\n"); exec '/home/$0' || log_warn ("Client : Could not exec $0\n"); exit 6; # Something is wrong if this exit is taken } # End if $timestamp log_notice ("Client : Normal Termination\n"); log_error("End Processing $src_cdr_file\n\n"); exec '/usr/bin/perl', '/home/client' || log_warn ("Client : Could not exec $0\n"); exit 7; # Something is wrong if this exit is taken } # End if $connected }; # End anonymous sub print $socket "tail\n"; # Rock n Roll