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

foxr lon-capa-cvs@mail.lon-capa.org
Tue, 07 Oct 2003 11:23:03 -0000


foxr		Tue Oct  7 07:23:03 2003 EDT

  Modified files:              
    /loncom	loncnew 
  Log:
  Installed and tested code to process reinit in parent server.
  
  
Index: loncom/loncnew
diff -u loncom/loncnew:1.26 loncom/loncnew:1.27
--- loncom/loncnew:1.26	Tue Sep 30 07:11:17 2003
+++ loncom/loncnew	Tue Oct  7 07:23:03 2003
@@ -2,7 +2,7 @@
 # The LearningOnline Network with CAPA
 # lonc maintains the connections to remote computers
 #
-# $Id: loncnew,v 1.26 2003/09/30 11:11:17 foxr Exp $
+# $Id: loncnew,v 1.27 2003/10/07 11:23:03 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -45,6 +45,9 @@
 
 # Change log:
 #    $Log: loncnew,v $
+#    Revision 1.27  2003/10/07 11:23:03  foxr
+#    Installed and tested code to process reinit in parent server.
+#
 #    Revision 1.26  2003/09/30 11:11:17  foxr
 #    Add book-keeping hashes to support the re-init procedure.
 #
@@ -1524,7 +1527,7 @@
     my $pid          = fork;
     if($pid) {			# Parent
 	$RemoteHost = "Parent";
-	$ChildHash{$pid} = $RemoteHost;
+	$ChildHash{$pid} = $host;
 	$HostToPid{$host}= $pid;
 	sigprocmask(SIG_UNBLOCK, $sigset);
 
@@ -1664,7 +1667,7 @@
 
 =item
 
-HUP's children for hosts that already exist (this just forces a status display
+QUITs  children for hosts that already exist (this just forces a status display
 and resets the connection retry count for that host.
 
 =item
@@ -1675,7 +1678,84 @@
 =cut
 
 sub UpdateKids {
+
     Log("INFO", "Updating connections via SIGUSR2");
+
+    #  Just in case we need to kill our own lonc, we wait a few seconds to
+    #  give it a chance to receive and relay lond's response to the 
+    #  re-init command.
+    #
+
+    sleep(2);			# Wait a couple of seconds.
+
+    my %hosts;                   # Indexed by loncapa hostname, value=ip.
+    
+    # Need to re-read  the host table:
+    
+    
+    LondConnection::ReadConfig();
+    my $I = LondConnection::GetHostIterator;
+    while (! $I->end()) {
+	my $item = $I->get();
+	$hosts{$item->[0]} = $item->[4];
+	$I->next();
+    }
+
+    #  The logic below is written for clarity not for efficiency.
+    #  Since I anticipate that this function is only rarely called, that's
+    #  appropriate.  There are certainly ways to combine the loops below,
+    #  and anyone wishing to obscure the logic is welcome to go for it.
+    #  Note that we don't re-direct sigchild.  Instead we do what's needed
+    #  to the data structures that keep track of children to ensure that
+    #  when sigchild is honored, no new child is born.
+    #
+
+    #  For each existing child; if it's host doesn't exist, kill the child.
+
+    foreach my $child (keys %ChildHash) {
+	my $oldhost = $ChildHash{$child};
+	if (!(exists $hosts{$oldhost})) {
+	    Log("CRITICAL", "Killing child for $oldhost  host no longer exists");
+	    delete $ChildHash{$child};
+	    delete $HostToPid{$oldhost};
+	    kill 'QUIT' => $child;
+	}
+    }
+    # For each remaining existing child; if it's host's ip has changed,
+    # Restart the child on the new IP.
+
+    foreach my $child (keys %ChildHash) {
+	my $oldhost = $ChildHash{$child};
+	my $oldip   = $HostHash{$oldhost};
+	if ($hosts{$oldhost} ne $oldip) {
+
+	    # kill the old child.
+
+	    Log("CRITICAL", "Killing child for $oldhost host ip has changed...");
+	    delete $ChildHash{$child};
+	    delete $HostToPid{$oldhost};
+	    kill 'QUIT' => $child;
+
+	    # Do the book-keeping needed to start a new child on the
+	    # new ip.
+
+	    $HostHash{$oldhost} = $hosts{$oldhost};
+	    CreateChild($oldhost);
+	}
+    }
+    # Finally, for each new host, not in the host hash, create a
+    # enter the host and create a new child.
+    # Force a status display of any existing process.
+
+    foreach my $host (keys %hosts) {
+	if(!(exists $HostHash{$host})) {
+	    Log("INFO", "New host $host discovered in hosts.tab...");
+	    $HostHash{$host} = $hosts{$host};
+	    CreateChild($host);
+	} else {
+	    kill 'HUP' => $HostToPid{$host};    # status display.
+	}
+    }
 }