Bugfix: after rotate_logs, restarter() may have a stale PID (#840)
* when rotate_logs restarts the process due to the file being above the size limit, the new PID is not returned to the caller * this leads to signal_child signaling the old, non-existing PID and subsequently a second master process being started * fixed by returning the PID from rotate_logs
This commit is contained in:
committed by
GitHub
parent
2e4ef7bbdf
commit
ad6df1fae6
@@ -96,7 +96,6 @@ my $child = 0;
|
|||||||
sub restarter {
|
sub restarter {
|
||||||
my ($daemon, @program_args) = @_;
|
my ($daemon, @program_args) = @_;
|
||||||
$0 = 'netdisco-backend';
|
$0 = 'netdisco-backend';
|
||||||
|
|
||||||
$child = fork_and_start($daemon, @program_args);
|
$child = fork_and_start($daemon, @program_args);
|
||||||
exit(1) unless $child;
|
exit(1) unless $child;
|
||||||
|
|
||||||
@@ -129,8 +128,7 @@ sub restarter {
|
|||||||
++$hupit;
|
++$hupit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$child = rotate_logs($child, $daemon, @program_args) if $rotate;
|
||||||
rotate_logs($child, $daemon, @program_args) if $rotate;
|
|
||||||
if ($hupit) {
|
if ($hupit) {
|
||||||
signal_child('TERM', $child);
|
signal_child('TERM', $child);
|
||||||
$child = fork_and_start($daemon, @program_args);
|
$child = fork_and_start($daemon, @program_args);
|
||||||
@@ -163,8 +161,7 @@ sub signal_child {
|
|||||||
|
|
||||||
sub rotate_logs {
|
sub rotate_logs {
|
||||||
my $child = shift;
|
my $child = shift;
|
||||||
|
return $child unless (-f $log_file) and
|
||||||
return unless (-f $log_file) and
|
|
||||||
((-s $log_file) > ($logsize * 1024768));
|
((-s $log_file) > ($logsize * 1024768));
|
||||||
|
|
||||||
my @files = grep { /$log_file\.\d+/ } glob file($log_dir, '*');
|
my @files = grep { /$log_file\.\d+/ } glob file($log_dir, '*');
|
||||||
@@ -184,11 +181,15 @@ sub rotate_logs {
|
|||||||
rename $log_file, $log_file .'.1';
|
rename $log_file, $log_file .'.1';
|
||||||
signal_child('TERM', $child);
|
signal_child('TERM', $child);
|
||||||
$child = fork_and_start(@_);
|
$child = fork_and_start(@_);
|
||||||
exit(1) unless $child;
|
if ($child){
|
||||||
|
return $child;
|
||||||
|
}else{
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
copy $log_file, $log_file .'.1';
|
copy $log_file, $log_file .'.1';
|
||||||
truncate $log_file, 0;
|
truncate $log_file, 0;
|
||||||
|
return $child;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user