2008-01-27 19:16:44 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
BEGIN
|
|
|
|
{
|
|
|
|
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr';
|
|
|
|
}
|
|
|
|
use lib "$::XCATROOT/lib/perl";
|
|
|
|
use IO::Socket::SSL;
|
|
|
|
use XML::Simple;
|
2009-07-29 16:05:42 +00:00
|
|
|
$XML::Simple::PREFERRED_PARSER='XML::Parser';
|
2011-04-11 16:17:08 +00:00
|
|
|
#use Data::Dumper;
|
2008-01-27 19:16:44 +00:00
|
|
|
use IO::Handle;
|
|
|
|
use IO::Select;
|
|
|
|
use xCAT::Utils;
|
2008-05-05 13:29:10 +00:00
|
|
|
use Thread qw(yield);
|
2008-01-27 19:16:44 +00:00
|
|
|
use Getopt::Long;
|
|
|
|
use POSIX qw(:signal_h :errno_h :sys_wait_h);
|
|
|
|
my $interface;
|
2011-03-09 13:59:46 +00:00
|
|
|
my $opts;
|
2008-01-27 19:16:44 +00:00
|
|
|
Getopt::Long::Configure("require_order");
|
2008-10-31 19:56:18 +00:00
|
|
|
Getopt::Long::Configure("posix_default");
|
|
|
|
Getopt::Long::Configure("no_gnu_compat");
|
|
|
|
Getopt::Long::Configure("bundling");
|
|
|
|
|
2008-01-27 19:16:44 +00:00
|
|
|
my %nodehdl;
|
|
|
|
my $xcathost='localhost:3001';
|
|
|
|
if ($ENV{XCATHOST}) {
|
|
|
|
$xcathost=$ENV{XCATHOST};
|
|
|
|
}
|
|
|
|
|
2008-10-31 19:56:18 +00:00
|
|
|
if (!(@ARGV)) {
|
|
|
|
&usage;
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
}
|
|
|
|
if (!GetOptions(
|
|
|
|
'h|help' => \$help,
|
|
|
|
'v|version' => \$version,
|
2011-03-09 13:59:46 +00:00
|
|
|
'o|options=s' => \$opts,
|
2012-06-08 11:38:07 +00:00
|
|
|
'f|fanout=s' => \$fanout,
|
2008-10-31 19:56:18 +00:00
|
|
|
'i|interface=s' => \$interface))
|
|
|
|
{
|
|
|
|
&usage;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if ($help) {
|
|
|
|
&usage;
|
|
|
|
exit(0);
|
2008-01-27 19:16:44 +00:00
|
|
|
}
|
2008-10-31 19:56:18 +00:00
|
|
|
if ($version) {
|
|
|
|
my $version = xCAT::Utils->Version();
|
|
|
|
print "$version \n";
|
|
|
|
exit(0);
|
|
|
|
}
|
2012-06-08 11:38:07 +00:00
|
|
|
my $pshmaxp = 64;
|
|
|
|
# determine fanout
|
|
|
|
if ($fanout) { # see if they overroad the fanout from the command line
|
|
|
|
$pshmaxp=$fanout;
|
|
|
|
}
|
|
|
|
if ($ENV{XCATPSHFANOUT}) { # env variable rules
|
|
|
|
$pshmaxp=$ENV{XCATPSHFANOUT};
|
|
|
|
}
|
2008-01-27 19:16:44 +00:00
|
|
|
(my $noderange,my $destloc) = split(/:/,$ARGV[1]);
|
2012-03-22 13:57:17 +00:00
|
|
|
my @user = getpwuid($>);
|
|
|
|
my $homedir=$user[7];
|
2008-01-27 19:16:44 +00:00
|
|
|
my $client = IO::Socket::SSL->new(
|
|
|
|
PeerAddr=>$xcathost,
|
2012-03-22 13:57:17 +00:00
|
|
|
SSL_key_file=>$homedir."/.xcat/client-cred.pem",
|
|
|
|
SSL_cert_file=>$homedir."/.xcat/client-cred.pem",
|
|
|
|
SSL_ca_file => $homedir."/.xcat/ca.pem",
|
2008-01-27 19:16:44 +00:00
|
|
|
SSL_use_cert => 1,
|
|
|
|
#SSL_verify_mode => 1,
|
|
|
|
);
|
|
|
|
die "Connection failure: $!\n" unless ($client);
|
|
|
|
my %cmdref = (command => 'noderange', noderange => $noderange);
|
|
|
|
$SIG{ALRM} = sub { die "No response getting noderange" };
|
|
|
|
alarm(15);
|
|
|
|
print $client XMLout(\%cmdref,RootName=>'xcatrequest', NoAttr=>1, KeyAttr => []);
|
|
|
|
alarm(15);
|
|
|
|
my $response="";
|
|
|
|
my @nodes=();
|
|
|
|
while (<$client>) {
|
|
|
|
alarm(0);
|
|
|
|
$response .= $_;
|
|
|
|
if ($response =~ m/<\/xcatresponse>/) {
|
|
|
|
$rsp=XMLin($response, ForceArray => ['node']);
|
|
|
|
$response='';
|
|
|
|
if ($rsp->{warning}) {
|
|
|
|
printf "Warning: ".$rsp->{warning}."\n";
|
|
|
|
}
|
|
|
|
if ($rsp->{error}) {
|
|
|
|
die ("ERROR: ".$rsp->{error}."\n");
|
|
|
|
} elsif ($rsp->{node}) {
|
|
|
|
@nodes=@{$rsp->{node}};
|
|
|
|
}
|
|
|
|
if ($rsp->{serverdone}) {
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close($client);
|
|
|
|
my $children = 0;
|
|
|
|
my $inputs = new IO::Select;
|
|
|
|
$SIG{CHLD} = \&reaper;
|
2008-05-03 13:49:33 +00:00
|
|
|
sub reaper {
|
|
|
|
while (($pid = waitpid(-1,WNOHANG)) > 0) {
|
|
|
|
$children--;
|
2008-01-27 19:16:44 +00:00
|
|
|
}
|
|
|
|
if ($children and $pid == -1) { #for whatever reason, rsync processes slip by frequently
|
|
|
|
$children = 0;
|
|
|
|
}
|
|
|
|
$SIG{CHLD} = \&reaper;
|
|
|
|
}
|
2008-05-03 13:49:33 +00:00
|
|
|
|
2008-01-27 19:16:44 +00:00
|
|
|
|
|
|
|
if ($interface) {
|
|
|
|
foreach (@nodes) {
|
|
|
|
s/$/-$interface/;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach (@nodes) {
|
|
|
|
my $node=$_;
|
|
|
|
while ($children > $pshmaxp) { processoutput($inputs); }
|
|
|
|
my $child;
|
|
|
|
$children++;
|
2011-03-09 13:59:46 +00:00
|
|
|
scpnode(\$child,$node,@ARGV[0],$destloc,$opts);
|
2008-01-27 19:16:44 +00:00
|
|
|
$inputs->add($child);
|
|
|
|
$nodehdl{$child} = $node;
|
|
|
|
}
|
2008-05-02 21:19:42 +00:00
|
|
|
while ($inputs->count and $children) {
|
2008-01-27 19:16:44 +00:00
|
|
|
processoutput($inputs);
|
|
|
|
}
|
|
|
|
while (processoutput($inputs)) {};
|
2008-05-02 21:19:42 +00:00
|
|
|
wait;
|
2008-01-27 19:16:44 +00:00
|
|
|
exit(0);
|
|
|
|
|
|
|
|
sub processoutput { #This way, one arbiter handles output, no interrupting
|
|
|
|
my $inputs = shift;
|
|
|
|
my @readyins = $inputs->can_read(1);
|
|
|
|
my $rc = @readyins;
|
|
|
|
my $readyh;
|
|
|
|
foreach $readyh (@readyins) {
|
|
|
|
my $line = <$readyh>;
|
|
|
|
unless ($line) {
|
|
|
|
$inputs->remove($readyh);
|
|
|
|
print $nodehdl{$readyh}.": done\n";
|
|
|
|
close($readyh);
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
chomp($line);
|
|
|
|
print $nodehdl{$readyh}.": ".$line."\n";
|
|
|
|
}
|
2008-05-03 13:49:33 +00:00
|
|
|
#yield;
|
2008-01-27 19:16:44 +00:00
|
|
|
return $rc;
|
|
|
|
}
|
|
|
|
sub scpnode {
|
|
|
|
my $out = shift;
|
|
|
|
my $node = shift;
|
|
|
|
my $in;
|
|
|
|
#my $args = join(" ",@_);
|
|
|
|
my $file = shift;
|
|
|
|
my $dest = shift;
|
2011-03-09 13:59:46 +00:00
|
|
|
my $opts = shift;
|
|
|
|
my $cmd="rsync -az$opts $file $node:$dest 2>&1 |";
|
|
|
|
open($$out,"rsync -az$opts $file $node:$dest 2>&1 |");
|
2008-01-27 19:16:44 +00:00
|
|
|
}
|
2008-10-31 19:56:18 +00:00
|
|
|
sub usage {
|
|
|
|
print "Usage: prsync filename [filename ...] noderange:destinationdirectory\n";
|
2012-06-08 11:38:07 +00:00
|
|
|
print " prsync [-f fanout] [-o rsync options] [filename filename ...] [directory directory ...]";
|
2011-03-09 13:59:46 +00:00
|
|
|
print " noderange:destinationdirectory\n";
|
2008-10-31 19:56:18 +00:00
|
|
|
print " prsync {-h|--help|-v|--version}\n";
|
|
|
|
}
|
2011-03-09 13:59:46 +00:00
|
|
|
|