[LON-CAPA-cvs] cvs: loncom(version_2_10_X) / lond

raeburn raeburn@source.lon-capa.org
Sat, 14 May 2011 17:14:30 -0000


raeburn		Sat May 14 17:14:30 2011 EDT

  Modified files:              (Branch: version_2_10_X)
    /loncom	lond 
  Log:
  - Backport 1.471, 1.472, 1.473, 1.474.
  
  
Index: loncom/lond
diff -u loncom/lond:1.467.2.2 loncom/lond:1.467.2.3
--- loncom/lond:1.467.2.2	Tue Apr  5 15:49:27 2011
+++ loncom/lond	Sat May 14 17:14:29 2011
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.467.2.2 2011/04/05 15:49:27 raeburn Exp $
+# $Id: lond,v 1.467.2.3 2011/05/14 17:14:29 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -52,13 +52,14 @@
 use LONCAPA::lonssl;
 use Fcntl qw(:flock);
 use Apache::lonnet;
+use Mail::Send;
 
 my $DEBUG = 0;		       # Non zero to enable debug log entries.
 
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.467.2.2 $'; #' stupid emacs
+my $VERSION='$Revision: 1.467.2.3 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid="default";
 my $currentdomainid;
@@ -419,8 +420,11 @@
 
    my $tablename = $perlvar{'lonTabDir'}."/managers.tab";
    if (!open (MANAGERS, $tablename)) {
-      logthis('<font color="red">No manager table.  Nobody can manage!!</font>');
-      return;
+       my $hostname = &Apache::lonnet::hostname($perlvar{'lonHostID'});
+       if (&Apache::lonnet::is_LC_dns($hostname)) {
+           &logthis('<font color="red">No manager table.  Nobody can manage!!</font>');
+       }
+       return;
    }
    while(my $host = <MANAGERS>) {
       chomp($host);
@@ -445,7 +449,7 @@
          }
       } else {
          logthis('<font color="green"> existing host'." $host</font>\n");
-         $managers{&Apache::lonnet::get_host_ip($host)} = $host;  # Use info from cluster tab if clumemeber
+         $managers{&Apache::lonnet::get_host_ip($host)} = $host;  # Use info from cluster tab if cluster memeber
       }
    }
 }
