Diff for /loncom/loncnew between versions 1.57.2.1 and 1.60

version 1.57.2.1, 2005/01/19 21:38:25 version 1.60, 2004/09/22 11:11:54
Line 61  use LONCAPA::LondConnection; Line 61  use LONCAPA::LondConnection;
 use LONCAPA::LondTransaction;  use LONCAPA::LondTransaction;
 use LONCAPA::Configuration;  use LONCAPA::Configuration;
 use LONCAPA::HashIterator;  use LONCAPA::HashIterator;
 use Fcntl qw(:flock);  
   
   
 # Read the httpd configuration file to get perl variables  # Read the httpd configuration file to get perl variables
Line 107  my $LondVersion     = "unknown"; # Versi Line 106  my $LondVersion     = "unknown"; # Versi
 my $KeyMode         = "";       # e.g. ssl, local, insecure from last connect.  my $KeyMode         = "";       # e.g. ssl, local, insecure from last connect.
 my $LondConnecting  = 0;       # True when a connection is being built.  my $LondConnecting  = 0;       # True when a connection is being built.
   
   
   # DO NOT SET THE NEXT VARIABLE TO NON ZERO!!!!!!!!!!!!!!!
   
 my $DieWhenIdle     = 0; # When true children die when trimmed -> 0.  my $DieWhenIdle     = 0; # When true children die when trimmed -> 0.
   
 #  #
Line 384  sub Tick { Line 386  sub Tick {
  $KeyMode = "";    $KeyMode = ""; 
  $clock_watcher->cancel();   $clock_watcher->cancel();
     }      }
     &UpdateStatus();  
 }  }
   
 =pod  =pod
