--- loncom/clusteradmin 2009/03/16 09:43:00 1.2 +++ loncom/clusteradmin 2009/05/13 19:58:32 1.3 @@ -260,6 +260,40 @@ sub update_file { } } &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 = ) { + 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 @@ if ($argc == 0) { 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)) {