--- loncom/loncron	2002/05/11 21:18:14	1.26
+++ loncom/loncron	2002/09/09 13:59:16	1.33
@@ -55,9 +55,9 @@ ENDERROUT
 
 # ================================================================ Main Program
 
-# ------------------------------------------- Read access.conf and loncapa.conf
-my $perlvarref=LONCAPA::Configuration::read_conf('access.conf','loncapa.conf');
-my %perlvar=%{$perlvarref};
+# --------------------------------- Read loncapa_apache.conf and loncapa.conf
+my $perlvarref=LONCAPA::Configuration::read_conf('loncapa.conf');
+%perlvar=%{$perlvarref};
 undef $perlvarref;
 delete $perlvar{'lonReceipt'}; # remove since sensitive and not needed
 delete $perlvar{'lonSqlAccess'}; # remove since sensitive and not needed
@@ -92,14 +92,21 @@ if ($wwwid!=$<) {
     my $config=IO::File->new("$perlvar{'lonTabDir'}/hosts.tab");
 
     while (my $configline=<$config>) {
-       my ($id,$domain,$role,$name,$ip)=split(/:/,$configline);
-       $hostname{$id}=$name;
-       $hostdom{$id}=$domain;
-       $hostrole{$id}=$role;
-       $hostip{$id}=$ip;
-       if (($role eq 'library') && ($id ne $perlvar{'lonHostID'})) {
-	   $libserv{$id}=$name;
-       }
+	my ($id,$domain,$role,$name,$ip,$domdescr)=split(/:/,$configline);
+	if ($id && $domain && $role && $name && $ip) {
+	    $hostname{$id}=$name;
+	    $hostdom{$id}=$domain;
+	    $hostip{$id}=$ip;
+	    $hostrole{$id}=$role;
+	    if ($domdescr) { $domaindescription{$domain}=$domdescr; }
+	    if (($role eq 'library') && ($id ne $perlvar{'lonHostID'})) {
+		$libserv{$id}=$name;
+	    }
+	} else {
+	    if ($configline) {
+#		&logthis("Skipping hosts.tab line -$configline-");
+	    }
+	}
     }
 }
 
@@ -159,17 +166,17 @@ print $fh (<<ENDHEADERS);
 <table border=2>
 ENDHEADERS
 
