]> git.proxmox.com Git - pve-ha-manager.git/blobdiff - src/PVE/HA/LRM.pm
followup code cleanup
[pve-ha-manager.git] / src / PVE / HA / LRM.pm
index e8a8147a243e1702ecb89573d22bc90627643dc1..417619b5d16852880da783f1fa34330f47c122dd 100644 (file)
@@ -34,6 +34,7 @@ sub new {
        shutdown_errors => 0,
        # mode can be: active, reboot, shutdown, restart
        mode => 'active',
+       cluster_state_update => 0,
     }, $class;
 
     $self->set_local_status({ state =>         'wait_for_agent_lock' });   
@@ -52,6 +53,25 @@ sub shutdown_request {
 
     my ($shutdown, $reboot) = $haenv->is_node_shutdown();
 
+    my $dc_ha_cfg = $haenv->get_ha_settings();
+    my $shutdown_policy = $dc_ha_cfg->{shutdown_policy} // 'conditional';
+
+    if ($shutdown) { # don't log this on service restart, only on node shutdown
+       $haenv->log('info', "got shutdown request with shutdown policy '$shutdown_policy'");
+    }
+
+    my $freeze_all;
+    if ($shutdown_policy eq 'conditional') {
+       $freeze_all = $reboot;
+    } elsif ($shutdown_policy eq 'freeze') {
+       $freeze_all = 1;
+    } elsif ($shutdown_policy eq 'failover') {
+       $freeze_all = 0;
+    } else {
+       $haenv->log('err', "unknown shutdown policy '$shutdown_policy', fall back to conditional");
+       $freeze_all = $reboot;
+    }
+
     if ($shutdown) {
        # *always* queue stop jobs for all services if the node shuts down,
        # independent if it's a reboot or a poweroff, else we may corrupt
@@ -68,8 +88,12 @@ sub shutdown_request {
     }
 
     if ($shutdown) {
-       if ($reboot) {
-           $haenv->log('info', "reboot LRM, stop and freeze all services");
+       if ($freeze_all) {
+           if ($reboot) {
+               $haenv->log('info', "reboot LRM, stop and freeze all services");
+           } else {
+               $haenv->log('info', "shutdown LRM, stop and freeze all services");
+           }
            $self->{mode} = 'restart';
        } else {
            $haenv->log('info', "shutdown LRM, stop all services");
@@ -217,6 +241,22 @@ sub do_one_iteration {
 
     my $haenv = $self->{haenv};
 
+    $haenv->loop_start_hook();
+
+    $self->{cluster_state_update} = $haenv->cluster_state_update();
+
+    my $res = $self->work();
+
+    $haenv->loop_end_hook();
+
+    return $res;
+}
+
+sub work {
+    my ($self) = @_;
+
+    my $haenv = $self->{haenv};
+
     if (!$wrote_lrm_status_at_startup) {
        if ($self->update_lrm_status()) {
            $wrote_lrm_status_at_startup = 1;
@@ -332,6 +372,13 @@ sub do_one_iteration {
                    }
                }
            } else {
+               if (!$self->{cluster_state_update}) {
+                   # update failed but we could still renew our lock (cfs restart?),
+                   # safely skip manage and expect to update just fine next round
+                   $haenv->log('notice', "temporary inconsistent cluster state " .
+                               "(cfs restart?), skip round");
+                   return;
+               }
 
                $self->manage_resources();
 
@@ -662,7 +709,7 @@ sub exec_resource_agent {
 
     my $nodename = $haenv->nodename();
 
-    my (undef, $service_type, $service_name) = PVE::HA::Tools::parse_sid($sid);
+    my (undef, $service_type, $service_name) = $haenv->parse_sid($sid);
 
     my $plugin = PVE::HA::Resources->lookup($service_type);
     if (!$plugin) {