[LON-CAPA-cvs] cvs: loncom / loncnew

foxr lon-capa-cvs@mail.lon-capa.org
Wed, 22 Sep 2004 10:22:51 -0000


foxr		Wed Sep 22 06:22:51 2004 EDT

  Modified files:              
    /loncom	loncnew 
  Log:
  - Factor out link status display into UpdateStatus
  - Add a call to UpdateStatus when the connection count goes to zero.
    Otherwise, since the Tick clock gets disabled, the ps status never
    shows that the process has 0 connections.
  - Add/test latent support in Tick for exiting the child process with
    a lock file on the unix domain socket when the number of connections
    has been trimmed to zero.  This is currently disabled (controlled via
    the DieWhenIdle variable).   Note that since parent logic for fork on
    accept has not yet been written, some transactions may fail if this
    support is enabled at this time, because there will be a time window
    during which the child is being restarted while there is no listen on 
    the unix domain socket.
  
  
Index: loncom/loncnew
diff -u loncom/loncnew:1.56 loncom/loncnew:1.57
--- loncom/loncnew:1.56	Tue Sep 21 06:54:43 2004
+++ loncom/loncnew	Wed Sep 22 06:22:50 2004
@@ -2,7 +2,7 @@
 # The LearningOnline Network with CAPA
 # lonc maintains the connections to remote computers
 #
-# $Id: loncnew,v 1.56 2004/09/21 10:54:43 foxr Exp $
+# $Id: loncnew,v 1.57 2004/09/22 10:22:50 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -106,6 +106,8 @@
 my $KeyMode         = "";       # e.g. ssl, local, insecure from last connect.
 my $LondConnecting  = 0;       # True when a connection is being built.
 
+my $DieWhenIdle     = 0;	# When true children die when trimmed -> 0.
+
 #
 #   The hash below gives the HTML format for log messages
 #   given a severity.
@@ -119,6 +121,20 @@
 $LogFormats{"DEFAULT"}  = " %s ";
 
 
+#  UpdateStatus;
+#    Update the idle status display to show how many connections
+#    are left, retries and other stuff.
+#
+sub UpdateStatus {
+    if ($ConnectionRetriesLeft > 0) {
+	ShowStatus(GetServerHost()." Connection count: ".$ConnectionCount
+		   ." Retries remaining: ".$ConnectionRetriesLeft
+		   ." ($KeyMode)");
+    } else {
+	ShowStatus(GetServerHost()." >> DEAD <<");
+    }
+}
+
 
 =pod
 
@@ -296,13 +312,8 @@
     my $clock_watcher = $Event->w;
 
     my $client;
-    if($ConnectionRetriesLeft > 0) {
-	ShowStatus(GetServerHost()." Connection count: ".$ConnectionCount
-		   ." Retries remaining: ".$ConnectionRetriesLeft
-		   ." ($KeyMode)");
-    } else {
-	ShowStatus(GetServerHost()." >> DEAD <<");
-    }
+    UpdateStatus();
+
     # Is it time to prune connection count:
 
 
@@ -313,6 +324,21 @@
 	    my $Socket = $IdleConnections->pop();
 	    KillSocket($Socket);
 	    $IdleSeconds = 0;	# Otherwise all connections get trimmed to fast.
+	    UpdateStatus();
+	    if(($ConnectionCount == 0) && $DieWhenIdle) {
+		#
+		#  Create a lock file since there will be a time window
+		#  between our exit and the parent's picking up the listen
+		#  during which no listens will be done on the
+		#  lonnet client socket.
+		#
+		my $lock_file = GetLoncSocketPath().".lock";
+		open(LOCK,">$lock_file");
+		print LOCK "Contents not important";
+		close(LOCK);
+		
+		exit(0);
+	    }
 	}
     } else {
 	$IdleSeconds = 0;	# Reset idle count if not idle.
@@ -331,7 +357,8 @@
     # Do we have work in the queue, but no connections to service them?
     # If so, try to make some new connections to get things going again.
     #
-    
+    #   Note this code is dead now...
+    #
     my $Requests = $WorkQueue->Count();
     if (($ConnectionCount == 0)  && ($Requests > 0) && (!$LondConnecting)) { 
 	if ($ConnectionRetriesLeft > 0) {