-foreach $varname (keys %perlvar) {
+foreach $varname (sort(keys(%perlvar))) {
     print $fh "<tr><td>$varname</td><td>$perlvar{$varname}</td></tr>\n";
 }
 print $fh "</table><h3>Hosts</h3><table border=2>";
-foreach $id (keys %hostname) {
-print $fh 
-    "<tr><td>$id</td><td>$hostdom{$id}</td><td>$hostrole{$id}</td>";
-print $fh "<td>$hostname{$id}</td><td>$hostip{$id}</td></tr>\n";
+foreach $id (sort(keys(%hostname))) {
+    print $fh 
+	"<tr><td>$id</td><td>$hostdom{$id}</td><td>$hostrole{$id}</td>";
+    print $fh "<td>$hostname{$id}</td><td>$hostip{$id}</td></tr>\n";
 }
 print $fh "</table><h3>Spare Hosts</h3><ol>";
-foreach $id (keys %spareid) {
+foreach $id (sort(keys(%spareid))) {
     print $fh "<li>$id\n";
 }
 
@@ -238,6 +245,7 @@ if ($psproc>250) { $notices++; }
 # --------------------------------------------------------------- clean out tmp
 print $fh '<hr><a name="tmp"><h2>Temporary Files</h2>';
 $cleaned=0;
+$old=0;
 while ($fname=<$perlvar{'lonDaemons'}/tmp/*>) {
                           my ($dev,$ino,$mode,$nlink,
                               $uid,$gid,$rdev,$size,
@@ -246,12 +254,24 @@ while ($fname=<$perlvar{'lonDaemons'}/tm
                           $now=time;
                           $since=$now-$mtime;
                           if ($since>$perlvar{'lonExpire'}) {
-                              $cleaned++;
-                              unlink("$fname");
+                              $line='';
+                              if (open(PROBE,$fname)) {
+				  $line=<PROBE>;
+                                  close(PROBE);
+			      }
+			      unless ($line=~/^CHECKOUTTOKEN\&/) {
+                                 $cleaned++;
+                                 unlink("$fname");
+			      } else {
+				  if ($since>365*$perlvar{'lonExpire'}) {
+                                     $cleaned++;
+                                     unlink("$fname");
+				 } else { $old++; }
+                              }
                           }
     
 }
-print $fh "Cleaned up ".$cleaned." files.";
+print $fh "Cleaned up ".$cleaned." files (".$old." old checkout tokens).";
 
 # ------------------------------------------------------------ clean out lonIDs
 print $fh '<hr><a name="tokens"><h2>Session Tokens</h2>';
@@ -338,20 +358,20 @@ if ($perlvar{'lonRole'} eq "library") {
 	$errors++;
 	         print $fh '<br><font color="red">Killall lonsql: '.
                     system('killall lonsql').' - ';
-                    sleep 60;
+                    sleep 2;
                     print $fh unlink($lonsqlfile).' - '.
                               system('killall -9 lonsql').
                     '</font><br>';
 	print $fh "<h3>lonsql not running, trying to start</h3>";
 	system(
  "$perlvar{'lonDaemons'}/lonsql 2>>$perlvar{'lonDaemons'}/logs/lonsql_errors");
-	sleep 10;
+	sleep 2;
 	if (-e $lonsqlfile) {
 	    print $fh "Seems like it started ...<p>";
 	    my $lfh=IO::File->new("$lonsqlfile");
 	    my $lonsqlpid=<$lfh>;
 	    chomp($lonsqlpid);
-	    sleep 30;
+	    sleep 2;
 	    if (kill 0 => $lonsqlpid) {
 		print $fh "<h3>lonsql at pid $lonsqlpid responding</h3>";
 	    } else {
@@ -360,7 +380,7 @@ if ($perlvar{'lonRole'} eq "library") {
 		print $fh "Give it one more try ...<p>";
 		system(
  "$perlvar{'lonDaemons'}/lonsql 2>>$perlvar{'lonDaemons'}/logs/lonsql_errors");
-		sleep 10;
+		sleep 2;
 	    }
 	} else {
 	    print $fh "Seems like that did not work!<p>";
@@ -435,19 +455,19 @@ if ($restartflag==1) {
    $errors++;
 	  print $fh '<br><font color="red">Killall lond: '.
                     system('killall lond').' - ';
-          sleep 60;
+          sleep 2;
           print $fh unlink($londfile).' - '.system('killall -9 lond').
                     '</font><br>';
    print $fh "<h3>lond not running, trying to start</h3>";
    system(
      "$perlvar{'lonDaemons'}/lond 2>>$perlvar{'lonDaemons'}/logs/lond_errors");
-   sleep 10;
+   sleep 2;
    if (-e $londfile) {
        print $fh "Seems like it started ...<p>";
        my $lfh=IO::File->new("$londfile");
        my $londpid=<$lfh>;
        chomp($londpid);
-       sleep 30;
+       sleep 2;
        if (kill 0 => $londpid) {
           print $fh "<h3>lond at pid $londpid responding</h3>";
        } else {
@@ -456,7 +476,7 @@ if ($restartflag==1) {
           print $fh "Give it one more try ...<p>";
 	  system(
  "$perlvar{'lonDaemons'}/lond 2>>$perlvar{'lonDaemons'}/logs/lond_errors");
-          sleep 10;
+          sleep 2;
        }
    } else {
        print $fh "Seems like that did not work!<p>";
@@ -531,19 +551,19 @@ if ($restartflag==1) {
    $errors++;
 	  print $fh '<br><font color="red">Killall lonc: '.
 	            system('killall lonc').' - ';
-          sleep 60;
+          sleep 2;
           print $fh unlink($loncfile).' - '.system('killall -9 lonc').
                     '</font><br>';
    print $fh "<h3>lonc not running, trying to start</h3>";
 	system(
  "$perlvar{'lonDaemons'}/lonc 2>>$perlvar{'lonDaemons'}/logs/lonc_errors");
-   sleep 10;
+   sleep 2;
    if (-e $loncfile) {
        print $fh "Seems like it started ...<p>";
        my $lfh=IO::File->new("$loncfile");
        my $loncpid=<$lfh>;
        chomp($loncpid);
-       sleep 30;
+       sleep 2;
        if (kill 0 => $loncpid) {
           print $fh "<h3>lonc at pid $loncpid responding</h3>";
        } else {
@@ -552,7 +572,7 @@ if ($restartflag==1) {
           print $fh "Give it one more try ...<p>";
  	  system(
  "$perlvar{'lonDaemons'}/lonc 2>>$perlvar{'lonDaemons'}/logs/lonc_errors");
-          sleep 10;
+          sleep 2;
        }
    } else {
        print $fh "Seems like that did not work!<p>";
@@ -629,7 +649,7 @@ print $fh "</pre>";
 print $fh '<hr><a name="connections"><h2>Connections</h2>';
 
 print $fh "<table border=2>";
-foreach $tryserver (keys %hostname) {
+foreach $tryserver (sort(keys(%hostname))) {
 
     $answer=reply("pong",$tryserver);
     if ($answer eq "$tryserver:$perlvar{'lonHostID'}") {