Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make Interchange reopen debug.log/STDERR when receiving HUP signal
Co-authored-by: David Christensen <david@endpoint.com>
Co-authored-by: Jon Jensen <jon@endpoint.com>
  • Loading branch information
David Christensen and jonjensen committed Jul 9, 2018
1 parent 586e5a9 commit f2fec38
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/Vend/Server.pm
Expand Up @@ -1258,6 +1258,13 @@ sub sig_int_or_term {
return;
}

sub sig_hup {
$Signal_Restart = 1;
my $am_master = ($Vend::MasterProcess == $$);
warn "Re-opening log...\n" if $am_master;
setup_debug_log(!$am_master);
}

unless ($Global::Windows) {
push @trapped_signals, qw(HUP USR1 USR2);
}
Expand Down Expand Up @@ -1310,7 +1317,7 @@ sub setup_signals {
else {
$SIG{INT} = \&sig_int_or_term;
$SIG{TERM} = \&sig_int_or_term;
$SIG{HUP} = sub { $Signal_Restart = 1; };
$SIG{HUP} = \&sig_hup;
$SIG{USR1} = sub { $Num_servers++; };
$SIG{USR2} = sub { $Num_servers--; };
}
Expand Down Expand Up @@ -1390,6 +1397,7 @@ sub housekeeping {
}

foreach my $pid (@active_pids) {
kill('HUP', $pid) and next if $Signal_Restart;
kill(0, $pid) and next;
#::logDebug("Non-existent server at PID %s", $pid);
delete $Page_pids{$pid};
Expand Down Expand Up @@ -1460,6 +1468,8 @@ sub housekeeping {
($jobs) = grep $_ eq 'jobsqueue', @files
if $do->{jobs};

undef $Signal_Restart;

if($do_before) {
for(@$do_before) {
#::logDebug("run before macro $_");
Expand All @@ -1480,7 +1490,6 @@ sub housekeeping {
my $respawn;

if (defined $restart) {
$Signal_Restart = 0;
open(Vend::Server::RESTART, "+<$Global::RunDir/restart")
or die "open $Global::RunDir/restart: $!\n";
lockfile(\*Vend::Server::RESTART, 1, 1)
Expand Down Expand Up @@ -2520,11 +2529,13 @@ sub send_ipc {
}

sub setup_debug_log {
my $quiet = shift;
if ($Global::DebugFile) {
open(Vend::DEBUG, ">>$Global::DebugFile");
close Vend::DEBUG;
open Vend::DEBUG, '>>', $Global::DebugFile;
select Vend::DEBUG;
$| = 1;
print "Start DEBUG at " . localtime() . "\n" unless $Global::SysLog;
print "Start DEBUG at " . localtime() . "\n" unless $Global::SysLog or $quiet;
}
elsif (!$Global::DEBUG) {
# May as well turn warnings off, not going anywhere
Expand Down

0 comments on commit f2fec38

Please sign in to comment.