[pve-devel] [RFC v2 pve-ha-manager 6/9] add shutdown_all_remaining_services function to LRM

Thomas Lamprecht t.lamprecht at proxmox.com
Mon Dec 14 15:29:58 CET 2015


This can be used to execute a stop for all services which are in the
started state. This only makes sense when stopping the LRM and
powering off the node. Now we can ensure that HA managed services are
gracefully shut down on such a case.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 src/PVE/HA/LRM.pm | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/src/PVE/HA/LRM.pm b/src/PVE/HA/LRM.pm
index 89177ee..74bcee6 100644
--- a/src/PVE/HA/LRM.pm
+++ b/src/PVE/HA/LRM.pm
@@ -157,6 +157,36 @@ sub active_service_count {
     return $count;
 }
 
+
+my $shutdown_all_remaining_services = sub {
+    my ($self) = @_;
+
+    my $haenv = $self->{haenv};
+
+    my $nodename = $haenv->nodename();
+    my $count = 0;
+    my $ss = $self->{service_status};
+
+    foreach my $sid (keys %$ss) {
+	my $sd = $ss->{$sid};
+	next if !$sd->{node};
+	next if !$sd->{uid};
+	next if $sd->{node} ne $nodename;
+	next if !defined($sd->{state});
+	next if $sd->{state} ne 'started';
+
+	$sd->{state} = 'request_stop';
+	$count++;
+    }
+    $self->manage_resources($count);
+
+    # just to be sure
+    while ($self->check_active_workers() > 0) {
+	$haenv->sleep(1);
+    }
+};
+
+
 my $wrote_lrm_status_at_startup = 0;
 
 sub do_one_iteration {
@@ -309,7 +339,7 @@ sub do_one_iteration {
 }
 
 sub manage_resources {
-    my ($self) = @_;
+    my ($self, $max_workers) = @_;
 
     my $haenv = $self->{haenv};
 
@@ -336,7 +366,7 @@ sub manage_resources {
     my $starttime = $haenv->get_time();
 
     # start workers
-    my $max_workers = 4;
+    $max_workers = $max_workers || 4;
 
     my $sc = $haenv->read_service_config();
 
-- 
2.1.4





More information about the pve-devel mailing list