]>
git.proxmox.com Git - pve-ha-manager.git/blob - pve-ha-manager
12 my $statusdir = "/var/tmp/pve-ha-manager";
16 my $haenv = PVE
::HA
::SimEnv-
>new($statusdir, 'node1');
20 sub set_local_status
{
21 my ($new_status) = @_;
23 return if $status eq $new_status;
25 $haenv->log('info', "manager status change $status => $new_status");
27 $status = $new_status;
29 $haenv->write_local_status($status);
32 sub get_manager_lock
{
36 return 1 if $haenv->get_ha_manager_lock();
48 my $cur_time = $haenv->get_time();
49 return if $cur_time >= $end_time;
50 $haenv->sleep($end_time - $cur_time);
54 if (!$haenv->manager_status_exists()) {
55 $haenv->log('info', "HA is not enabled");
59 $status = $haenv->read_local_status() || 'wait_for_quorum';
61 # can happen after crash?
62 if ($status eq 'master') {
63 set_local_status
('recover');
65 set_local_status
('wait_for_quorum');
68 $haenv->log('info', "starting simulation environment (status = $status)");
70 my $manager = PVE
::HA
::Manager-
>new($haenv);
76 $haenv->loop_start_hook();
78 if ($status eq 'recover') {
80 $haenv->log('info', "waiting for 5 seconds");
83 set_local_status
('wait_for_quorum');
85 } elsif ($status eq 'wait_for_quorum') {
89 if ($haenv->quorate()) {
90 if (get_manager_lock
()) {
91 set_local_status
('master');
93 set_local_status
('slave');
97 } elsif ($status eq 'master') {
99 my $startime = $haenv->get_time();
104 # do work (max_time seconds)
106 # fixme: set alert timer
112 $haenv->log('err', "got unexpected error - $err");
113 set_local_status
('error');
116 sleep_until
($startime + $max_time);
119 if (!get_manager_lock
()) {
120 if ($haenv->quorate()) {
121 set_local_status
('slave');
123 set_local_status
('wait_for_quorum');
124 # set_local_status('lost_quorum');
127 } elsif ($status eq 'slave') {
131 if ($haenv->quorate()) {
132 if (get_manager_lock
()) {
133 set_local_status
('master');
136 set_local_status
('wait_for_quorum');
139 } elsif ($status eq 'error') {
140 die "stopping due to errors\n";
141 } elsif ($status eq 'lost_quorum') {
143 } elsif ($status eq 'halt') {
146 die "got unexpected status '$status'\n";
149 $haenv->loop_end_hook();
153 $haenv->log('err', "exit now (status = $status) - $err ");
155 $haenv->log('info', "exit simulation environment (status = $status)");