]> git.proxmox.com Git - pve-ha-manager.git/commitdiff
HA Env: add 'is_poweroff' function
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 14 Dec 2015 14:29:59 +0000 (15:29 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 15 Dec 2015 15:35:12 +0000 (16:35 +0100)
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@proxmox.com>
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
src/PVE/HA/Env.pm
src/PVE/HA/Env/PVE2.pm
src/PVE/HA/Sim/Env.pm
src/PVE/HA/Sim/TestEnv.pm

index 5c7a5441ce0faaa6f4ca2f9fa45b85d780a484a9..1e29f05579569add85bc05df393ff598ad124c93 100644 (file)
@@ -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) = @_;
index 49654a2708583de5482324353945d2d8d28bbc89..707615e9eb7db933cc4efb0c665dba1455ab91d5 100644 (file)
@@ -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) = @_;
 
index e09444e1cf75649aa12b497aae60346273a765d3..1656442dd4b72362095fba9150b9c29111de3850 100644 (file)
@@ -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) = @_;
index 4e2eaf9eac94deb2ba65a8c02b820a31cc26c709..fa0178c58c9618835bf13b5c98db8d2e40544918 100644 (file)
@@ -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;