]> git.proxmox.com Git - pve-ha-manager.git/blame - pve-ha-crm
fixup watchdog to cleanly compile with systemd
[pve-ha-manager.git] / pve-ha-crm
CommitLineData
659a7501
DM
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use PVE::SafeSyslog;
378af518 6use PVE::Daemon;
659a7501 7use Data::Dumper;
0c2c07d4 8use PVE::RPCEnvironment;
659a7501 9
714a4016
DM
10use PVE::HA::Env;
11use PVE::HA::Env::PVE2;
12use PVE::HA::CRM;
13
378af518 14use base qw(PVE::Daemon);
659a7501 15
378af518 16my $cmdline = [$0, @ARGV];
659a7501 17
0c2c07d4 18my %daemon_options = (stop_wait_time => 5);
659a7501 19
0c2c07d4 20my $daemon = __PACKAGE__->new('pve-ha-crm', $cmdline, %daemon_options);
659a7501 21
0c2c07d4 22my $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
28sub 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
46sub 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
56my $cmddef = {
57 start => [ __PACKAGE__, 'start', []],
abd854c8 58 stop => [ __PACKAGE__, 'stop', []],
378af518 59 status => [ __PACKAGE__, 'status', [], undef, sub { print shift . "\n";} ],
659a7501
DM
60};
61
62my $cmd = shift;
63
64PVE::CLIHandler::handle_cmd($cmddef, $0, $cmd, \@ARGV, undef, $0);
65
66exit (0);
67
68__END__
69
70=head1 NAME
71
72pve-ha-crm - PVE Cluster Ressource Manager Daemon
73
74=head1 SYNOPSIS
75
76=include synopsis
77
78=head1 DESCRIPTION
79
80This is the Cluster Ressource Manager.
81
82=include pve_copyright