mirror of
git://git.proxmox.com/git/pve-ha-manager.git
synced 2025-01-07 21:18:00 +03:00
136 lines
2.4 KiB
Perl
Executable File
136 lines
2.4 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
|
|
use strict;
|
|
use warnings;
|
|
use PVE::SafeSyslog;
|
|
use PVE::Daemon;
|
|
use Data::Dumper;
|
|
|
|
use PVE::HA::Env;
|
|
use PVE::HA::Env::PVE2;
|
|
use PVE::HA::CRM;
|
|
|
|
use base qw(PVE::Daemon);
|
|
|
|
my $cmdline = [$0, @ARGV];
|
|
|
|
my $daemon = __PACKAGE__->new('pve-ha-crm', $cmdline);
|
|
|
|
sub init {
|
|
my ($self) = @_;
|
|
|
|
$self->{haenv} = PVE::HA::Env->new('PVE::HA::Env::PVE2', $self->{nodename});
|
|
|
|
$self->{crm} = PVE::HA::CRM->new($self->{haenv});
|
|
}
|
|
|
|
sub run {
|
|
my ($self) = @_;
|
|
|
|
for (;;) {
|
|
$self->{haenv}->loop_start_hook();
|
|
|
|
last if !$self->{crm}->do_one_iteration();
|
|
|
|
$self->{haenv}->loop_end_hook();
|
|
}
|
|
}
|
|
|
|
sub shutdown {
|
|
my ($self) = @_;
|
|
|
|
$self->{crm}->shutdown_request();
|
|
}
|
|
|
|
__PACKAGE__->register_method ({
|
|
name => 'start',
|
|
path => 'start',
|
|
method => 'POST',
|
|
description => "Start the Proxmox HA CRM service.",
|
|
parameters => {
|
|
additionalProperties => 0,
|
|
properties => {
|
|
debug => {
|
|
description => "Debug mode - stay in foreground",
|
|
type => "boolean",
|
|
optional => 1,
|
|
default => 0,
|
|
},
|
|
},
|
|
},
|
|
returns => { type => 'null' },
|
|
|
|
code => sub {
|
|
my ($param) = @_;
|
|
|
|
$daemon->start($param->{debug});
|
|
|
|
return undef;
|
|
}});
|
|
|
|
__PACKAGE__->register_method ({
|
|
name => 'stop',
|
|
path => 'stop',
|
|
method => 'POST',
|
|
description => "Stop the Proxmox HA CRM service.",
|
|
parameters => {
|
|
additionalProperties => 0,
|
|
properties => {},
|
|
},
|
|
returns => { type => 'null' },
|
|
|
|
code => sub {
|
|
my ($param) = @_;
|
|
|
|
$daemon->stop();
|
|
|
|
return undef;
|
|
}});
|
|
|
|
__PACKAGE__->register_method ({
|
|
name => 'status',
|
|
path => 'status',
|
|
method => 'GET',
|
|
description => "Get Proxmox HA CRM status.",
|
|
parameters => {
|
|
additionalProperties => 0,
|
|
properties => {},
|
|
},
|
|
returns => {
|
|
type => 'string',
|
|
enum => ['stopped', 'running'],
|
|
},
|
|
code => sub {
|
|
my ($param) = @_;
|
|
|
|
return $daemon->running() ? 'running' : 'stopped';
|
|
}});
|
|
|
|
my $cmddef = {
|
|
start => [ __PACKAGE__, 'start', []],
|
|
stop => [ __PACKAGE__, 'stop', []],
|
|
status => [ __PACKAGE__, 'status', [], undef, sub { print shift . "\n";} ],
|
|
};
|
|
|
|
my $cmd = shift;
|
|
|
|
PVE::CLIHandler::handle_cmd($cmddef, $0, $cmd, \@ARGV, undef, $0);
|
|
|
|
exit (0);
|
|
|
|
__END__
|
|
|
|
=head1 NAME
|
|
|
|
pve-ha-crm - PVE Cluster Ressource Manager Daemon
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
=include synopsis
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
This is the Cluster Ressource Manager.
|
|
|
|
=include pve_copyright
|