Commit b2552804 authored by sikeda's avatar sikeda
Browse files

[bug] (probably fixes bug[#6204]) task_manager.pl sometimes ignores signal to...

[bug] (probably fixes bug[#6204]) task_manager.pl sometimes ignores signal to shutdown it.  If there are large number of lists, calling get_lists() can take long time and the process cannot deal with TERM signal.
Now get_lists() checks HUP, INT and TERM signals and returns immediately when signal is raised.  As a side effect of this fix, get_lists() may return undef.


git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@12052 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent 378d1f78
......@@ -9109,6 +9109,16 @@ sub get_lists {
my $that = shift || '*';
my %options = @_;
# Set signal handler so that long call can be aborted by signal.
my $signalled;
my %sighandler = (HUP => $SIG{HUP}, INT => $SIG{INT}, TERM => $SIG{TERM});
local $SIG{HUP} = sub { $sighandler{HUP}->(@_); $signalled = 1; }
if ref $SIG{HUP} eq 'CODE';
local $SIG{INT} = sub { $sighandler{INT}->(@_); $signalled = 1; }
if ref $SIG{INT} eq 'CODE';
local $SIG{TERM} = sub { $sighandler{TERM}->(@_); $signalled = 1; }
if ref $SIG{TERM} eq 'CODE';
my (@lists, @robot_ids, $family_name);
if (ref $that and ref $that eq 'Sympa::Family') {
......@@ -9361,6 +9371,9 @@ sub get_lists {
my $limit = $options{'limit'} || undef;
my $count = 0;
# Check signal at first.
return undef if $signalled;
foreach my $robot_id (@robot_ids) {
if (!Sympa::Tools::Data::smart_eq($Conf::Conf{'db_list_cache'}, 'on')
or $options{'reload_config'}) {
......@@ -9431,6 +9444,8 @@ sub get_lists {
my @l = ();
foreach my $listname (sort @requested_lists) {
return undef if $signalled;
## create object
my $list = __PACKAGE__->new(
$listname,
......@@ -9513,6 +9528,8 @@ sub get_lists {
$sth = pop @sth_stack;
foreach my $listname (@requested_lists) {
return undef if $signalled;
my $list = __PACKAGE__->new(
$listname,
$robot_id,
......
......@@ -184,7 +184,7 @@ $log->syslog('notice', 'Archived %s Started', Sympa::Constants::VERSION);
## Catch signals, in order to exit cleanly, whenever possible.
$SIG{'TERM'} = 'sigterm';
$SIG{'INT'} = \&sigterm;
$SIG{'INT'} = 'sigterm';
my $end = 0;
my $queue = $Conf::Conf{'queueoutgoing'};
......
......@@ -198,7 +198,7 @@ $log->syslog('notice', 'Bounced %s Started', Sympa::Constants::VERSION());
## Catch signals, in order to exit cleanly, whenever possible.
$SIG{'TERM'} = 'sigterm';
$SIG{'INT'} = \&sigterm;
$SIG{'INT'} = 'sigterm';
my $end = 0;
my $spool = $Conf::Conf{'queuebounce'};
......
......@@ -174,7 +174,7 @@ $log->syslog('notice', 'Bulk %s Started', Sympa::Constants::VERSION);
## Catch signals, in order to exit cleanly, whenever possible.
$SIG{'TERM'} = 'sigterm';
$SIG{'INT'} = \&sigterm;
$SIG{'INT'} = 'sigterm';
my $end = 0;
my $timeout = $Conf::Conf{'bulk_wait_to_fork'};
......
......@@ -174,9 +174,9 @@ if ($main::options{'keepcopy'}) {
# Catch signals, in order to exit cleanly, whenever possible.
my $signal = 0;
$SIG{'TERM'} = 'sigterm';
$SIG{'INT'} = \&sigterm; # Interrupt from terminal.
$SIG{'INT'} = 'sigterm'; # Interrupt from terminal.
$SIG{'HUP'} = 'sighup';
$SIG{'PIPE'} = 'IGNORE'; ## Ignore SIGPIPE ; prevents process from dying
$SIG{'PIPE'} = 'IGNORE'; # Ignore SIGPIPE ; prevents process from dying
# Main loop.
# This loop is run foreach HUP signal received.
......
......@@ -254,9 +254,9 @@ if ($main::options{'keepcopy'}) {
# Catch signals, in order to exit cleanly, whenever possible.
my $signal = 0;
$SIG{'TERM'} = 'sigterm';
$SIG{'INT'} = \&sigterm; # Interrupt from terminal.
$SIG{'INT'} = 'sigterm'; # Interrupt from terminal.
$SIG{'HUP'} = 'sighup';
$SIG{'PIPE'} = 'IGNORE'; ## Ignore SIGPIPE ; prevents process from dying
$SIG{'PIPE'} = 'IGNORE'; # Ignore SIGPIPE ; prevents process from dying
# Main loop.
# This loop is run foreach HUP signal received.
......
......@@ -159,7 +159,7 @@ unless (chdir($Conf::Conf{'home'})) {
}
## Catch signals, in order to exit cleanly, whenever possible.
$SIG{'TERM'} = 'sigterm';
$SIG{'TERM'} = \&sigterm;
$SIG{'INT'} = \&sigterm;
my $end = 0;
......@@ -305,11 +305,12 @@ while (!$end) {
}
}
## list tasks
# list tasks
foreach my $robot (Sympa::List::get_robots()) {
my $all_lists = Sympa::List::get_lists($robot);
foreach my $list (@$all_lists) {
last if $end;
foreach my $list (@{$all_lists || []}) {
my %data = %default_data;
$data{'list'} = {
......@@ -350,6 +351,7 @@ while (!$end) {
}
}
}
last if $end;
## Execute existing tasks
## List all tasks
......@@ -416,7 +418,6 @@ while (!$end) {
}
sleep 60;
#$end = 1;
## Free zombie sendmail processes
Sympa::Mailer->instance->reaper();
......@@ -1336,6 +1337,7 @@ sub purge_spools {
_clean_spool($directory, $clean_delay);
}
}
# Expiring bad packets and messages in bulk spool.
foreach my $subdir (qw(pct msg)) {
my $directory = $Conf::Conf{'queuebulk'} . '/bad/' . $subdir;
......@@ -1344,6 +1346,7 @@ sub purge_spools {
_clean_spool($directory, $clean_delay);
}
}
# Expiring moderation spools, topic spool and temporary files.
foreach my $queue (
qw(queueauth queueautomatic queuemod queuesubscribe queuetopic tmpdir)
......@@ -1354,6 +1357,7 @@ sub purge_spools {
_clean_spool($directory, $clean_delay);
}
}
# Expiring formatted held messages.
my $all_lists = Sympa::List::get_lists('*');
foreach my $list (@{$all_lists || []}) {
......@@ -1363,6 +1367,8 @@ sub purge_spools {
_clean_spool($directory, $clean_delay);
}
}
return 1;
}
# Old name: tools::CleanSpool(), Sympa::Tools::File::CleanDir().
......@@ -1412,7 +1418,9 @@ sub purge_tables {
$removed = 0;
foreach my $robot (Sympa::List::get_robots()) {
my $all_lists = Sympa::List::get_lists($robot);
foreach my $list (@$all_lists) {
return 1 if $end;
foreach my $list (@{$all_lists || []}) {
my $tracking = Sympa::Tracking->new($list);
$removed +=
......@@ -1539,13 +1547,8 @@ sub purge_orphan_bounces {
$log->syslog('info', '');
my $all_lists;
unless ($all_lists = Sympa::List::get_lists('*')) {
$log->syslog('notice', 'No list available');
return 1;
}
foreach my $list (@$all_lists) {
my $all_lists = Sympa::List::get_lists('*');
foreach my $list (@{$all_lists || []}) {
# First time: loading DB entries into %bounced_users,
# hash {'bounced address' => 1}
my %bounced_users;
......@@ -1601,19 +1604,18 @@ sub purge_orphan_bounces {
return 1;
}
# If a bounce is older than $list->get_latest_distribution_date() - $delay
# expire the bounce.
sub expire_bounce {
# If a bounce is older than $list->get_latest_distribution_date() - $delay
# expire the bounce.
# May this variable be set in to task model ?
$log->syslog('debug2', '(%s, %s, %s)', @_);
#FXIME: May this variable be set in to task model ?
my ($task, $Rarguments, $context) = @_;
my @tab = @{$Rarguments};
my $delay = $tab[0];
$log->syslog('debug2', '(%d)', $delay);
my $all_lists = Sympa::List::get_lists('*');
foreach my $list (@$all_lists) {
foreach my $list (@{$all_lists || []}) {
my $listname = $list->{'name'};
# the reference date is the date until which we expire bounces in
......@@ -1705,8 +1707,7 @@ sub eval_bouncers {
my ($task, $context) = @_;
my $all_lists = Sympa::List::get_lists('*');
foreach my $list (@$all_lists) {
foreach my $list (@{$all_lists || []}) {
my $listname = $list->{'name'};
my $list_traffic = {};
......@@ -1754,14 +1755,8 @@ sub none {
1;
}
## Routine for automatic bouncing users management
##
sub process_bouncers {
###################
my ($task, $context) = @_;
$log->syslog('info', 'Processing automatic actions on bouncing users');
###########################################################################
# Routine for automatic bouncing users management
#
# This sub apply a treatment foreach category of bouncing-users
#
# The relation between possible actions and correponding subroutines
......@@ -1773,7 +1768,9 @@ sub process_bouncers {
# - the name of the current list
# - a reference on users email list:
# Look at the "remove_bouncers" sub in List.pm for an example
###########################################################################
sub process_bouncers {
my ($task, $context) = @_;
$log->syslog('info', 'Processing automatic actions on bouncing users');
## possible actions
my %actions = (
......@@ -1783,17 +1780,15 @@ sub process_bouncers {
);
my $all_lists = Sympa::List::get_lists('*');
foreach my $list (@$all_lists) {
foreach my $list (@{$all_lists || []}) {
my $listname = $list->{'name'};
my @bouncers;
# @bouncers = ( ['email1', 'email2', 'email3',....,], There is one
# line
# ['email1', 'email2', 'email3',....,], foreach
# bounce
# ['email1', 'email2', 'email3',....,],) level.
next unless ($list);
# @bouncers = (
# ['email1', 'email2', 'email3',....,], There is one line
# ['email1', 'email2', 'email3',....,], foreach bounce
# ['email1', 'email2', 'email3',....,], level.
# );
my $max_level;
for (
......@@ -1967,6 +1962,9 @@ sub get_score {
## when we catch signal, just change the value of the loop variable.
sub sigterm {
my ($sig) = @_;
$log->syslog('notice',
'Signal %s received, still processing current task', $sig);
$end = 1;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment