[rt-users] DB down, tickets go to the bit bucket

Aaron Turner aturner at netscreen.com
Tue Aug 12 14:22:23 EDT 2003


Hey Ben,

What i did was use a wrapper script (see attached) which detects the 
return value of rt-mailgate and sleeps for a specified period of time 
and tries again (and again) until success.

Basically, I call the wrapper via procmail (but you prolly could do it
via your /etc/aliases file too):

:0 w
| $HOME/bin/resubmit.pl -t 5 -f 12 -c '/usr/local/rt3/bin/rt-mailgate
--queue MyQueue --action comment --url https://rt.mycompany.com/'

On Tue, Aug 12, 2003 at 10:46:54AM -0700, Ben Browning wrote:
> Hi all,
> 
> I am running RT2 with MySQL and Sendmail.
> 
> For a long time it has bothered me that when the DB goes down (nearly 
> never, but you never know) tickets get horked mightily. This happens 
> because the RT mail-ripper script can't access the DB, so it just drops the 
> payload.
> 
> Is there a workaround for this? As it stands I just monitor the DB closely 
> and when it goes down I bring down sendmail on the box, allowing mail to 
> queue at a backup MX.
-------------- next part --------------
#!/usr/bin/perl -w

# This script is a wrapper for procmail which should be called like:
# | resubmit.pl -t 5 -f 60 -c "/dir/dir2/script_to_execute script options"

# This wrapper, checks the exit code of the above script.  If it fails
# (exit code != 0), it sleeps for -t  minutes and trys again until success
# -f 12 says to return exit(1) after 12 tries.  use -f 0 to try forever


use strict;
use Carp;
use Getopt::Std;
use File::Temp qw/tempfile/;
use integer; # always use integer math

my $DEBUG = 0;

use vars qw/$opt_c $opt_t $opt_f/;
getopts("c:t:f:");

# default sleep delay is 5 minute
my $sleep = $opt_t ? $opt_t * 60 : 5 * 60;

# default fail count is 1 hour
my $failcount = (defined $opt_f) ? $opt_f : 60 / ($sleep / 60);

# script to run
my $script = $opt_c;

# read in STDIN
my @data = <STDIN>;

# create temp file
my ($fh, $filename) = tempfile ( DIR => '/tmp' );
print $fh @data;

print STDERR "Tempfile: $filename\n" if ($DEBUG);

# default forces try
my $exit_value = 1;
my $numfail = 0;

while ($exit_value) {
  system("cat $filename | $script");
  $exit_value = $? >> 8;

  print STDERR "Exit code: $exit_value\n" if ($DEBUG);

  # sleep only on failure
  if ($exit_value) {
    $numfail ++;
    if ($numfail == $failcount) {
      exit 1;
    }
    print STDERR "Sleeping for $sleep seconds\n" if ($DEBUG);
    sleep($sleep);
  }
}

print STDERR "Cleaning up\n" if ($DEBUG);
# delete temp file
unlink $filename;
exit 0;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 244 bytes
Desc: not available
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20030812/9eb2acc3/attachment.sig>


More information about the rt-users mailing list