WIP
This commit is contained in:
Quentin Garnier 2014-10-20 17:58:36 +02:00
parent 92db819eae
commit d5862c4495
2 changed files with 25 additions and 20 deletions

View File

@ -20,6 +20,7 @@ sub new {
my ($class, %options) = @_;
$connector = {};
bless $connector, $class;
$connector->set_signal_handlers;
$connector->{child_proc} = {};
$connector->{return_child} = {};
@ -82,13 +83,13 @@ sub class_handle_CHLD {
sub handle_TERM {
my $self = shift;
$self->{logger}->writeLogInfo("$$ Receiving order to stop...");
$self->{logger}->writeLogInfo("connector '" . $self->{whoaim} . "' Receiving order to stop...");
$self->{stop} = 1;
}
sub handle_HUP {
my $self = shift;
$self->{logger}->writeLogInfo("$$ Receiving order to reload...");
$self->{logger}->writeLogInfo("connector $$ Receiving order to reload...");
# TODO
}
@ -163,6 +164,7 @@ sub reqclient {
$self->{modules_registry}->{$result->{command}}->run();
centreon::esxd::common::response(token => 'RESPSERVER2', endpoint => $backend, reinit => 'ipc://routing.ipc');
zmq_close($backend);
exit(0);
}
} else {
@ -223,8 +225,10 @@ sub run {
eval {
$connector->{session1}->logout();
};
}
exit (0);
}
zmq_close($backend);
exit(0);
}
###

View File

@ -193,6 +193,11 @@ sub handle_TERM {
my $self = shift;
$self->{logger}->writeLogInfo("$$ Receiving order to stop...");
$self->{stop} = 1;
foreach (keys %{$self->{childs_vpshere_pid}}) {
kill('TERM', $_);
$self->{logger}->writeLogInfo("Send -TERM signal to '" . $self->{childs_vpshere_pid}->{$_} . "' process..");
}
}
sub handle_HUP {
@ -208,6 +213,7 @@ sub handle_CHLD {
while (($child_pid = waitpid(-1, &WNOHANG)) > 0) {
$self->{return_child}{$child_pid} = {status => 1, rtime => time()};
}
$SIG{CHLD} = \&class_handle_CHLD;
}
@ -229,20 +235,20 @@ sub verify_child_vsphere {
foreach (keys %{$self->{return_child}}) {
delete $self->{return_child}->{$_};
# We need to quit
if ($self->{stop} != 0) {
my $name = $self->{childs_vpshere_pid}->{$_};
$self->{centreonesxd_config}->{vsphere_server}->{$name}->{running} = 0;
next;
}
if (defined($self->{childs_vpshere_pid}->{$_})) {
$self->{logger}->writeLogError("Sub-process for '" . $self->{childs_vpshere_pid}->{$_} . "' dead ???!! We relaunch it");
$self->create_vsphere_child(vsphere_name => $self->{childs_vpshere_pid}->{$_});
if ($self->{stop} == 0) {
$self->{logger}->writeLogError("Sub-process for '" . $self->{childs_vpshere_pid}->{$_} . "'???!! we relaunch it!!!");
$self->create_vsphere_child(vsphere_name => $self->{childs_vpshere_pid}->{$_});
} else {
$self->{logger}->writeLogInfo("Sub-process for '" . $self->{childs_vpshere_pid}->{$_} . "' dead ???!!");
$self->{centreonesxd_config}->{vsphere_server}->{$self->{childs_vpshere_pid}->{$_}}->{running} = 0;
}
delete $self->{childs_vpshere_pid}->{$_};
}
}
my $count = 0;
foreach (keys %{$self->{centreonesxd_config}->{vsphere_server}}) {
if ($self->{centreonesxd_config}->{vsphere_server}->{$_}->{running} == 1) {
@ -399,14 +405,9 @@ sub run {
# No childs
if ($count == 0) {
$centreonesxd->{logger}->writeLogInfo("Quit main process");
zmq_close($frontend);
exit(0);
}
foreach (keys %{$centreonesxd->{centreonesxd_config}->{vsphere_server}}) {
$centreonesxd->{logger}->writeLogInfo("Send STOP command to '$_' child.");
zmq_sendmsg($frontend, "server-" . $_, ZMQ_SNDMORE);
zmq_sendmsg($frontend, "STOP");
}
$centreonesxd->{stop} = 2;
}
zmq_poll(\@poll, 5000);