[LON-CAPA-cvs] cvs: doc /loncapafiles loncapafiles.lpml loncom clusteradmin
raeburn
raeburn@source.lon-capa.org
Mon, 16 May 2011 15:48:29 -0000
raeburn Mon May 16 15:48:29 2011 EDT
Modified files:
/loncom clusteradmin
/doc/loncapafiles loncapafiles.lpml
Log:
- LON-CAPA dns_*.tab cluster table management.
- Logging
- Skip contacting host aliases for other hostIDs on the current server.
- Run by root.
Index: loncom/clusteradmin
diff -u loncom/clusteradmin:1.4 loncom/clusteradmin:1.5
--- loncom/clusteradmin:1.4 Thu May 12 14:08:54 2011
+++ loncom/clusteradmin Mon May 16 15:48:26 2011
@@ -152,6 +152,7 @@
my $config_vars = LONCAPA::Configuration::read_conf('loncapa.conf');
my %config = %{$config_vars};
+my $logfile = $config{'lonDaemons'}.'/logs/dns_updates.log';
sub construct_table_path {
@@ -175,9 +176,9 @@
while (my $line = <HOSTS>) {
chomp($line);
if ($line =~ /^\^/) {
- $line =~ s/^\^//; # Get rid of leading ^
- $line =~ s/\s*$//; # and any trailing whitespace.
- push(@result, $line);
+ if ($line =~ /^\^([\w.\-]+)/) {
+ push(@result,$1);
+ }
}
}
return (@result);
@@ -198,7 +199,7 @@
# 0 - Failure with appropriate output to stderr.
#
sub push_file {
- my ($specifier, $pushfile, $hosts) = @_;
+ my ($specifier, $pushfile, $hosts, $fh) = @_;
# Read in the entire file:
@@ -217,15 +218,21 @@
# Iterate over the hosts and run cmd as a critical
# operation:
+ my @ids=&Apache::lonnet::current_machine_ids();
foreach my $host (@$hosts) {
my $loncapa_name = &Apache::lonnet::host_from_dns($host);
- next if ($loncapa_name eq $config{'lonHostID'});
+ next if (grep(/^\Q$loncapa_name\E$/,@ids));
my $reply = &Apache::lonnet::critical($cmd, $loncapa_name);
- if ($reply ne 'ok') {
- print STDERR "Reply from $host ($loncapa_name) not 'ok' was: $reply\n";
- }
+ my $msg;
+ 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;
}
#
@@ -248,11 +255,25 @@
# Validate the filename:
- if ($filename eq 'dns_hosts.tab' || $filename eq 'dns_domain.tab') {
- my $pushfile = &construct_table_path($filename);
- my $specifier = basename($filename, ('.tab'));
- my @hosts = (&get_dns_hosts());
- return &push_file($specifier, $pushfile, \@hosts);
+ if (($filename eq 'dns_hosts.tab') || ($filename eq 'dns_domain.tab') ||
+ ($filename eq 'hosts.tab') || ($filename eq 'domain.tab')) {
+ my ($result,$fh);
+ if (!-e $logfile) {
+ 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 {
print STDERR "Only dns_hosts.tab or dns_domain.tab can be updated\n";
&usage();
@@ -301,6 +322,12 @@
# 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);
if ($argc == 0) {
print STDERR "Missing subcommand\n";
Index: doc/loncapafiles/loncapafiles.lpml
diff -u doc/loncapafiles/loncapafiles.lpml:1.740 doc/loncapafiles/loncapafiles.lpml:1.741
--- doc/loncapafiles/loncapafiles.lpml:1.740 Mon May 16 15:36:29 2011
+++ doc/loncapafiles/loncapafiles.lpml Mon May 16 15:48:29 2011
@@ -2,7 +2,7 @@
"http://lpml.sourceforge.net/DTD/lpml.dtd">
<!-- loncapafiles.lpml -->
-<!-- $Id: loncapafiles.lpml,v 1.740 2011/05/16 15:36:29 raeburn Exp $ -->
+<!-- $Id: loncapafiles.lpml,v 1.741 2011/05/16 15:48:29 raeburn Exp $ -->
<!--
@@ -7723,7 +7723,7 @@
<file>
<source>loncom/clusteradmin</source>
<target dist='default'>home/httpd/perl/manage_dns/clusteradmin</target>
-<categoryname>script</categoryname>
+<categoryname>rootscript</categoryname>
<description>
Script to update cluster tables: dns_hosts.tab and dns_domain.tab
on a LON-CAPA DNS server.