[LON-CAPA-cvs] cvs: loncom / loncapa_apache.conf loncnew lond /lonnet/perl lonnet.pm

albertel lon-capa-cvs@mail.lon-capa.org
Wed, 28 Mar 2007 00:05:47 -0000


albertel		Tue Mar 27 20:05:47 2007 EDT

  Modified files:              
    /loncom	loncnew lond loncapa_apache.conf 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - switch lond to use new multiplex lonc communication route
  - swithc to making the common socket a config option
  
  
Index: loncom/loncnew
diff -u loncom/loncnew:1.77 loncom/loncnew:1.78
--- loncom/loncnew:1.77	Tue Mar 27 15:38:36 2007
+++ loncom/loncnew	Tue Mar 27 20:05:38 2007
@@ -2,7 +2,7 @@
 # The LearningOnline Network with CAPA
 # lonc maintains the connections to remote computers
 #
-# $Id: loncnew,v 1.77 2007/03/27 19:38:36 albertel Exp $
+# $Id: loncnew,v 1.78 2007/03/28 00:05:38 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1529,15 +1529,14 @@
 =cut
 
 sub SetupLoncListener {
+    my ($host,$SocketName) = @_;
+    if (!$host) { $host = &GetServerHost(); }
+    if (!$SocketName) { $SocketName = &GetLoncSocketPath($host); }
 
-    my $host       = GetServerHost(); # Default host.
-    if (@_) {
-	($host)    = @_		# Override host with parameter.
-    }
 
-    my $socket;
-    my $SocketName = GetLoncSocketPath($host);
     unlink($SocketName);
+
+    my $socket;
     unless ($socket =IO::Socket::UNIX->new(Local  => $SocketName,
 					    Listen => 250, 
 					    Type   => SOCK_STREAM)) {
@@ -1844,7 +1843,7 @@
 	my $socket    = $watcher->fd;
 	
 	my $thisread;
-	my $rv = $socket->recv($thisread, 1, 0);
+	my $rv = $socket->recv($thisread, POSIX::BUFSIZ, 0);
 	Debug(8, "rcv:  data length = ".length($thisread)." read =".$thisread);
 	if (!defined($rv) || length($thisread) == 0) {
 	    # Likely eof on socket.
@@ -1890,13 +1889,21 @@
     my ($loncapa_host) = @_;
     Debug(5, "parent_listen: $loncapa_host");
 
-    my $socket   = &SetupLoncListener($loncapa_host);
+    my ($socket,$file);
+    if (!$loncapa_host) {
+	$loncapa_host = 'common_parent';
+	$file         = $perlvar{'lonSockCreate'};
+    } else {
+	$file         = &GetLoncSocketPath($loncapa_host);
+    }
+    $socket = &SetupLoncListener($loncapa_host,$file);
+
     $listening_to{$socket} = $loncapa_host;
     if (!$socket) {
 	die "Unable to create a listen socket for $loncapa_host";
     }
     
-    my $lock_file = &GetLoncSocketPath($loncapa_host).".lock";
+    my $lock_file = $file.".lock";
     unlink($lock_file);		# No problem if it doesn't exist yet [startup e.g.]
 
     my $watcher = 
@@ -1950,7 +1957,7 @@
 
 sub listen_on_common_socket {
     Debug(5, "listen_on_common_socket");
-    &parent_listen('common');
+    &parent_listen();
 }
 
 #   server_died is called whenever a child process exits.
Index: loncom/lond
diff -u loncom/lond:1.362 loncom/lond:1.363
--- loncom/lond:1.362	Mon Mar 12 18:24:58 2007
+++ loncom/lond	Tue Mar 27 20:05:38 2007
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.362 2007/03/12 22:24:58 albertel Exp $
+# $Id: lond,v 1.363 2007/03/28 00:05:38 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -59,7 +59,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.362 $'; #' stupid emacs
+my $VERSION='$Revision: 1.363 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid="default";
 my $currentdomainid;
@@ -5309,15 +5309,36 @@
     }
 }
 
-# -------------------------------------------------- Non-critical communication
+sub create_connection {
+    my ($server) = @_;
+    my $client=IO::Socket::UNIX->new(Peer    => $perlvar{'lonSockCreate'},
+				     Type    => SOCK_STREAM,
+				     Timeout => 10);
+    return 0 if (!$client);
+    print $client ("$server\n");
+    my $result = <$client>;
+    chomp($result);
+    return 1 if ($result eq 'done');
+    return 0;
+}
 
+# -------------------------------------------------- Non-critical communication
+my $max_connection_retries = 10;
 sub subreply {
     my ($cmd,$server)=@_;
     my $peerfile="$perlvar{'lonSockDir'}/".$hostname{$server};
-    my $sclient=IO::Socket::UNIX->new(Peer    =>"$peerfile",
-                                      Type    => SOCK_STREAM,
-                                      Timeout => 10)
-       or return "con_lost";
+    my $sclient;
+    for (my $retries = 0; $retries < $max_connection_retries; $retries++) {
+	$sclient=IO::Socket::UNIX->new(Peer    =>"$peerfile",
+				       Type    => SOCK_STREAM,
+				       Timeout => 10);
+	if($sclient) {
+	    last;		# Connected!
+	} else {
+	    &create_connection($hostname{$server});
+	}
+        sleep(1);		# Try again later if failed connection.
+    }
     print $sclient "sethost:$server:$cmd\n";
     my $answer=<$sclient>;
     chomp($answer);
Index: loncom/loncapa_apache.conf
diff -u loncom/loncapa_apache.conf:1.163 loncom/loncapa_apache.conf:1.164
--- loncom/loncapa_apache.conf:1.163	Thu Mar  1 13:04:27 2007
+++ loncom/loncapa_apache.conf	Tue Mar 27 20:05:38 2007
@@ -1,7 +1,7 @@
 ##
 ## loncapa_apache.conf -- Apache HTTP LON-CAPA configuration file
 ##
-## $Id: loncapa_apache.conf,v 1.163 2007/03/01 18:04:27 raeburn Exp $
+## $Id: loncapa_apache.conf,v 1.164 2007/03/28 00:05:38 albertel Exp $
 ##
 
 #
@@ -1190,6 +1190,12 @@
 ErrorDocument     500 /adm/errorhandler
 </LocationMatch>
 
+#<LocationMatch "^/adm/dns">
+#SetHandler perl-script
+#PerlHandler Apache::londns
+#ErrorDocument     500 /adm/errorhandler
+#</LocationMatch>
+
 # ------------------------------------------------- Backdoor Adm Tests/Programs
 
 <Location /cgi-bin/loncron.pl>
@@ -1361,6 +1367,7 @@
 PerlSetVar       lonSysEMail  korte@lite.msu.edu
 PerlSetVar       lonDaemons   /home/httpd/perl
 PerlSetVar       lonSockDir   /home/httpd/sockets
+PerlSetVar       lonSockCreate   /home/httpd/sockets/common
 PerlSetVar       lonDocRoot   /home/httpd/html
 PerlSetVar       lonPrtDir    /home/httpd/prtspool
 PerlSetVar       lonIncludes  /home/httpd/html/res/adm/includes
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.850 loncom/lonnet/perl/lonnet.pm:1.851
--- loncom/lonnet/perl/lonnet.pm:1.850	Tue Mar 27 15:38:39 2007
+++ loncom/lonnet/perl/lonnet.pm	Tue Mar 27 20:05:45 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.850 2007/03/27 19:38:39 albertel Exp $
+# $Id: lonnet.pm,v 1.851 2007/03/28 00:05:45 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -146,7 +146,7 @@
 
 sub create_connection {
     my ($server) = @_;
-    my $client=IO::Socket::UNIX->new(Peer    =>"/home/httpd/sockets/common",
+    my $client=IO::Socket::UNIX->new(Peer    => $perlvar{'lonSockCreate'},
 				     Type    => SOCK_STREAM,
 				     Timeout => 10);
     return 0 if (!$client);