]> git.proxmox.com Git - pve-ha-manager.git/blob - pve-ha-crm
a7570cebce1ef0b85ceb7b63e9cb0035656eb679
[pve-ha-manager.git] / pve-ha-crm
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use PVE::SafeSyslog;
6 use PVE::Daemon;
7 use Data::Dumper;
8 use PVE::RPCEnvironment;
9
10 use PVE::HA::Env;
11 use PVE::HA::Env::PVE2;
12 use PVE::HA::CRM;
13
14 use base qw(PVE::Daemon);
15
16 my $cmdline = [$0, @ARGV];
17
18 my %daemon_options = (stop_wait_time => 5);
19
20 my $daemon = __PACKAGE__->new('pve-ha-crm', $cmdline, %daemon_options);
21
22 my $rpcenv = PVE::RPCEnvironment->init('cli');
23
24 $rpcenv->init_request();
25 $rpcenv->set_language($ENV{LANG});
26 $rpcenv->set_user('root@pam');
27
28 sub run {
29 my ($self) = @_;
30
31 $self->{haenv} = PVE::HA::Env->new('PVE::HA::Env::PVE2', $self->{nodename});
32
33 $self->{crm} = PVE::HA::CRM->new($self->{haenv});
34
35 for (;;) {
36 $self->{haenv}->loop_start_hook();
37
38 my $repeat = $self->{crm}->do_one_iteration();
39
40 $self->{haenv}->loop_end_hook();
41
42 last if !$repeat;
43 }
44 }
45
46 sub shutdown {
47 my ($self) = @_;
48
49 $self->{crm}->shutdown_request();
50 }
51
52 $daemon->register_start_command();
53 $daemon->register_stop_command();
54 $daemon->register_status_command();
55
56 my $cmddef = {
57 start => [ __PACKAGE__, 'start', []],
58 stop => [ __PACKAGE__, 'stop', []],
59 status => [ __PACKAGE__, 'status', [], undef, sub { print shift . "\n";} ],
60 };
61
62 my $cmd = shift;
63
64 PVE::CLIHandler::handle_cmd($cmddef, $0, $cmd, \@ARGV, undef, $0);
65
66 exit (0);
67
68 __END__
69
70 =head1 NAME
71
72 pve-ha-crm - PVE Cluster Ressource Manager Daemon
73
74 =head1 SYNOPSIS
75
76 =include synopsis
77
78 =head1 DESCRIPTION
79
80 This is the Cluster Ressource Manager.
81
82 =include pve_copyright