]>
Commit | Line | Data |
---|---|---|
a802c337 TL |
1 | package PVE::Service::pve_ha_crm; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
a802c337 | 6 | use PVE::Daemon; |
a802c337 TL |
7 | |
8 | use PVE::HA::Env; | |
9 | use PVE::HA::Env::PVE2; | |
10 | use PVE::HA::CRM; | |
11 | ||
12 | use base qw(PVE::Daemon); | |
13 | ||
a802c337 TL |
14 | my $cmdline = [$0, @ARGV]; |
15 | ||
16 | my %daemon_options = (stop_wait_time => 60); | |
17 | ||
18 | my $daemon = __PACKAGE__->new('pve-ha-crm', $cmdline, %daemon_options); | |
19 | ||
20 | sub run { | |
21 | my ($self) = @_; | |
22 | ||
23 | $self->{haenv} = PVE::HA::Env->new('PVE::HA::Env::PVE2', $self->{nodename}); | |
24 | ||
25 | $self->{crm} = PVE::HA::CRM->new($self->{haenv}); | |
26 | ||
27 | for (;;) { | |
28 | $self->{haenv}->loop_start_hook(); | |
29 | ||
30 | my $repeat = $self->{crm}->do_one_iteration(); | |
31 | ||
32 | $self->{haenv}->loop_end_hook(); | |
33 | ||
34 | last if !$repeat; | |
35 | } | |
36 | } | |
37 | ||
38 | sub shutdown { | |
39 | my ($self) = @_; | |
40 | ||
41 | $self->{crm}->shutdown_request(); | |
42 | } | |
43 | ||
44 | $daemon->register_start_command(); | |
45 | $daemon->register_stop_command(); | |
46 | $daemon->register_status_command(); | |
47 | ||
48 | our $cmddef = { | |
49 | start => [ __PACKAGE__, 'start', []], | |
50 | stop => [ __PACKAGE__, 'stop', []], | |
51 | status => [ __PACKAGE__, 'status', [], undef, sub { print shift . "\n";} ], | |
52 | }; | |
53 | ||
54 | 1; |