]> git.proxmox.com Git - pve-manager.git/commitdiff
PVE/Replication.pm: save pid/ptime to running job state
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 15 May 2017 10:28:33 +0000 (12:28 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 31 May 2017 06:23:46 +0000 (08:23 +0200)
So that we can check which job is running.

PVE/API2/Replication.pm
PVE/CLI/pvesr.pm
PVE/Replication.pm

index eaa7e571fceb3562615b95f10a2762f89f5cd32e..d1d8feb236efde8efcdcd9bdf7c805c66dc57bfe 100644 (file)
@@ -5,6 +5,7 @@ use strict;
 
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::RPCEnvironment;
+use PVE::ProcFSTools;
 use PVE::ReplicationConfig;
 use PVE::Replication;
 
@@ -84,6 +85,11 @@ __PACKAGE__->register_method ({
            foreach my $k (qw(last_sync fail_count error duration)) {
                $d->{$k} = $state->{$k} if defined($state->{$k});
            }
+           if ($state->{pid} && $state->{ptime}) {
+               if (PVE::ProcFSTools::check_process_running($state->{pid}, $state->{ptime})) {
+                   $d->{pid} = $state->{pid};
+               }
+           }
            push @$res, $d;
        }
 
index 433596042ed88ac29613aebafdf186af5aadc5e1..49fc86a3bc7ee91b1e1b2b31bcdd4aa75a57d5e2 100644 (file)
@@ -124,9 +124,11 @@ my $print_job_status = sub {
        my $timestr = $job->{last_sync} ?
            strftime("%Y-%m-%d_%H:%M:%S", localtime($job->{last_sync})) : '-';
 
+       my $state = $job->{pid} ? "SYNCING" : $job->{error} // 'OK';
+
        printf($format, $job->{id}, $job->{guest}, $tid,
               $timestr, $job->{duration} // '-',
-              $job->{fail_count}, , $job->{error} // 'OK');
+              $job->{fail_count}, $state);
     }
 };
 
index 220d8f6ed42aff210ebd02d9fdae4fc8ed5a3806..86e7dd5dac6081efa50e0dc681e9e0bba8fd9698 100644 (file)
@@ -7,6 +7,7 @@ use JSON;
 use Time::HiRes qw(gettimeofday tv_interval);
 
 use PVE::INotify;
+use PVE::ProcFSTools;
 use PVE::Tools;
 use PVE::Cluster;
 use PVE::QemuConfig;
@@ -167,10 +168,26 @@ my $run_replication = sub {
 
     my $t0 = [gettimeofday];
 
+    # cleanup stale pid/ptime state
+    foreach my $vmid (keys %$stateobj) {
+       foreach my $tid (keys %{$stateobj->{$vmid}}) {
+           my $state = $stateobj->{$vmid}->{$tid};
+           delete $state->{pid};
+           delete $state->{ptime};
+       }
+    }
+
+    $state->{pid} = $$;
+    $state->{ptime} = PVE::ProcFSTools::read_proc_starttime($state->{pid});
+
+    $update_job_state->($stateobj, $jobcfg,  $state);
+
     eval { replicate($jobcfg, $start_time); };
     my $err = $@;
 
     $state->{duration} = tv_interval($t0);
+    delete $state->{pid};
+    delete $state->{ptime};
 
     if ($err) {
        $state->{fail_count}++;