Permalink
Browse files

Merge branch '2.3.x+win32-service-refacto' into 2.3.x

  • Loading branch information...
g-bougard committed Jul 7, 2017
2 parents 3c915fe + 33f5b01 commit 0b2acbd164afd41875bf14e5e52c5936cf15a5dc
@@ -216,27 +216,36 @@ sub sleep {
sub loadHttpInterface {
my ($self) = @_;
# Handle re-init case
$self->{server}->stop() if ($self->{server});
my $config = $self->{config};
return if $config->{'no-httpd'};
if ($config->{'no-httpd'}) {
# Handle re-init case
$self->{server}->stop() if ($self->{server});
return;
}
my $logger = $self->{logger};
my %server_config = (
logger => $logger,
agent => $self,
htmldir => $self->{datadir} . '/html',
ip => $config->{'httpd-ip'},
port => $config->{'httpd-port'},
trust => $config->{'httpd-trust'}
);
# Handle re-init, don't restart httpd interface unless config changed
if ($self->{server}) {
return unless $self->{server}->needToRestart(%server_config);
$self->{server}->stop();
}
FusionInventory::Agent::HTTP::Server->require();
if ($EVAL_ERROR) {
$logger->error("Failed to load HTTP server: $EVAL_ERROR");
} else {
$self->{server} = FusionInventory::Agent::HTTP::Server->new(
logger => $logger,
agent => $self,
htmldir => $self->{datadir} . '/html',
ip => $config->{'httpd-ip'},
port => $config->{'httpd-port'},
trust => $config->{'httpd-trust'}
);
$self->{server} = FusionInventory::Agent::HTTP::Server->new(%server_config);
$self->{server}->init();
}
}
@@ -260,6 +269,9 @@ sub RunningServiceOptimization {
sub terminate {
my ($self) = @_;
# Still stop HTTP interface
$self->{server}->stop() if ($self->{server});
$self->{logger}->info("$PROVIDER Agent exiting");
$self->SUPER::terminate();
@@ -248,6 +248,9 @@ sub ApplyServiceOptimizations {
# Preload is64bit result to avoid a lot of WMI calls
is64bit();
# Also call running service optimization to free memory
$self->RunningServiceOptimization();
}
sub RunningServiceOptimization {
@@ -31,6 +31,14 @@ sub new {
};
bless $self, $class;
$self->setTrustedAddresses(%params);
return $self;
}
sub setTrustedAddresses {
my ($self, %params) = @_;
# compute addresses allowed for push requests
foreach my $target ($self->{agent}->getTargets()) {
next unless $target->isa('FusionInventory::Agent::Target::Server');
@@ -45,8 +53,6 @@ sub new {
$self->{trust}->{$string} = \@addresses if @addresses;
}
}
return $self;
}
sub _handle {
@@ -297,7 +303,7 @@ sub init {
LocalAddr => $self->{ip},
LocalPort => $self->{port},
Reuse => 1,
Timeout => 5,
Timeout => 1,
Blocking => 0
);
@@ -313,16 +319,37 @@ sub init {
return 1;
}
sub needToRestart {
my ($self, %params) = @_;
# If no httpd daemon was started, we need to really start it
return 1 unless $self->{listener};
# Restart httpd daemon if ip or port changed
return 1 if ($params{ip} && (!$self->{ip} || $params{ip} ne $self->{ip}));
return 1 if ($params{port} && (!$self->{port} || $params{port} ne $self->{port}));
# Logger may have changed, but then resetting logger ref is sufficient
$self->{logger} = $params{logger};
$self->{logger}->debug2(
$log_prefix . "HTTPD service still listening on port $self->{port}"
);
# Be sure to reset computed trusted addresses
delete $self->{trust};
$self->setTrustedAddresses(%params);
return 0;
}
sub stop {
my ($self) = @_;
return unless $self->{listener};
if ($self->{listener}->shutdown(2)) {
$self->{logger}->debug($log_prefix . "HTTPD service stopped");
} else {
$self->{logger}->debug($log_prefix . "HTTPD service stop error: $!");
}
$self->{listener}->shutdown(2);
$self->{logger}->debug($log_prefix . "HTTPD service stopped");
delete $self->{listener};
}

0 comments on commit 0b2acbd

Please sign in to comment.