]>
Commit | Line | Data |
---|---|---|
659a7501 DM |
1 | #!/usr/bin/perl |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | use PVE::SafeSyslog; | |
378af518 | 6 | use PVE::Daemon; |
659a7501 | 7 | use Data::Dumper; |
0c2c07d4 | 8 | use PVE::RPCEnvironment; |
659a7501 | 9 | |
714a4016 DM |
10 | use PVE::HA::Env; |
11 | use PVE::HA::Env::PVE2; | |
12 | use PVE::HA::CRM; | |
13 | ||
378af518 | 14 | use base qw(PVE::Daemon); |
659a7501 | 15 | |
378af518 | 16 | my $cmdline = [$0, @ARGV]; |
659a7501 | 17 | |
0c2c07d4 | 18 | my %daemon_options = (stop_wait_time => 5); |
659a7501 | 19 | |
0c2c07d4 | 20 | my $daemon = __PACKAGE__->new('pve-ha-crm', $cmdline, %daemon_options); |
659a7501 | 21 | |
0c2c07d4 | 22 | my $rpcenv = PVE::RPCEnvironment->init('cli'); |
659a7501 | 23 | |
0c2c07d4 DM |
24 | $rpcenv->init_request(); |
25 | $rpcenv->set_language($ENV{LANG}); | |
26 | $rpcenv->set_user('root@pam'); | |
659a7501 | 27 | |
378af518 DM |
28 | sub run { |
29 | my ($self) = @_; | |
659a7501 | 30 | |
0c2c07d4 DM |
31 | $self->{haenv} = PVE::HA::Env->new('PVE::HA::Env::PVE2', $self->{nodename}); |
32 | ||
33 | $self->{crm} = PVE::HA::CRM->new($self->{haenv}); | |
34 | ||
378af518 DM |
35 | for (;;) { |
36 | $self->{haenv}->loop_start_hook(); | |
659a7501 | 37 | |
0c2c07d4 | 38 | my $repeat = $self->{crm}->do_one_iteration(); |
659a7501 | 39 | |
378af518 | 40 | $self->{haenv}->loop_end_hook(); |
0c2c07d4 DM |
41 | |
42 | last if !$repeat; | |
659a7501 | 43 | } |
378af518 | 44 | } |
659a7501 | 45 | |
378af518 DM |
46 | sub shutdown { |
47 | my ($self) = @_; | |
659a7501 | 48 | |
378af518 | 49 | $self->{crm}->shutdown_request(); |
659a7501 DM |
50 | } |
51 | ||
0c2c07d4 DM |
52 | $daemon->register_start_command(); |
53 | $daemon->register_stop_command(); | |
54 | $daemon->register_status_command(); | |
659a7501 DM |
55 | |
56 | my $cmddef = { | |
57 | start => [ __PACKAGE__, 'start', []], | |
abd854c8 | 58 | stop => [ __PACKAGE__, 'stop', []], |
378af518 | 59 | status => [ __PACKAGE__, 'status', [], undef, sub { print shift . "\n";} ], |
659a7501 DM |
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 |