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

albertel lon-capa-cvs-allow@mail.lon-capa.org
Wed, 11 Apr 2007 23:08:43 -0000


albertel		Wed Apr 11 19:08:43 2007 EDT

  Modified files:              
    /loncom	loncron 
  Log:
  - updated to use lonnet.pm for host information and reply communication
  
  
Index: loncom/loncron
diff -u loncom/loncron:1.71 loncom/loncron:1.72
--- loncom/loncron:1.71	Mon Apr  2 20:47:26 2007
+++ loncom/loncron	Wed Apr 11 19:08:43 2007
@@ -2,7 +2,7 @@
 
 # Housekeeping program, started by cron, loncontrol and loncron.pl
 #
-# $Id: loncron,v 1.71 2007/04/03 00:47:26 albertel Exp $
+# $Id: loncron,v 1.72 2007/04/11 23:08:43 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -32,6 +32,7 @@
 
 use lib '/home/httpd/lib/perl/';
 use LONCAPA::Configuration;
+use Apache::lonnet;
 
 use IO::File;
 use IO::Socket;
@@ -43,21 +44,6 @@
 my $statusdir="/home/httpd/html/lon-status";
 
 
-# -------------------------------------------------- Non-critical communication
-sub reply {
-    my ($cmd,$server,$hostname)=@_;
-    my $peerfile="$perlvar{'lonSockDir'}/".$hostname->{$server};
-    my $client=IO::Socket::UNIX->new(Peer    =>"$peerfile",
-                                     Type    => SOCK_STREAM,
-                                     Timeout => 10)
-       or return "con_lost";
-    print $client "sethost:$server:$cmd\n";
-    my $answer=<$client>;
-    chomp($answer);
-    if (!$answer) { $answer="con_lost"; }
-    return $answer;
-}
-
 # --------------------------------------------------------- Output error status
 
 sub log {
@@ -297,7 +283,6 @@
 }
 
 sub start_logging {
-    my ($hostdom,$hostrole,$hostname,$spareid)=@_;
     my $fh=IO::File->new(">$statusdir/newstatus.html");
     my %simplestatus=();
     my $now=time;
@@ -340,17 +325,24 @@
 	     &encode_entities($perlvar{$varname},'<>&"')."</td></tr>\n");
     }
     &log($fh,"</table><h3>Hosts</h3><table border='2'>");
-    foreach my $id (sort(keys(%{$hostname}))) {
+    my %hostname = &Apache::lonnet::all_hostnames();
+    foreach my $id (sort(keys(%hostname))) {
+	my $role = (&Apache::lonnet::is_library($id) ? 'library'
+		                                     : 'access');
 	&log($fh,
-	    "<tr><td>$id</td><td>".$hostdom->{$id}.
-	    "</td><td>".$hostrole->{$id}.
-	    "</td><td>".$hostname->{$id}."</td></tr>\n");
-    }
-    &log($fh,"</table><h3>Spare Hosts</h3><ol>");
-    foreach my $id (sort(keys(%{$spareid}))) {
-	&log($fh,"<li>$id\n</li>");
+	    "<tr><td>$id</td><td>".&Apache::lonnet::host_domain($id).
+	    "</td><td>".$role.
+	    "</td><td>".&Apache::lonnet::hostname($id)."</td></tr>\n");
+    }
+    &log($fh,"</table><h3>Spare Hosts</h3><ul>");
+    foreach my $type (sort(keys(%Apache::lonnet::spareid))) {
+	&log($fh,"<li>$type\n<ol>");
+	foreach my $id (@{ $Apache::lonnet::spareid{$type} }) {
+	    &log($fh,"<li>$id</li>\n");
+	}
+	&log($fh,"</ol>\n</li>\n");
     }
-    &log($fh,"</ol>\n");
+    &log($fh,"</ul>\n");
     return $fh;
 }
 
@@ -477,15 +469,16 @@
 
 # ----------------------------------------------------------------- Connections
 sub test_connections {
-    my ($fh,$hostname)=@_;
+    my ($fh)=@_;
     &log($fh,'<hr /><a name="connections" /><h2>Connections</h2>');
     print "testing connections\n";
     &log($fh,"<table border='2'>");
     my ($good,$bad)=(0,0);
-    foreach my $tryserver (sort(keys(%{$hostname}))) {
+    my %hostname = &Apache::lonnet::all_hostnames();
+    foreach my $tryserver (sort(keys(%hostname))) {
 	print(".");
 	my $result;
-	my $answer=&reply("ping",$tryserver,$hostname);
+	my $answer=&Apache::lonnet::reply("ping",$tryserver);
 	if ($answer eq "$tryserver:$perlvar{'lonHostID'}") {
 	    $result="<b>ok</b>";
 	    $good++;
@@ -510,7 +503,7 @@
 
 # ------------------------------------------------------------ Delayed messages
 sub check_delayed_msg {
-    my ($fh,$hostname)=@_;
+    my ($fh)=@_;
     &log($fh,'<hr /><a name="delayed" /><h2>Delayed Messages</h2>');
     print "checking buffers\n";
     
@@ -548,7 +541,7 @@
 # pong to all servers that have delayed messages
 # this will trigger a reverse connection, which should flush the buffers
     foreach my $tryserver (keys %servers) {
-	my $answer=&reply("pong",$tryserver,$hostname);
+	my $answer=&Apache::lonnet::reply("pong",$tryserver);
 	&log($fh,"Pong to $tryserver: $answer<br />");
     }
 }
@@ -662,32 +655,10 @@
 	exit 1;
     }
 
-# ------------------------------------------------------------- Read hosts file
-    my $config=IO::File->new("$perlvar{'lonTabDir'}/hosts.tab");
-    
-    my (%hostname,%hostdom,%hostrole,%spareid);
-    while (my $configline=<$config>) {
-	next if ($configline =~ /^(\#|\s*\$)/);
-	my ($id,$domain,$role,$name)=split(/:/,$configline);
-	if ($id && $domain && $role && $name) {
-	    $name=~s/\s//g;
-	    $hostname{$id}=$name;
-	    $hostdom{$id}=$domain;
-	    $hostrole{$id}=$role;
-	}
-    }
-    undef $config;
-
-# ------------------------------------------------------ Read spare server file
-    $config=IO::File->new("$perlvar{'lonTabDir'}/spare.tab");
-    
-    while (my $configline=<$config>) {
-	chomp($configline);
-	if (($configline) && ($configline ne $perlvar{'lonHostID'})) {
-	    $spareid{$configline}=1;
-	}
-    }
-    undef $config;
+# -------------------------------------------- Force reload of host information
+    &Apache::lonnet::load_hosts_tab(1);
+    &Apache::lonnet::load_domain_tab(1);
+    &Apache::lonnet::get_iphost(1);
 
 # ---------------------------------------------------------------- Start report
 
@@ -698,7 +669,7 @@
 	
     my $fh;
     if (!$justcheckdaemons && !$justcheckconnections && !$justreload) {
-	$fh=&start_logging(\%hostdom,\%hostrole,\%hostname,\%spareid);
+	$fh=&start_logging();
 
 	&log_machine_info($fh);
 	&clean_tmp($fh);
@@ -721,10 +692,10 @@
 	&checkon_daemon($fh,'lonc',40000,'USR2');
     }
     if ($justcheckconnections) {
-	&test_connections($fh,\%hostname);
+	&test_connections($fh);
     }
     if (!$justcheckdaemons && !$justcheckconnections && !$justreload) {
-	&check_delayed_msg($fh,\%hostname);
+	&check_delayed_msg($fh);
 	&finish_logging($fh);
 	&log_simplestatus();