Patch to prevent bounces in PostMaster.pl for transient errors

I realize this may be a little late to get into 1.2, but here it is anyway. It wraps much of PostMaster.pl in an eval{} block so that if the database isn't available (for example), an incoming message won't be immediately bounced. This patch is against CVS; I haven't been using the CVS version of OTRS, but I have been using a nearly identical patch against 1.1.3 for several months without any trouble (with several hundred tickets a day), and it has prevented several bounces during database upgrades, etc. Note that although it looks like it changes a lot, it really changes hardly anything -- most of the "changes" are just fixing the indentation. diff -c PostMaster.pl.orig PostMaster.pl *** PostMaster.pl.orig Wed Oct 29 13:07:41 2003 --- PostMaster.pl Mon Feb 9 15:20:08 2004 *************** *** 65,113 **** $Opts{'q'} = ''; } ! # -- ! # create common objects ! # -- ! my %CommonObject = (); ! $CommonObject{ConfigObject} = Kernel::Config->new(); ! $CommonObject{LogObject} = Kernel::System::Log->new( ! LogPrefix => 'OTRS-PM', ! %CommonObject, ! ); ! $CommonObject{DBObject} = Kernel::System::DB->new(%CommonObject); ! # debug info ! if ($Opts{'d'}) { ! $CommonObject{LogObject}->Log( ! Priority => 'debug', ! Message => 'Global OTRS email handle (PostMaster.pl) started...', ); ! } ! # get email from SDTIN ! my @Email = <STDIN>; ! if (!@Email) { ! $CommonObject{LogObject}->Log( ! Priority => 'error', ! Message => 'Got not email on STDIN!', ); ! exit (1); ! } ! # common objects ! $CommonObject{PostMaster} = Kernel::System::PostMaster->new( ! %CommonObject, ! Email => \@Email, ! Trusted => $Opts{'t'}, ! Debug => $Opts{'d'}, ! ); ! $CommonObject{PostMaster}->Run( ! Queue => $Opts{'q'}, ! ); ! ! # debug info ! if ($Opts{'d'}) { ! $CommonObject{LogObject}->Log( ! Priority => 'debug', ! Message => 'Global OTRS email handle (PostMaster.pl) stoped.', ); } # -- exit (0); --- 65,129 ---- $Opts{'q'} = ''; } ! # Wrap the majority of the script in an "eval" block so that any unexpected ! # (but possibly transient) fatal errors (such as the database being ! # unavailable) can be trapped without causing a bounce. ! eval { ! # -- ! # create common objects ! # -- ! my %CommonObject = (); ! $CommonObject{ConfigObject} = Kernel::Config->new(); ! $CommonObject{LogObject} = Kernel::System::Log->new( ! LogPrefix => 'OTRS-PM', ! %CommonObject, ); ! $CommonObject{DBObject} = Kernel::System::DB->new(%CommonObject); ! # debug info ! if ($Opts{'d'}) { ! $CommonObject{LogObject}->Log( ! Priority => 'debug', ! Message => 'Global OTRS email handle (PostMaster.pl) started...', ! ); ! } ! # get email from SDTIN ! my @Email = <STDIN>; ! if (!@Email) { ! $CommonObject{LogObject}->Log( ! Priority => 'error', ! Message => 'Got not email on STDIN!', ! ); ! exit (1); ! } ! # common objects ! $CommonObject{PostMaster} = Kernel::System::PostMaster->new( ! %CommonObject, ! Email => \@Email, ! Trusted => $Opts{'t'}, ! Debug => $Opts{'d'}, ); ! $CommonObject{PostMaster}->Run( ! Queue => $Opts{'q'}, ); + + # debug info + if ($Opts{'d'}) { + $CommonObject{LogObject}->Log( + Priority => 'debug', + Message => 'Global OTRS email handle (PostMaster.pl) stoped.', + ); + } + }; # end of eval block + + if ($@) + { + # Some kind of unexpected problem occurred (for example, database + # unavailable). Return an EX_TEMPFAIL error to cause the mail program + # to requeue the message instead of immediately bouncing it; see + # sysexits.h. (Most mail programs will retry an EX_TEMPFAIL delivery + # for about four days, then bounce the message.) + exit 75; } + # -- exit (0); -- Robert L Mathews, Tiger Technologies http://www.tigertech.net/ "Ignorance more frequently begets confidence than does knowledge." -- Darwin

