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

raeburn raeburn@source.lon-capa.org
Wed, 13 May 2009 19:58:32 -0000


raeburn		Wed May 13 19:58:32 2009 EDT

  Modified files:              
    /loncom	clusteradmin 
  Log:
  - Add &is_manager() which checks if the server where this script is being run is included in managers.tab for the cluster, and is therefore capable of updating dns hosts/domain tables on remote DNS servers.
  
  
Index: loncom/clusteradmin
diff -u loncom/clusteradmin:1.2 loncom/clusteradmin:1.3
--- loncom/clusteradmin:1.2	Mon Mar 16 09:43:00 2009
+++ loncom/clusteradmin	Wed May 13 19:58:32 2009
@@ -260,6 +260,40 @@
     }
 }
 &define_command("update", \&update_file);
+
+#
+# Checks if current lonHostID is in managers.tab for the cluster, and is in the cluster.
+# Parameters:
+#    args   - none
+# Returns:
+#    1      - lonHostID is is managers.tab
+#    ''     - Failure (printing messages to STDERR).
+#
+sub is_manager {
+    my $currhost = $config{'lonHostID'};
+    my $canmanage;
+    if ($currhost eq '') {
+        print STDERR "Could not determine LON-CAPA host ID\n";
+        return;
+    } elsif (!defined &Apache::lonnet::get_host_ip($currhost)) {
+        print STDERR "This LON-CAPA host is not part of the cluster.\n";
+    }
+    my $tablename = &construct_table_path('managers.tab');
+    if (!open (MANAGERS, $tablename)) {
+        print STDERR "No managers.tab table. Could not verify host is a manager\n";
+        return;
+    }
+    while(my $host = <MANAGERS>) {
+        chomp($host);
+        next if ($host =~ /^\#/);
+        if ($host eq $currhost) {
+            $canmanage = 1;
+            last;
+        }
+    }
+    close(MANAGERS);
+    return $canmanage;
+}
 #---------------------------------------------------------------------------------
 #
 #  Program entry point.  Decode the subcommand from the args array and
@@ -273,6 +307,11 @@
     exit(-1);
 }
 
+if (!&is_manager()) {
+    print STDERR  'Script needs to be run from a server designated as a "Manager" in the LON-CAPA cluster'."\n";
+    exit(-1);
+}
+
 my $subcommand = shift(@ARGV);     # argv now the tail.
 
 if (!&dispatch_command($subcommand, \@ARGV)) {