[pve-devel] [PATCH v3 pve-manager 04/23] PVE/Replication.pm: save pid/ptime to running job state
Dietmar Maurer
dietmar at proxmox.com
Tue May 30 15:20:01 CEST 2017
So that we can check which job is running.
Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
PVE/API2/Replication.pm | 6 ++++++
PVE/CLI/pvesr.pm | 4 +++-
PVE/Replication.pm | 17 +++++++++++++++++
3 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/PVE/API2/Replication.pm b/PVE/API2/Replication.pm
index eaa7e571..d1d8feb2 100644
--- a/PVE/API2/Replication.pm
+++ b/PVE/API2/Replication.pm
@@ -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;
}
diff --git a/PVE/CLI/pvesr.pm b/PVE/CLI/pvesr.pm
index 43359604..49fc86a3 100644
--- a/PVE/CLI/pvesr.pm
+++ b/PVE/CLI/pvesr.pm
@@ -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);
}
};
diff --git a/PVE/Replication.pm b/PVE/Replication.pm
index 220d8f6e..86e7dd5d 100644
--- a/PVE/Replication.pm
+++ b/PVE/Replication.pm
@@ -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}++;
--
2.11.0
More information about the pve-devel
mailing list