]> oss.titaniummirror.com Git - ovzbpc.git/commitdiff
BackupPC_ovz: implment a ping command
authorR. Steve McKown <rsmckown@gmail.com>
Tue, 26 Nov 2013 16:59:22 +0000 (09:59 -0700)
committerR. Steve McKown <rsmckown@gmail.com>
Tue, 26 Nov 2013 16:59:22 +0000 (09:59 -0700)
BackupPC entries for VEs can use this as their PingCmd:

/usr/bin/BackupPC_ovz ping $host $pingPath -c 1 $host

The Backup_PC_ovz script will run the command which is the text starting
with the token '$pingPath', substituting '$host' for its HN if '$host'
is found to be a VE.

BackupPC_ovz

index 9e92313a6065baa48e27511f9e09ac7054f1b4a6..bc7228d0603c07697908721cea5fa792bae32243 100755 (executable)
@@ -435,6 +435,31 @@ sub checkRunningClient()
   }
 }
 
+sub runPing()
+{
+  # This command generates ping output by pinging the host specified in the
+  # ping command still within @ARGV.  However, if the host listed therein is
+  # a VE, the HN must be pinged instead.
+
+  # Get the host
+  my $host = shift(@ARGV);
+  my $cmd = join(' ', @ARGV);
+
+  # Find $host in the list of VEs
+  loadVeList();
+  my $hostname = gethostbyaddr(gethostbyname($host), AF_INET);
+  mydie "Host $host not found" if (!defined($hostname));
+  my $ve = getVeEntry('hostname', $hostname);
+  if (defined($ve)) {
+    $hostname = $ve->{'HN'};
+    mydie "HN is undefined for host $host" if (!defined($hostname));
+    $cmd =~ s/$host/$hostname/g;
+    print $dbgf ": ping request for $host remapped to HN $hostname\n";
+  }
+
+  cmdExecOrEval($cmd);
+}
+
 sub runClient($)
 {
   my ($restore) = @_;
@@ -557,10 +582,21 @@ if ($ARGV[0] eq "restore") {
   #print "Restore mode\n";
 }
 
+my $ping  = 0;
+if ($ARGV[0] eq "ping") {
+  shift(@ARGV);
+  $ping = 1;
+  #print "Ping mode\n";
+}
+
+print $dbgf ": server=$server, refresh=$refresh, restore=$restore ping=$ping";
+print $dbgf " on ".`date`;
 if ($server) {
   runServer($restore);
 } elsif ($refresh) {
   refreshConfig();
+} elsif ($ping) {
+  runPing();
 } else {
   runClient($restore);
 }