version 1.3, 2009/05/13 19:58:32
|
version 1.5, 2011/05/16 15:48:26
|
Line 8
|
Line 8
|
|
|
=head1 DESCRIPTION |
=head1 DESCRIPTION |
|
|
Performs an adiminstrative action on all hosts in the current dns_hosts.tab |
Performs an adminstrative action on DNS hosts in the current hosts.tab |
file. For this to work, the current host must be the cluster administrator |
file. For this to work, the current host must be the cluster administrator |
on the target systems. That is this must be a host in managers.tab |
on the target systems. That is this must be a host in managers.tab |
Furthermore, lonc must be running on this system. |
Furthermore, lonc must be running on this system. |
Line 16 Furthermore, lonc must be running on thi
|
Line 16 Furthermore, lonc must be running on thi
|
The action is specified by the 'command' parameter which may have additional arguments. |
The action is specified by the 'command' parameter which may have additional arguments. |
|
|
All communications with remote clients are made critical so that |
All communications with remote clients are made critical so that |
they will eventually happen even if the147 host we want to talk with |
they will eventually happen even if the host we want to talk with |
is dead. |
is dead. |
|
|
|
|
Line 152 sub usage {
|
Line 152 sub usage {
|
|
|
my $config_vars = LONCAPA::Configuration::read_conf('loncapa.conf'); |
my $config_vars = LONCAPA::Configuration::read_conf('loncapa.conf'); |
my %config = %{$config_vars}; |
my %config = %{$config_vars}; |
|
my $logfile = $config{'lonDaemons'}.'/logs/dns_updates.log'; |
|
|
|
|
sub construct_table_path { |
sub construct_table_path { |
Line 175 sub get_dns_hosts()
|
Line 176 sub get_dns_hosts()
|
while (my $line = <HOSTS>) { |
while (my $line = <HOSTS>) { |
chomp($line); |
chomp($line); |
if ($line =~ /^\^/) { |
if ($line =~ /^\^/) { |
$line =~ s/^\^//; # Get rid of leading ^ |
if ($line =~ /^\^([\w.\-]+)/) { |
$line =~ s/\s*$//; # and any trailing whitespace. |
push(@result,$1); |
push(@result, $line); |
} |
} |
} |
} |
} |
return (@result); |
return (@result); |
Line 198 sub get_dns_hosts()
|
Line 199 sub get_dns_hosts()
|
# 0 - Failure with appropriate output to stderr. |
# 0 - Failure with appropriate output to stderr. |
# |
# |
sub push_file { |
sub push_file { |
my ($specifier, $pushfile, $hosts) = @_; |
my ($specifier, $pushfile, $hosts, $fh) = @_; |
|
|
# Read in the entire file: |
# Read in the entire file: |
|
|
Line 217 sub push_file {
|
Line 218 sub push_file {
|
# Iterate over the hosts and run cmd as a critical |
# Iterate over the hosts and run cmd as a critical |
# operation: |
# operation: |
|
|
|
my @ids=&Apache::lonnet::current_machine_ids(); |
foreach my $host (@$hosts) { |
foreach my $host (@$hosts) { |
my $loncapa_name = &Apache::lonnet::host_from_dns($host); |
my $loncapa_name = &Apache::lonnet::host_from_dns($host); |
|
next if (grep(/^\Q$loncapa_name\E$/,@ids)); |
my $reply = &Apache::lonnet::critical($cmd, $loncapa_name); |
my $reply = &Apache::lonnet::critical($cmd, $loncapa_name); |
if ($reply ne 'ok') { |
my $msg; |
print STDERR "Reply from $host ($loncapa_name) not 'ok' was: $reply\n"; |
if ($reply eq 'ok') { |
} |
$msg = "$pushfile pushed to $host ($loncapa_name): $reply\n"; |
|
} else { |
|
$msg = "Reply from $host ($loncapa_name) not 'ok' was: $reply\n"; |
|
} |
|
print $fh $msg; |
|
print STDERR $msg; |
} |
} |
|
return; |
} |
} |
|
|
# |
# |
Line 247 sub update_file {
|
Line 255 sub update_file {
|
|
|
# Validate the filename: |
# Validate the filename: |
|
|
if ($filename eq 'dns_hosts.tab' || $filename eq 'dns_domain.tab') { |
if (($filename eq 'dns_hosts.tab') || ($filename eq 'dns_domain.tab') || |
my $pushfile = &construct_table_path($filename); |
($filename eq 'hosts.tab') || ($filename eq 'domain.tab')) { |
my $specifier = basename($filename, ('.tab')); |
my ($result,$fh); |
my @hosts = (&get_dns_hosts()); |
if (!-e $logfile) { |
return &push_file($specifier, $pushfile, \@hosts); |
system("touch $logfile"); |
|
system("chown www:www $logfile"); |
|
} |
|
if (open ($fh,">>$logfile")) { |
|
print $fh "clusteradmin update started: ".localtime(time)."\n"; |
|
my $pushfile = &construct_table_path($filename); |
|
my $specifier = basename($filename, ('.tab')); |
|
my @hosts = (&get_dns_hosts()); |
|
$result = &push_file($specifier, $pushfile, \@hosts, $fh); |
|
print $fh "ended: ".localtime(time)."\n"; |
|
close($fh); |
|
} else { |
|
print STDERR "Could not open $logfile to append. Exiting.\n"; |
|
} |
|
return $result; |
} else { |
} else { |
print STDERR "Only dns_hosts.tab or dns_domain.tab can be updated\n"; |
print STDERR "Only dns_hosts.tab or dns_domain.tab can be updated\n"; |
&usage(); |
&usage(); |
Line 300 sub is_manager {
|
Line 322 sub is_manager {
|
# dispatch to the appropriate command processor. |
# dispatch to the appropriate command processor. |
# |
# |
|
|
|
if ($< != 0) { # Am I root? |
|
print('You must be root in order to run clusteradmin.'. |
|
"\n"); |
|
exit(-1); |
|
} |
|
|
my $argc = scalar(@ARGV); |
my $argc = scalar(@ARGV); |
if ($argc == 0) { |
if ($argc == 0) { |
print STDERR "Missing subcommand\n"; |
print STDERR "Missing subcommand\n"; |