implemented an optional per-service stderr log for capturing miscellaneous stderr...
authorerickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Tue, 12 Oct 2010 14:53:41 +0000 (14:53 +0000)
committererickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Tue, 12 Oct 2010 14:53:41 +0000 (14:53 +0000)
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@2035 9efc2488-bf62-4759-914b-345cdb29e865

examples/opensrf.xml.example
src/perl/lib/OpenSRF/Server.pm
src/perl/lib/OpenSRF/System.pm

index a213975..2747d70 100644 (file)
@@ -90,6 +90,9 @@ vim:et:ts=2:sw=2:
         <!-- max stateful requests before a session automatically disconnects a client -->
         <max_requests>97</max_requests>
 
+        <!-- this will disable the stderr output log for this service -->
+        <!--<diable_stderr>true</disable_stderr>-->
+
         <!-- settings for the backend application drones.  These are probably sane defaults -->
         <unix_config>
 
index 85cd5fa..0365783 100644 (file)
@@ -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;
index f7e78ef..c01ee12 100644 (file)
@@ -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) {