Hi Robert, opps I remember. I add it to the cvs for the next release. Thanks! -Martin On Mon, Feb 09, 2004 at 04:14:54PM -0800, Robert L Mathews wrote:
I realize this may be a little late to get into 1.2, but here it is anyway. It wraps much of PostMaster.pl in an eval{} block so that if the database isn't available (for example), an incoming message won't be immediately bounced.
This patch is against CVS; I haven't been using the CVS version of OTRS, but I have been using a nearly identical patch against 1.1.3 for several months without any trouble (with several hundred tickets a day), and it has prevented several bounces during database upgrades, etc.
Note that although it looks like it changes a lot, it really changes hardly anything -- most of the "changes" are just fixing the indentation.
diff -c PostMaster.pl.orig PostMaster.pl *** PostMaster.pl.orig Wed Oct 29 13:07:41 2003 --- PostMaster.pl Mon Feb 9 15:20:08 2004 *************** *** 65,113 **** $Opts{'q'} = ''; }
! # -- ! # create common objects ! # -- ! my %CommonObject = (); ! $CommonObject{ConfigObject} = Kernel::Config->new(); ! $CommonObject{LogObject} = Kernel::System::Log->new( ! LogPrefix => 'OTRS-PM', ! %CommonObject, ! ); ! $CommonObject{DBObject} = Kernel::System::DB->new(%CommonObject); ! # debug info ! if ($Opts{'d'}) { ! $CommonObject{LogObject}->Log( ! Priority => 'debug', ! Message => 'Global OTRS email handle (PostMaster.pl) started...', ); ! } ! # get email from SDTIN ! my @Email = <STDIN>; ! if (!@Email) { ! $CommonObject{LogObject}->Log( ! Priority => 'error', ! Message => 'Got not email on STDIN!', ); ! exit (1); ! } ! # common objects ! $CommonObject{PostMaster} = Kernel::System::PostMaster->new( ! %CommonObject, ! Email => \@Email, ! Trusted => $Opts{'t'}, ! Debug => $Opts{'d'}, ! ); ! $CommonObject{PostMaster}->Run( ! Queue => $Opts{'q'}, ! ); ! ! # debug info ! if ($Opts{'d'}) { ! $CommonObject{LogObject}->Log( ! Priority => 'debug', ! Message => 'Global OTRS email handle (PostMaster.pl) stoped.', ); } # -- exit (0); --- 65,129 ---- $Opts{'q'} = ''; }
! # Wrap the majority of the script in an "eval" block so that any unexpected ! # (but possibly transient) fatal errors (such as the database being ! # unavailable) can be trapped without causing a bounce. ! eval { ! # -- ! # create common objects ! # -- ! my %CommonObject = (); ! $CommonObject{ConfigObject} = Kernel::Config->new(); ! $CommonObject{LogObject} = Kernel::System::Log->new( ! LogPrefix => 'OTRS-PM', ! %CommonObject, ); ! $CommonObject{DBObject} = Kernel::System::DB->new(%CommonObject); ! # debug info ! if ($Opts{'d'}) { ! $CommonObject{LogObject}->Log( ! Priority => 'debug', ! Message => 'Global OTRS email handle (PostMaster.pl) started...', ! ); ! } ! # get email from SDTIN ! my @Email = <STDIN>; ! if (!@Email) { ! $CommonObject{LogObject}->Log( ! Priority => 'error', ! Message => 'Got not email on STDIN!', ! ); ! exit (1); ! } ! # common objects ! $CommonObject{PostMaster} = Kernel::System::PostMaster->new( ! %CommonObject, ! Email => \@Email, ! Trusted => $Opts{'t'}, ! Debug => $Opts{'d'}, ); ! $CommonObject{PostMaster}->Run( ! Queue => $Opts{'q'}, ); + + # debug info + if ($Opts{'d'}) { + $CommonObject{LogObject}->Log( + Priority => 'debug', + Message => 'Global OTRS email handle (PostMaster.pl) stoped.', + ); + } + }; # end of eval block + + if ($@) + { + # Some kind of unexpected problem occurred (for example, database + # unavailable). Return an EX_TEMPFAIL error to cause the mail program + # to requeue the message instead of immediately bouncing it; see + # sysexits.h. (Most mail programs will retry an EX_TEMPFAIL delivery + # for about four days, then bounce the message.) + exit 75; } + # -- exit (0);
-- Robert L Mathews, Tiger Technologies http://www.tigertech.net/
"Ignorance more frequently begets confidence than does knowledge." -- Darwin
_______________________________________________ OTRS mailing list: dev - Webpage: http://otrs.org/ Archive: http://lists.otrs.org/pipermail/dev To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/dev
Martin Edenhofer -- ((otrs.de)) :: OTRS GmbH :: Norsk-Data-Str. 1 :: 61352 Bad Homburg http://www.otrs.de/ :: Manage your communication!
participants (2)
-
Martin Edenhofer
-
Robert L Mathews