[pve-devel] [RFC v3 pve-ha-manager 2/8] HA Env: add 'is_poweroff' function

Dietmar Maurer dietmar at proxmox.com
Wed Dec 16 09:04:44 CET 2015


From: Thomas Lamprecht <t.lamprecht at proxmox.com>

This function returns true if we do an shutdown/poweroff and thus the
services should not get freezed but fenced if the node does not
comes back up fast enough.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 src/PVE/HA/Env.pm         |  7 +++++++
 src/PVE/HA/Env/PVE2.pm    | 18 ++++++++++++++++++
 src/PVE/HA/Sim/Env.pm     |  5 +++++
 src/PVE/HA/Sim/TestEnv.pm | 16 ++++++++++++++++
 4 files changed, 46 insertions(+)

diff --git a/src/PVE/HA/Env.pm b/src/PVE/HA/Env.pm
index 5c7a544..1e29f05 100644
--- a/src/PVE/HA/Env.pm
+++ b/src/PVE/HA/Env.pm
@@ -54,6 +54,13 @@ sub write_lrm_status {
     return $self->{plug}->write_lrm_status($status_obj);
 }
 
+# check if we do a poweroff, can be used to decide if services should be freeze
+sub is_poweroff {
+    my ($self) = @_;
+
+    return $self->{plug}->is_poweroff();
+}
+
 # implement a way to send commands to the CRM master
 sub queue_crm_commands {
     my ($self, $cmd) = @_;
diff --git a/src/PVE/HA/Env/PVE2.pm b/src/PVE/HA/Env/PVE2.pm
index 49654a2..707615e 100644
--- a/src/PVE/HA/Env/PVE2.pm
+++ b/src/PVE/HA/Env/PVE2.pm
@@ -67,6 +67,24 @@ sub write_lrm_status {
     PVE::HA::Config::write_lrm_status($node, $status_obj);
 }
 
+# check if we do a poweroff, can be used to decide if services should be freezed
+sub is_poweroff {
+    my ($self) = @_;
+
+    my $poweroff;
+
+    my $code = sub {
+	my $line = shift;
+
+	$poweroff = 1 if ($line =~ m/poweroff\.target/);
+    };
+
+    my $cmd = ['/bin/systemctl', 'list-jobs'];
+    eval { PVE::Tools::run_command($cmd, outfunc => $code, noerr => 1); };
+
+    return $poweroff;
+}
+
 sub queue_crm_commands {
     my ($self, $cmd) = @_;
 
diff --git a/src/PVE/HA/Sim/Env.pm b/src/PVE/HA/Sim/Env.pm
index e09444e..1656442 100644
--- a/src/PVE/HA/Sim/Env.pm
+++ b/src/PVE/HA/Sim/Env.pm
@@ -139,6 +139,11 @@ sub write_lrm_status {
     return $self->{hardware}->write_lrm_status($node, $status_obj);
 }
 
+sub is_poweroff {
+    my ($self) = @_;
+
+    return 0; # default to freezing services if not overwritten by subclass
+}
 
 sub service_config_exists {
     my ($self) = @_;
diff --git a/src/PVE/HA/Sim/TestEnv.pm b/src/PVE/HA/Sim/TestEnv.pm
index 4e2eaf9..fa0178c 100644
--- a/src/PVE/HA/Sim/TestEnv.pm
+++ b/src/PVE/HA/Sim/TestEnv.pm
@@ -115,4 +115,20 @@ sub can_fork {
     return 0;
 }
 
+sub is_poweroff {
+    my ($self) = @_;
+
+    my $node = $self->{nodename};
+    my $cstatus = $self->{hardware}->read_hardware_status_nolock();
+
+    die "undefined node status for node '$node'" if !defined($cstatus->{$node});
+
+    if (defined($cstatus->{$node}->{shutdown}) &&
+	$cstatus->{$node}->{shutdown} eq 'shutdown') {
+	return 1;
+    }
+
+    return 0;
+}
+
 1;
-- 
2.1.4



More information about the pve-devel mailing list