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

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Dec 11 20:01:43 CET 2015


This function returns true if we do an 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>
---
 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 | 15 +++++++++++++++
 4 files changed, 45 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..80ed79a 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..d1c937e 100644
--- a/src/PVE/HA/Sim/TestEnv.pm
+++ b/src/PVE/HA/Sim/TestEnv.pm
@@ -115,4 +115,19 @@ sub can_fork {
     return 0;
 }
 
+sub is_poweroff {
+    my ($self) = @_;
+
+    my $node = $self->{nodename};
+    my $cstatus = $self->{hardware}->read_hardware_status_nolock();
+
+    # off is basically fencing so it must be a condition
+    if ($cstatus->{$node}->{currentaction} eq 'shutdown' ||
+	$cstatus->{$node}->{currentaction} eq 'off') {
+	return 1;
+    }
+
+    return 0;
+}
+
 1;
-- 
2.1.4




More information about the pve-devel mailing list