Commit e58e7fb8 authored by olivier.salaun's avatar olivier.salaun
Browse files

New feature: STDERR of daemons is redirected to a file. If process crashes,

next process started will detect the failure and send a notice to listmaster.


git-svn-id: https://subversion.renater.fr/sympa/trunk@4142 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent 01473812
......@@ -45,6 +45,22 @@ Content-Transfer-Encoding: [%|loc%]_encoding_[%END%]
[%|loc(db_type)%]No Database Driver installed for %1 ; you should download and install DBD::%1 from CPAN.[%END%]
[% ELSIF type == 'crash' -%]
Subject: [% FILTER qencode %][%|loc%]Process crashed[%END%][%END%]
MIME-Version: 1.0
Content-Type: text/plain; charset=[% charset %];
Content-Transfer-Encoding: [%|loc%]_encoding_[%END%]
[%|loc%]Previous process has died unexpectedly.[%END%]
[%|loc(crash_date)%]Date of crash : %1[%END%]
[%|loc%]Errors:[%END%]
[% FOREACH err IN crash_err%]
[% err %]
[% END %]
[%|loc%]Check log file for further details.[%END%]
[% ELSIF type == 'upgrade_failed' -%]
Subject: [% FILTER qencode %][%|loc%]Upgrade procedures failed[%END%][%END%]
MIME-Version: 1.0
......
......@@ -246,8 +246,9 @@ if ($signal ne 'hup') {
close(TTY);
}
open(STDIN, ">> /dev/null");
open(STDERR, ">> /dev/null");
open(STDOUT, ">> /dev/null");
open(STDERR, ">> /dev/null");
setpgrp(0, 0);
# start the main sympa.pl daemon
......@@ -318,6 +319,7 @@ if ($signal ne 'hup') {
do_log('debug', "Running server $$ for $service purpose ");
unless ($main::options{'batch'} ) {
## Create and write the pidfile
my $file = $Conf{'pidfile'};
$file = $Conf{'pidfile_distribute'} if ($main::daemon_usage == DAEMON_MESSAGE) ;
......@@ -994,10 +996,8 @@ List::db_disconnect if ($List::dbh);
} #end of block while ($signal ne 'term'){
do_log('notice', 'Sympa exited normally due to signal');
unless (unlink $Conf{'pidfile'}) {
fatal_err("Could not delete %s, exiting", $Conf{'pidfile'});
## No return.
}
&tools::remove_pid($Conf{'pidfile'}, $$);
exit(0);
......
......@@ -377,9 +377,8 @@ while (!$end) {
}
&do_log ('notice', 'task_manager exited normally due to signal');
unless (unlink $wwsconf->{'task_manager_pidfile'}) {
fatal_err("Could not delete %s, exiting", $wwsconf->{'task_manager_pidfile'});
}
&tools::remove_pid($wwsconf->{'task_manager_pidfile'}, $$);
exit(0);
####### SUBROUTINES #######
......
......@@ -1991,6 +1991,26 @@ sub qencode_hierarchy {
return $count;
}
## Remove PID file and STDERR output
sub remove_pid {
my ($pidfile, $pid) = @_;
unless (unlink $pidfile) {
&do_log('err', "Failed to remove $pidfile: %s", $!);
return undef;
}
my $err_file = $Conf{'tmpdir'}.'/'.$pid.'.stderr';
if (-f $err_file) {
unless (unlink $err_file) {
&do_log('err', "Failed to remove $err_file: %s", $!);
return undef;
}
}
return 1;
}
sub write_pid {
my ($pidfile, $pid) = @_;
......@@ -2007,6 +2027,14 @@ sub write_pid {
chown $uid, $gid, $piddir;
## If pidfile exists, read the PID and get date
my ($other_pid);
if (-f $pidfile) {
open PFILE, $pidfile;
$other_pid = <PFILE>; chomp $other_pid;
close PFILE;
}
## Create and write the pidfile
unless (open(LOCK, "+>> $pidfile")) {
fatal_err('Could not open %s, exiting', $pidfile);
......@@ -2014,6 +2042,25 @@ sub write_pid {
unless (flock(LOCK, 6)) {
fatal_err('Could not lock %s, process is probably already running : %s', $pidfile, $!);
}
## The previous process died suddenly, without pidfile cleanup
## Send a notice to listmaster with STDERR of the previous process
if ($other_pid) {
&do_log('notice', "Previous process $other_pid died suddenly ; notifying listmaster");
my $err_file = $Conf{'tmpdir'}.'/'.$other_pid.'.stderr';
my (@err_output, $err_date);
if (-f $err_file) {
open ERR, $err_file;
@err_output = <ERR>;
close ERR;
$err_date = &POSIX::strftime("%d %b %Y %H:%M", localtime( (stat($err_file))[9]));
}
&List::send_notify_to_listmaster('crash', $Conf::Conf{'domain'},
{'crash_err' => \@err_output, 'crash_date' => $err_date});
}
unless (open(LCK, "> $pidfile")) {
fatal_err('Could not open %s, exiting', $pidfile);
}
......@@ -2026,6 +2073,10 @@ sub write_pid {
chown $uid, $gid, $pidfile;
## Error output is stored in a file with PID-based name
## Usefull if process crashes
open(STDERR, '>>', $Conf{'tmpdir'}.'/'.$pid.'.stderr');
return 1;
}
......
......@@ -339,7 +339,7 @@ while (!$end) {
}
}
do_log('notice', 'archived exited normally due to signal');
unlink("$wwsconf->{'archived_pidfile'}");
&tools::remove_pid($wwsconf->{'archived_pidfile'}, $$);
exit(0);
......
......@@ -492,7 +492,7 @@ while (!$end) {
}
do_log('notice', 'bounced exited normally due to signal');
unlink("$wwsconf->{'bounced_pidfile'}");
&tools::remove_pid($wwsconf->{'bounced_pidfile'}, $$);
exit(0);
......
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