--- loncom/clusteradmin 2018/08/20 22:31:49 1.7 +++ loncom/clusteradmin 2018/08/20 22:42:05 1.8 @@ -2,7 +2,7 @@ # The LearningOnline Network with CAPA # Push admin files from cluster manager to cluster's "name servers". # -# $Id: clusteradmin,v 1.7 2018/08/20 22:31:49 raeburn Exp $ +# $Id: clusteradmin,v 1.8 2018/08/20 22:42:05 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -156,7 +156,8 @@ sub usage { print STDERR " subcommand describes what to actually do:\n"; print STDERR " help - Prints this message (args ignored)\n"; print STDERR " update - Updates an administrative file\n"; - print STDERR " args is one of dns_hosts.tab or dns_domain.tab\n"; + print STDERR " args is one of dns_hosts.tab, dns_domain.tab\n"; + print STDERR " or loncapaCAcrl.pem\n"; } @@ -185,8 +186,14 @@ my $logfile = $config{'lonDaemons'}.'/lo sub construct_table_path { my ($basename) = @_; - my $directory = $config{'lonTabDir'}; - + my $directory; + if ($basename eq 'managers.tab') { + $directory = $config{'lonTabDir'}; + } elsif ($basename eq 'loncapaCAcrl.pem') { + $directory = $config{'lonCertificateDirectory'}; + } elsif ($basename =~ /^(dns_|)(hosts|domain)\.tab$/) { + $directory = $config{'lonTabDir'}; + } return $directory . '/' . $basename; } @@ -200,14 +207,15 @@ sub get_dns_hosts() { my @result; my $hosts_tab = &construct_table_path('hosts.tab'); - open(HOSTS, "<$hosts_tab"); - while (my $line = ) { - chomp($line); - if ($line =~ /^\^/) { - if ($line =~ /^\^([\w.\-]+)/) { - push(@result,$1); - } - } + if (open(HOSTS,'<',$hosts_tab)) { + while (my $line = ) { + chomp($line); + if ($line =~ /^\^/) { + if ($line =~ /^\^([\w.\-]+)/) { + push(@result,$1); + } + } + } } return (@result); } @@ -233,7 +241,7 @@ sub push_file { my $contents; my $line; - open(FILE, "<$pushfile"); + open(FILE,'<',$pushfile); while ($line = ) { $contents .= $line; } @@ -284,16 +292,22 @@ sub update_file { # Validate the filename: if (($filename eq 'dns_hosts.tab') || ($filename eq 'dns_domain.tab') || - ($filename eq 'hosts.tab') || ($filename eq 'domain.tab')) { + ($filename eq 'hosts.tab') || ($filename eq 'domain.tab') || + ($filename eq 'loncapaCAcrl.pem')) { my ($result,$fh); if (!-e $logfile) { system("touch $logfile"); system("chown www:www $logfile"); } - if (open ($fh,">>$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()); + my $ext = 'tab'; + if ($filename eq 'loncapaCAcrl.pem') { + $ext = 'pem'; + } + my $specifier = basename($filename, (".$ext")); my @hosts = (&get_dns_hosts()); $result = &push_file($specifier, $pushfile, \@hosts, $fh); print $fh "ended: ".localtime(time)."\n"; @@ -303,7 +317,7 @@ sub update_file { } return $result; } else { - print STDERR "Only dns_hosts.tab or dns_domain.tab can be updated\n"; + print STDERR "Only dns_hosts.tab, dns_domain.tab or loncapaCAcrl.pem can be updated\n"; &usage(); return 0; }