I have two perl scripts on a server that tail a file on another system and writing records to a db. One is always active, and one is always backup. If the first server fails, the second kicks on and the second script begins tailing that backup box for records. This is done using IO::Socket.
The section I am posting below is creating the socket I believe. But would like more understanding on what it's doing. Like what is it looking for with the TERM, INT, PIPE, CHLD?
What is the TERM, HUP, INT all about? Is that how it determines if there was a user sent command to shutdown, or if it was a crash, or if it just shut itself down?
Thank you for any input
$SIG{TERM}=$SIG{INT}=$SIG{PIPE}=$SIG{CHLD} = sub {
my $sig=shift;
if (defined $sth) { $sth->finish; }
if (defined $stDst) { $stDst->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) {
$timestamp=time;
if($timestamp < $midnight) {
log_notice ("Client : Restarting $0\n");
log_error("End Processing $src_cdr_file\n");
exec '/home/user/$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/user/$0' ||
log_warn ("Client : Could not exec $0\n");
exit 7; # Something is wrong if this exit is taken
} # End if $connected
}; # End anonymous sub
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.