@@ -507,7 +511,8 @@
     my $me        = $perlvar{'lonHostID'};
 
     foreach my $line (split(/\n/,$contents)) {
-	if(!(($line eq "") || ($line =~ /^ *\#/) || ($line =~ /^ *$/))) {
+	if(!(($line eq "") || ($line =~ /^ *\#/) || ($line =~ /^ *$/) ||
+             ($line =~ /^\s*\^/))) {
 	    chomp($line);
 	    my ($id,$domain,$role,$name,$ip,$maxcon,$idleto,$mincon)=split(/:/,$line);
 	    if ($id eq $me) {
@@ -595,11 +600,8 @@
 #
 #   ConfigFileFromSelector: converts a configuration file selector
 #                 into a configuration file pathname.
-#                 It's probably no longer necessary to preserve
-#                 special handling of hosts or domain as those
-#                 files have been superceded by dns_hosts, dns_domain.
-#                 The default action is just to prepend the directory
-#                 and append .tab
+#                 Supports the following file selectors:
+#                 hosts, domain, dns_hosts, dns_domain
 #
 #
 #  Parameters:
@@ -612,12 +614,9 @@
     my $tablefile;
 
     my $tabledir = $perlvar{'lonTabDir'}.'/';
-    if ($selector eq "hosts") {
-	$tablefile = $tabledir."hosts.tab";
-    } elsif ($selector eq "domain") {
-	$tablefile = $tabledir."domain.tab";
-    } else {
-	$tablefile =  $tabledir.$selector.'.tab';
+    if (($selector eq "hosts") || ($selector eq "domain") ||
+        ($selector eq "dns_hosts") || ($selector eq "dns_domain")) {
+        $tablefile =  $tabledir.$selector.'.tab';
     }
     return $tablefile;
 
@@ -646,6 +645,8 @@
     #  supported:
     #   hosts.tab  ($filename eq host).
     #   domain.tab ($filename eq domain).
+    #   dns_hosts.tab ($filename eq dns_host).
+    #   dns_domain.tab ($filename eq dns_domain).
     # Construct the destination filename or reject the request.
     #
     # lonManage is supposed to ensure this, however this session could be
@@ -676,12 +677,32 @@
 	 .$tablefile." $! </font>");
 	return "error:$!";
     } else {
-	&logthis('<font color="green"> Installed new '.$tablefile
-		 ."</font>");
-
+        &logthis('<font color="green"> Installed new '.$tablefile
+                 ." - transaction by: $clientname ($clientip)</font>");
+        my $adminmail = $perlvar{'lonAdmEMail'};
+        my $admindom = &Apache::lonnet::host_domain($perlvar{'lonHostID'});
+        if ($admindom ne '') {
+            my %domconfig =
+                &Apache::lonnet::get_dom('configuration',['contacts'],$admindom);
+            if (ref($domconfig{'contacts'}) eq 'HASH') {
+                if ($domconfig{'contacts'}{'adminemail'} ne '') {
+                    $adminmail = $domconfig{'contacts'}{'adminemail'};
+                }
+            }
+        }
+        if ($adminmail =~ /^[^\@]+\@[^\@]+$/) {
+            my $msg = new Mail::Send;
+            $msg->to($adminmail);
+            $msg->subject('LON-CAPA DNS update on '.$perlvar{'lonHostID'});
+            $msg->add('Content-type','text/plain; charset=UTF-8');
+            if (my $fh = $msg->open()) {
+                print $fh 'Update to '.$tablefile.' from Cluster Manager '.
+                          "$clientname ($clientip)\n";
+                $fh->close;
+            }
+        }
     }
 
-
     #  Indicate success:
  
     return "ok";
@@ -1668,6 +1689,15 @@
 }
 &register_handler("serverhomeID", \&server_homeID_handler, 0, 1, 0);
 
+sub server_distarch_handler {
+    my ($cmd,$tail,$client) = @_;
+    my $userinput = "$cmd:$tail";
+    my $reply = &distro_and_arch();
+    &Reply($client,\$reply,$userinput);
+    return 1;
+}
+&register_handler("serverdistarch", \&server_distarch_handler, 0, 1, 0);
+
 #   Process a reinit request.  Reinit requests that either
 #   lonc or lond be reinitialized so that an updated 
 #   host.tab or domain.tab can be processed.
@@ -6062,9 +6092,12 @@
 #  a setuid perl script that can be root for us to do this job.
 #
 sub ReloadApache {
-    my $execdir = $perlvar{'lonDaemons'};
-    my $script  = $execdir."/apachereload";
-    system($script);
+    if (&LONCAPA::try_to_lock('/tmp/lock_apachereload')) {
+        my $execdir = $perlvar{'lonDaemons'};
+        my $script  = $execdir."/apachereload";
+        system($script);
+        unlink('/tmp/lock_apachereload'); #  Remove the lock file.
+    }
 }
 
 #
@@ -6330,6 +6363,11 @@
 
 my $dist=`$perlvar{'lonDaemons'}/distprobe`;
 
+my $arch = `uname -i`;
+if ($arch eq 'unknown') {
+    $arch = `uname -m`;
+}
+
 # --------------------------------------------------------------
 #   Accept connections.  When a connection comes in, it is validated
 #   and if good, a child process is created to process transactions
@@ -7477,6 +7515,10 @@
     return 1;
 }
 
+sub distro_and_arch {
+    return $dist.':'.$arch;
+}
+
 # ----------------------------------- POD (plain old documentation, CPAN style)
 
 =head1 NAME