]> git.proxmox.com Git - pve-ha-manager.git/commitdiff
convert pve-ha-crm into a PVE::Service class
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 14 Sep 2015 15:21:56 +0000 (17:21 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 15 Sep 2015 05:30:41 +0000 (07:30 +0200)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/Makefile
src/PVE/Service/Makefile
src/PVE/Service/pve_ha_crm.pm [new file with mode: 0644]
src/pve-ha-crm

index 358ca129b1f93435071b3072ba44c407621b1316..1928d4cba8dc2119d008d51024d1f01b5b48f438 100644 (file)
@@ -18,8 +18,11 @@ all: watchdog-mux
        rm -f $@
        cat $<|pod2man -n $* -s 1 -r ${VERSION} -c "Proxmox Documentation"|gzip -c9 >$@
 
-pve-ha-crm.1.pod: pve-ha-crm
-       perl -I. ./pve-ha-crm printmanpod >$@
+pve-ha-crm.1.pod:
+       perl -I. -T -e "use PVE::Service::pve_ha_crm; PVE::Service::pve_ha_crm->generate_pod_manpage();" >$@
+
+pve-ha-crm.bash-completion:
+       perl -I. -T -e "use PVE::Service::pve_ha_crm; PVE::Service::pve_ha_crm->generate_bash_completions();" >$@
 
 pve-ha-lrm.1.pod:
        perl -I. -T -e "use PVE::Service::pve_ha_lrm; PVE::Service::pve_ha_lrm->generate_pod_manpage();" >$@
@@ -39,8 +42,8 @@ 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 pve-ha-lrm.bash-completion
-       perl -I. ./pve-ha-crm verifyapi
+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 pve-ha-crm.bash-completion
+       perl -I. -T -e "use PVE::Service::pve_ha_crm; PVE::Service::pve_ha_crm->verify_api();"
        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}
@@ -48,6 +51,7 @@ install: watchdog-mux pve-ha-crm pve-ha-lrm ha-manager.1.pod ha-manager.1.gz pve
        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-crm.bash-completion ${DESTDIR}${BASHCOMPLDIR}/pve-ha-crm
        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
index 8502c8d716a650f494d337b696818a838737195c..51058850345c79a244646bb932e7a714a6d42347 100644 (file)
@@ -1,4 +1,4 @@
-SOURCES=pve_ha_lrm.pm
+SOURCES=pve_ha_lrm.pm pve_ha_crm.pm
 
 .PHONY: install
 install: ${SOURCES}
diff --git a/src/PVE/Service/pve_ha_crm.pm b/src/PVE/Service/pve_ha_crm.pm
new file mode 100644 (file)
index 0000000..c8325e2
--- /dev/null
@@ -0,0 +1,74 @@
+package PVE::Service::pve_ha_crm;
+
+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);
+
+our $exename = "pve-ha-crm";
+
+my $cmdline = [$0, @ARGV];
+
+my %daemon_options = (stop_wait_time => 60);
+
+my $daemon = __PACKAGE__->new('pve-ha-crm', $cmdline, %daemon_options);
+
+sub run {
+    my ($self) = @_;
+
+    $self->{haenv} = PVE::HA::Env->new('PVE::HA::Env::PVE2', $self->{nodename});
+
+    $self->{crm} = PVE::HA::CRM->new($self->{haenv});
+
+    for (;;) {
+       $self->{haenv}->loop_start_hook();
+
+       my $repeat = $self->{crm}->do_one_iteration();
+
+       $self->{haenv}->loop_end_hook();
+
+       last if !$repeat;
+    }
+}
+
+sub shutdown {
+    my ($self) = @_;
+
+    $self->{crm}->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-crm - PVE Cluster Ressource Manager Daemon
+
+=head1 SYNOPSIS
+
+=include synopsis
+
+=head1 DESCRIPTION
+
+This is the Cluster Ressource Manager.
+
+=include pve_copyright
index 885d4592efb5c34b62bcf799478f0884d00d2f7f..362b91980c0b00fa4a59acd7712423ed154ac08f 100755 (executable)
@@ -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::CRM;
+use PVE::Service::pve_ha_crm;
 
-use base qw(PVE::Daemon);
+use PVE::RPCEnvironment;
 
 $SIG{'__WARN__'} = sub {
     my $err = $@;
@@ -22,70 +16,13 @@ $SIG{'__WARN__'} = sub {
     $@ = $err;
 };
 
-my $cmdline = [$0, @ARGV];
-
-my %daemon_options = (stop_wait_time => 60);
-
-my $daemon = __PACKAGE__->new('pve-ha-crm', $cmdline, %daemon_options);
-
-my $rpcenv = PVE::RPCEnvironment->init('cli');
-
-$rpcenv->init_request();
-$rpcenv->set_language($ENV{LANG});
-$rpcenv->set_user('root@pam');
-
-sub run {
-    my ($self) = @_;
-
-    $self->{haenv} = PVE::HA::Env->new('PVE::HA::Env::PVE2', $self->{nodename});
-
-    $self->{crm} = PVE::HA::CRM->new($self->{haenv});
-
-    for (;;) {
-       $self->{haenv}->loop_start_hook();
-
-       my $repeat = $self->{crm}->do_one_iteration();
-
-       $self->{haenv}->loop_end_hook();
+my $prepare = sub {
+    my $rpcenv = PVE::RPCEnvironment->init('cli');
 
-       last if !$repeat;
-    }
-}
+    $rpcenv->init_request();
+    $rpcenv->set_language($ENV{LANG});
+    $rpcenv->set_user('root@pam');
 
-sub shutdown {
-    my ($self) = @_;
-
-    $self->{crm}->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-crm - PVE Cluster Ressource Manager Daemon
-
-=head1 SYNOPSIS
-
-=include synopsis
-
-=head1 DESCRIPTION
-
-This is the Cluster Ressource Manager.
-
-=include pve_copyright
+PVE::Service::pve_ha_crm->run_cli(undef, undef, $prepare);