Line 1397  sub NewClient { Line 1398  sub NewClient {
 Returns the name of the UNIX socket on which to listen for client  Returns the name of the UNIX socket on which to listen for client
 connections.  connections.
   
   =head2 Parameters:
   
       host (optional)  - Name of the host socket to return.. defaults to
                          the return from GetServerHost().
   
 =cut  =cut
   
 sub GetLoncSocketPath {  sub GetLoncSocketPath {
     return $UnixSocketDir."/".GetServerHost();  
       my $host = GetServerHost(); # Default host.
       if (@_) {
    ($host)  = @_; # Override if supplied.
       }
       return $UnixSocketDir."/".$host;
 }  }
   
 =pod  =pod
Line 1437  connection.  The event handler establish Line 1448  connection.  The event handler establish
 (creating a communcations channel), that int turn will establish  (creating a communcations channel), that int turn will establish
 another event handler to subess requests.  another event handler to subess requests.
   
   =head2  Parameters:
   
      host (optional)   Name of the host to set up a unix socket to.
   
 =cut  =cut
   
 sub SetupLoncListener {  sub SetupLoncListener {
   
       my $host       = GetServerHost(); # Default host.
       if (@_) {
    ($host)    = @_ # Override host with parameter.
       }
   
     my $socket;      my $socket;
     my $SocketName = GetLoncSocketPath();      my $SocketName = GetLoncSocketPath($host);
     unlink($SocketName);      unlink($SocketName);
     unless ($socket =IO::Socket::UNIX->new(Local  => $SocketName,      unless ($socket =IO::Socket::UNIX->new(Local  => $SocketName,
     Listen => 250,       Listen => 250, 
     Type   => SOCK_STREAM)) {      Type   => SOCK_STREAM)) {
  die "Failed to create a lonc listner socket";   die "Failed to create a lonc listner socket";
     }      }
     Event->io(cb     => \&NewClient,      return $socket;
       poll   => 'r',  
       desc   => 'Lonc listener Unix Socket',  
       fd     => $socket);  
 }  }
   
 #  #
Line 1490  sub ChildStatus { Line 1507  sub ChildStatus {
   
     Debug(2, "Reporting child status because : ".$watcher->data);      Debug(2, "Reporting child status because : ".$watcher->data);
     my $docdir = $perlvar{'lonDocRoot'};      my $docdir = $perlvar{'lonDocRoot'};
           my $fh = IO::File->new(">>$docdir/lon-status/loncstatus.txt");
     open(LOG,">>$docdir/lon-status/loncstatus.txt");      print $fh $$."\t".$RemoteHost."\t".$Status."\t".
     flock(LOG,LOCK_EX);  
     print LOG $$."\t".$RemoteHost."\t".$Status."\t".  
  $RecentLogEntry."\n";   $RecentLogEntry."\n";
     #      #
     #  Write out information about each of the connections:      #  Write out information about each of the connections:
     #      #
     if ($DebugLevel > 2) {      if ($DebugLevel > 2) {
  print LOG "Active connection statuses: \n";   print $fh "Active connection statuses: \n";
  my $i = 1;   my $i = 1;
  print STDERR  "================================= Socket Status Dump:\n";   print STDERR  "================================= Socket Status Dump:\n";
  foreach my $item (keys %ActiveConnections) {   foreach my $item (keys %ActiveConnections) {
     my $Socket = $ActiveConnections{$item}->data;      my $Socket = $ActiveConnections{$item}->data;
     my $state  = $Socket->GetState();      my $state  = $Socket->GetState();
     print LOG "Connection $i State: $state\n";      print $fh "Connection $i State: $state\n";
     print STDERR "---------------------- Connection $i \n";      print STDERR "---------------------- Connection $i \n";
     $Socket->Dump(-1); # Ensure it gets dumped..      $Socket->Dump(-1); # Ensure it gets dumped..
     $i++;      $i++;
  }   }
     }      }
     flock(LOG,LOCK_UN);  
     close(LOG);  
     $ConnectionRetriesLeft = $ConnectionRetries;      $ConnectionRetriesLeft = $ConnectionRetries;
 }  }
   
Line 1584  sub ChildProcess { Line 1597  sub ChildProcess {
   data     => "INT");    data     => "INT");
   
           
     SetupLoncListener();      my $socket =  SetupLoncListener();
       Event->io(cb   => \&NewClient,
         poll => 'r',
         desc => 'Lonc Listener Unix Socket',
         fd   => $socket);
           
     $Event::Debuglevel = $DebugLevel;      $Event::Debuglevel = $DebugLevel;
           
Line 1675  Log("CRITICAL", "--------------- Startin Line 1692  Log("CRITICAL", "--------------- Startin
   
 LondConnection::ReadConfig;               # Read standard config files.  LondConnection::ReadConfig;               # Read standard config files.
 my $HostIterator = LondConnection::GetHostIterator;  my $HostIterator = LondConnection::GetHostIterator;
 while (! $HostIterator->end()) {  
   
     my $hostentryref = $HostIterator->get();  if ($DieWhenIdle) {
     CreateChild($hostentryref->[0]);      print "Die when idle socket monitoring is not yet implemented\n";
     $HostHash{$hostentryref->[0]} = $hostentryref->[4];      exit(-1);
     $HostIterator->next();  } else {
       
       while (! $HostIterator->end()) {
   
    my $hostentryref = $HostIterator->get();
    CreateChild($hostentryref->[0]);
    $HostHash{$hostentryref->[0]} = $hostentryref->[4];
    $HostIterator->next();
       }
 }  }
   
 $RemoteHost = "Parent Server";  $RemoteHost = "Parent Server";
   
 # Maintain the population:  # Maintain the population:
Line 1692  ShowStatus("Parent keeping the flock"); Line 1717  ShowStatus("Parent keeping the flock");
 #   Set up parent signals:  #   Set up parent signals:
 #  #
   
 $SIG{INT}  = \&Terminate;  if ($DieWhenIdle) {
 $SIG{TERM} = \&Terminate;       print "Die when idle main processing not yet implemented";
 $SIG{HUP}  = \&Restart;      exit (-1);
 $SIG{USR1} = \&CheckKids;   } else {
 $SIG{USR2} = \&UpdateKids; # LonManage update request.      
       $SIG{INT}  = \&Terminate;
 while(1) {      $SIG{TERM} = \&Terminate; 
     my $deadchild = wait();      $SIG{HUP}  = \&Restart;
     if(exists $ChildHash{$deadchild}) { # need to restart.      $SIG{USR1} = \&CheckKids; 
  my $deadhost = $ChildHash{$deadchild};      $SIG{USR2} = \&UpdateKids; # LonManage update request.
  delete($HostToPid{$deadhost});      
  delete($ChildHash{$deadchild});      while(1) {
  Log("WARNING","Lost child pid= ".$deadchild.   my $deadchild = wait();
       "Connected to host ".$deadhost);   if(exists $ChildHash{$deadchild}) { # need to restart.
  Log("INFO", "Restarting child procesing ".$deadhost);      my $deadhost = $ChildHash{$deadchild};
  CreateChild($deadhost);      delete($HostToPid{$deadhost});
       delete($ChildHash{$deadchild});
       Log("WARNING","Lost child pid= ".$deadchild.
    "Connected to host ".$deadhost);
       Log("INFO", "Restarting child procesing ".$deadhost);
       CreateChild($deadhost);
    }
     }      }
 }  }
   
   
   
 =pod  =pod
   
 =head1 CheckKids  =head1 CheckKids
Line 1735  sub CheckKids { Line 1765  sub CheckKids {
     foreach my $pid (keys %ChildHash) {      foreach my $pid (keys %ChildHash) {
  Debug(2, "Sending USR1 -> $pid");   Debug(2, "Sending USR1 -> $pid");
  kill 'USR1' => $pid; # Tell Child to report status.   kill 'USR1' => $pid; # Tell Child to report status.
    sleep 1; # Wait so file doesn't intermix.
     }      }
 }  }
   

Removed from v.1.57.2.1  
changed lines
  Added in v.1.60


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>