From 90f6792c564760df2cf7abea34925182b40401ba Mon Sep 17 00:00:00 2001 From: erickson Date: Tue, 12 Oct 2010 14:53:41 +0000 Subject: [PATCH] implemented an optional per-service stderr log for capturing miscellaneous stderr output from services, similar to the old-style _unix.log files, since there are often useful warnings and error messages that never bubble up to syslog. for clarity, the files now use _stderr as a suffix instead of _unix. stderr logs are enabled by default. included opensrf.xml example of how to disable it for a given service git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@2035 9efc2488-bf62-4759-914b-345cdb29e865 --- examples/opensrf.xml.example | 3 +++ src/perl/lib/OpenSRF/Server.pm | 26 ++++++++++++++++++++------ src/perl/lib/OpenSRF/System.pm | 7 ++++++- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/examples/opensrf.xml.example b/examples/opensrf.xml.example index a213975..2747d70 100644 --- a/examples/opensrf.xml.example +++ b/examples/opensrf.xml.example @@ -90,6 +90,9 @@ vim:et:ts=2:sw=2: 97 + + + diff --git a/src/perl/lib/OpenSRF/Server.pm b/src/perl/lib/OpenSRF/Server.pm index 85cd5fa..0365783 100644 --- a/src/perl/lib/OpenSRF/Server.pm +++ b/src/perl/lib/OpenSRF/Server.pm @@ -34,12 +34,15 @@ sub new { my($class, $service, %args) = @_; my $self = bless(\%args, $class); - $self->{service} = $service; # service name - $self->{num_children} = 0; # number of child processes - $self->{osrf_handle} = undef; # xmpp handle - $self->{routers} = []; # list of registered routers - $self->{active_list} = []; # list of active children - $self->{idle_list} = []; # list of idle children + $self->{service} = $service; # service name + $self->{num_children} = 0; # number of child processes + $self->{osrf_handle} = undef; # xmpp handle + $self->{routers} = []; # list of registered routers + $self->{active_list} = []; # list of active children + $self->{idle_list} = []; # list of idle children + + $self->{stderr_log} = $self->{stderr_log_path} . "/${service}_stderr.log" + if $self->{stderr_log_path}; $self->{min_spare_children} ||= 0; @@ -345,6 +348,17 @@ sub spawn_child { $SIG{$_} = 'DEFAULT' for (qw/INT TERM QUIT HUP/); + if($self->{stderr_log}) { + + $chatty and $logger->internal("server: redirecting STDERR to " . $self->{stderr_log}); + + close STDERR; + unless( open(STDERR, '>>' . $self->{stderr_log}) ) { + $logger->error("server: unable to open STDERR log file: " . $self->{stderr_log} . " : $@"); + open STDERR, '>/dev/null'; # send it back to /dev/null + } + } + $child->{pid} = $$; eval { $child->init; diff --git a/src/perl/lib/OpenSRF/System.pm b/src/perl/lib/OpenSRF/System.pm index f7e78ef..c01ee12 100644 --- a/src/perl/lib/OpenSRF/System.pm +++ b/src/perl/lib/OpenSRF/System.pm @@ -86,6 +86,10 @@ sub run_service { # kill the temp connection OpenSRF::Transport::PeerHandle->retrieve->disconnect; + + # if this service does not want stderr output, it will be redirected to /dev/null + my $disable_stderr = $getval->('disable_stderr') || ''; + my $stderr_path = ($disable_stderr =~ /true/i) ? undef : $sclient->config_value(dirs => 'log'); my $server = OpenSRF::Server->new( $service, @@ -94,7 +98,8 @@ sub run_service { max_children => $getval->(unix_config => 'max_children') || 20, min_children => $getval->(unix_config => 'min_children') || 1, min_spare_children => $getval->(unix_config => 'min_spare_children'), - max_spare_children => $getval->(unix_config => 'max_spare_children') + max_spare_children => $getval->(unix_config => 'max_spare_children'), + stderr_log_path => $stderr_path ); while(1) { -- 2.43.2