[pve-devel] [PATCH pve-ha-manager 2/3] convert pve-ha-lrm into a PVE::Service class
Thomas Lamprecht
t.lamprecht at proxmox.com
Mon Sep 14 17:21:55 CEST 2015
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
src/Makefile | 12 ++++---
src/PVE/Makefile | 1 +
src/PVE/Service/Makefile | 6 ++++
src/PVE/Service/pve_ha_lrm.pm | 74 ++++++++++++++++++++++++++++++++++++++++
src/pve-ha-lrm | 78 +++++--------------------------------------
5 files changed, 97 insertions(+), 74 deletions(-)
create mode 100644 src/PVE/Service/Makefile
create mode 100644 src/PVE/Service/pve_ha_lrm.pm
diff --git a/src/Makefile b/src/Makefile
index d2cdd8e..358ca12 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -21,8 +21,11 @@ all: watchdog-mux
pve-ha-crm.1.pod: pve-ha-crm
perl -I. ./pve-ha-crm printmanpod >$@
-pve-ha-lrm.1.pod: pve-ha-lrm
- perl -I. ./pve-ha-lrm printmanpod >$@
+pve-ha-lrm.1.pod:
+ perl -I. -T -e "use PVE::Service::pve_ha_lrm; PVE::Service::pve_ha_lrm->generate_pod_manpage();" >$@
+
+pve-ha-lrm.bash-completion:
+ perl -I. -T -e "use PVE::Service::pve_ha_lrm; PVE::Service::pve_ha_lrm->generate_bash_completions();" >$@
ha-manager.1.pod:
perl -I. -T -e "use PVE::CLI::ha_manager; PVE::CLI::ha_manager->generate_pod_manpage();" >$@.tmp
@@ -36,15 +39,16 @@ watchdog-mux: watchdog-mux.c
gcc watchdog-mux.c -o watchdog-mux -Wall -Wl,-z,relro $$(pkg-config --libs --cflags libsystemd-daemon)
.PHONY: install
-install: watchdog-mux pve-ha-crm pve-ha-lrm ha-manager.1.pod ha-manager.1.gz pve-ha-crm.1.pod pve-ha-crm.1.gz pve-ha-lrm.1.pod pve-ha-lrm.1.gz ha-manager.bash-completion
+install: watchdog-mux pve-ha-crm pve-ha-lrm ha-manager.1.pod ha-manager.1.gz pve-ha-crm.1.pod pve-ha-crm.1.gz pve-ha-lrm.1.pod pve-ha-lrm.1.gz ha-manager.bash-completion pve-ha-lrm.bash-completion
perl -I. ./pve-ha-crm verifyapi
- perl -I. ./pve-ha-lrm verifyapi
+ perl -I. -T -e "use PVE::Service::pve_ha_lrm; PVE::Service::pve_ha_lrm->verify_api();"
perl -I. -T -e "use PVE::CLI::ha_manager; PVE::CLI::ha_manager->verify_api();"
install -d ${DESTDIR}${SBINDIR}
install -m 0755 pve-ha-crm ${DESTDIR}${SBINDIR}
install -m 0755 pve-ha-lrm ${DESTDIR}${SBINDIR}
install -m 0755 ha-manager ${DESTDIR}${SBINDIR}
install -m 0755 watchdog-mux ${DESTDIR}${SBINDIR}
+ install -m 0644 -D pve-ha-lrm.bash-completion ${DESTDIR}${BASHCOMPLDIR}/pve-ha-lrm
install -m 0644 -D ha-manager.bash-completion ${DESTDIR}${BASHCOMPLDIR}/ha-manager
make -C PVE install
install -d ${DESTDIR}/usr/share/man/man1
diff --git a/src/PVE/Makefile b/src/PVE/Makefile
index 6012c2c..b57dd06 100644
--- a/src/PVE/Makefile
+++ b/src/PVE/Makefile
@@ -5,6 +5,7 @@ install:
make -C HA install
make -C API2 install
make -C CLI install
+ make -C Service install
.PHONY: installsim
installsim:
diff --git a/src/PVE/Service/Makefile b/src/PVE/Service/Makefile
new file mode 100644
index 0000000..8502c8d
--- /dev/null
+++ b/src/PVE/Service/Makefile
@@ -0,0 +1,6 @@
+SOURCES=pve_ha_lrm.pm
+
+.PHONY: install
+install: ${SOURCES}
+ install -d -m 0755 ${DESTDIR}${PERLDIR}/PVE/Service
+ for i in ${SOURCES}; do install -D -m 0644 $$i ${DESTDIR}${PERLDIR}/PVE/Service/$$i; done
diff --git a/src/PVE/Service/pve_ha_lrm.pm b/src/PVE/Service/pve_ha_lrm.pm
new file mode 100644
index 0000000..8914a26
--- /dev/null
+++ b/src/PVE/Service/pve_ha_lrm.pm
@@ -0,0 +1,74 @@
+package PVE::Service::pve_ha_lrm;
+
+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::LRM;
+
+use base qw(PVE::Daemon);
+
+our $exename = "pve-ha-lrm";
+
+my $cmdline = [$0, @ARGV];
+
+my %daemon_options = (stop_wait_time => 180);
+
+my $daemon = __PACKAGE__->new('pve-ha-lrm', $cmdline, %daemon_options);
+
+sub run {
+ my ($self) = @_;
+
+ $self->{haenv} = PVE::HA::Env->new('PVE::HA::Env::PVE2', $self->{nodename});
+
+ $self->{lrm} = PVE::HA::LRM->new($self->{haenv});
+
+ for (;;) {
+ $self->{haenv}->loop_start_hook();
+
+ my $repeat = $self->{lrm}->do_one_iteration();
+
+ $self->{haenv}->loop_end_hook();
+
+ last if !$repeat;
+ }
+}
+
+sub shutdown {
+ my ($self) = @_;
+
+ $self->{lrm}->shutdown_request();
+}
+
+$daemon->register_start_command();
+$daemon->register_stop_command();
+$daemon->register_status_command();
+
+our $cmddef = {
+ start => [ __PACKAGE__, 'start', []],
+ stop => [ __PACKAGE__, 'stop', []],
+ status => [ __PACKAGE__, 'status', [], undef, sub { print shift . "\n";} ],
+};
+
+1;
+
+__END__
+
+=head1 NAME
+
+pve-ha-lrm - PVE Local HA Ressource Manager Daemon
+
+=head1 SYNOPSIS
+
+=include synopsis
+
+=head1 DESCRIPTION
+
+This is the Local HA Ressource Manager.
+
+=include pve_copyright
diff --git a/src/pve-ha-lrm b/src/pve-ha-lrm
index 4bffa72..259269f 100755
--- a/src/pve-ha-lrm
+++ b/src/pve-ha-lrm
@@ -2,16 +2,10 @@
use strict;
use warnings;
-use PVE::SafeSyslog;
-use PVE::Daemon;
-use Data::Dumper;
-use PVE::RPCEnvironment;
-use PVE::HA::Env;
-use PVE::HA::Env::PVE2;
-use PVE::HA::LRM;
+use PVE::Service::pve_ha_lrm;
-use base qw(PVE::Daemon);
+use PVE::RPCEnvironment;
$SIG{'__WARN__'} = sub {
my $err = $@;
@@ -22,70 +16,14 @@ $SIG{'__WARN__'} = sub {
$@ = $err;
};
-my $cmdline = [$0, @ARGV];
-
-my %daemon_options = (stop_wait_time => 180);
-
-my $daemon = __PACKAGE__->new('pve-ha-lrm', $cmdline, %daemon_options);
-
-my $rpcenv = PVE::RPCEnvironment->init('ha');
-
-$rpcenv->init_request();
-$rpcenv->set_language($ENV{LANG});
-$rpcenv->set_user('root at pam');
-
-sub run {
- my ($self) = @_;
-
- $self->{haenv} = PVE::HA::Env->new('PVE::HA::Env::PVE2', $self->{nodename});
-
- $self->{lrm} = PVE::HA::LRM->new($self->{haenv});
-
- for (;;) {
- $self->{haenv}->loop_start_hook();
-
- my $repeat = $self->{lrm}->do_one_iteration();
-
- $self->{haenv}->loop_end_hook();
+my $prepare = sub {
- last if !$repeat;
- }
-}
+ my $rpcenv = PVE::RPCEnvironment->init('ha');
-sub shutdown {
- my ($self) = @_;
+ $rpcenv->init_request();
+ $rpcenv->set_language($ENV{LANG});
+ $rpcenv->set_user('root at pam');
- $self->{lrm}->shutdown_request();
-}
-
-$daemon->register_start_command();
-$daemon->register_stop_command();
-$daemon->register_status_command();
-
-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-lrm - PVE Local HA Ressource Manager Daemon
-
-=head1 SYNOPSIS
-
-=include synopsis
-
-=head1 DESCRIPTION
-
-This is the Local HA Ressource Manager.
-
-=include pve_copyright
+PVE::Service::pve_ha_lrm->run_cli(undef, undef, $prepare);
--
2.1.4
More information about the pve-devel
mailing list