Commit 7c105e2d authored by Xavier Guimard's avatar Xavier Guimard

Fix status for Apache (closes: #1448)

parent 28c4429b
......@@ -37,6 +37,9 @@
header unset Lm-Remote-User
</Files>
# Uncomment this if status is enabled
#FcgidInitialEnv LLNGSTATUSHOST 127.0.0.1:64321
# Static files
Alias /static/ __PORTALSTATICDIR__/
<Directory __PORTALSTATICDIR__>
......
......@@ -43,6 +43,9 @@
header unset Lm-Remote-User
</Files>
# Uncomment this if status is enabled
#FcgidInitialEnv LLNGSTATUSHOST 127.0.0.1:64321
# Static files
Alias /static/ __PORTALSTATICDIR__/
<Directory __PORTALSTATICDIR__>
......
......@@ -38,6 +38,9 @@
header unset Lm-Remote-User
</Files>
# Uncomment this if status is enabled
#FcgidInitialEnv LLNGSTATUSHOST 127.0.0.1:64321
# Static files
Alias /static/ __PORTALSTATICDIR__/
<Directory __PORTALSTATICDIR__>
......
......@@ -43,6 +43,7 @@ our $request; # Apache2::RequestRec object for current request
#*run = \&Lemonldap::NG::Handler::Main::run;
$ENV{LLNGSTATUSLISTEN} ||= '127.0.0.1:64321';
__PACKAGE__->init();
# INTERNAL METHODS
......
......@@ -7,6 +7,7 @@ use strict;
use POSIX qw(setuid setgid);
use JSON qw(to_json);
use IO::Select;
use IO::Socket::INET;
our $VERSION = '2.0.0';
......@@ -118,6 +119,16 @@ sub run {
my ( $lastMn, $mn, $count, $cache, @ready );
my $sel = IO::Select->new;
$sel->add( \*STDIN );
while ( my $opt = shift @ARGV ) {
if ( $opt eq '--udp' ) {
my $hp = shift @ARGV;
my $s = IO::Socket::INET->new( Proto => 'udp', LocalAddr => $hp );
$sel->add($s);
}
else {
die "Unknown option $opt";
}
}
while ( @ready = $sel->can_read ) {
foreach my $fh (@ready) {
if ( $fh == \*STDIN and $fh->eof ) {
......@@ -178,13 +189,13 @@ sub run {
# $args contains parameters passed to url status page (a=1 for example
# if request is http://test.example.com/status?a=1). To be used
# later...
elsif (/^STATUS\s*(\S+)?$/) {
elsif (/^STATUS\s*(.+)?$/) {
my $tmp = $1;
my $out;
if ( $fh == \*STDIN ) {
$out = \*STDOUT;
}
elsif ( $tmp =~ /host=(\S+)$/ ) {
elsif ( $tmp =~ s/\s*host=(\S+)$// ) {
$out =
IO::Socket::INET->new( Proto => "udp", PeerAddr => $1 );
unless ($out) {
......
......@@ -42,8 +42,7 @@ sub init($$) {
$class->serverSignatureInit unless ( $class->localConfig->{hideSignature} );
# * launch status process
$class->statusInit() if ( $class->localConfig->{status} and $statusInit );
$statusInit = 0;
$class->statusInit();
1;
}
......@@ -74,29 +73,52 @@ sub serverSignatureInit {
# Launch the status process
sub statusInit {
my ($class) = @_;
return if ( $class->tsv->{statusPipe} and $class->tsv->{statusOut} );
require IO::Pipe;
my $statusPipe = IO::Pipe->new;
my $statusOut = IO::Pipe->new;
if ( my $pid = fork() ) {
$class->logger->debug("Status collector launched ($pid)");
$statusPipe->writer();
$statusOut->reader();
$statusPipe->autoflush(1);
( $class->tsv->{statusPipe}, $class->tsv->{statusOut} ) =
( $statusPipe, $statusOut );
return unless ( $class->localConfig->{status} and $statusInit );
$statusInit = 0;
return if ( $class->tsv->{statusPipe} );
if ( $ENV{LLNGSTATUSHOST} ) {
require IO::Socket::INET;
$class->tsv->{statusPipe} = IO::Socket::INET->new(
Proto => 'udp',
PeerAddr => $ENV{LLNGSTATUSHOST}
);
$class->tsv->{statusOut} = undef;
}
else {
$statusPipe->reader();
$statusOut->writer();
my $fdin = $statusPipe->fileno;
my $fdout = $statusOut->fileno;
open STDIN, "<&$fdin";
open STDOUT, ">&$fdout";
my $perl_exec = ( $^X =~ /perl/ ) ? $^X : 'perl';
exec $perl_exec, '-MLemonldap::NG::Handler::Lib::Status',
map( { "-I$_" } @INC ),
'-e', '&Lemonldap::NG::Handler::Lib::Status::run()';
require IO::Pipe;
my $statusPipe = IO::Pipe->new;
my $statusOut = IO::Pipe->new;
if ( my $pid = fork() ) {
$class->logger->debug("Status collector launched ($pid)");
$statusPipe->writer();
$statusOut->reader();
$statusPipe->autoflush(1);
( $class->tsv->{statusPipe}, $class->tsv->{statusOut} ) =
( $statusPipe, $statusOut );
}
else {
$statusPipe->reader();
$statusOut->writer();
my $fdin = $statusPipe->fileno;
my $fdout = $statusOut->fileno;
open STDIN, "<&$fdin";
open STDOUT, ">&$fdout";
my $perl_exec = ( $^X =~ /perl/ ) ? $^X : 'perl';
exec $perl_exec, '-MLemonldap::NG::Handler::Lib::Status',
# Insert @INC in Perl path
map( { "-I$_" } @INC ),
# Command to launch
'-e', '&Lemonldap::NG::Handler::Lib::Status::run()',
# Optional arg: UDP socket to listen to
(
$ENV{LLNGSTATUSLISTEN}
? ( '--', '--udp', $ENV{LLNGSTATUSLISTEN} )
: ()
);
}
}
}
......
......@@ -40,10 +40,25 @@ sub getStatus {
$class->logger->debug("Request for status");
my $statusPipe = $class->tsv->{statusPipe};
my $statusOut = $class->tsv->{statusOut};
my $args = '';
if ( $ENV{LLNGSTATUSHOST} ) {
require IO::Socket::INET;
foreach ( 64322 .. 64331 ) {
if ( $statusOut =
IO::Socket::INET->new( Proto => 'udp', LocalPort => $_ ) )
{
$args = ' host=' . ( $ENV{LLNGSTATUSCLIENT} || 'localhost' ) . ":$_";
last;
}
}
return $class->abort( $req,
"$class: status page can not be displayed, unable to open socket" )
unless ($statusOut);
}
return $class->abort( $req, "$class: status page can not be displayed" )
unless ( $statusPipe and $statusOut );
$statusPipe->print(
"STATUS " . ( $req->{env}->{QUERY_STRING} || '' ) . "\n" );
"STATUS " . ( $req->{env}->{QUERY_STRING} || '' ) . "$args\n" );
my $buf;
while ( $_ = $statusOut->getline ) {
......
......@@ -9,6 +9,7 @@ use strict;
use Mouse;
use JSON qw(from_json);
use MIME::Base64;
use IO::Socket::INET;
our $VERSION = '2.0.0';
......@@ -27,10 +28,25 @@ sub status {
my ( $self, $req ) = @_;
my $res = {};
if ( my $p = $self->p->HANDLER->tsv->{statusPipe} ) {
$p->print("STATUS json=1\n");
my $buf;
$p = $self->p->HANDLER->tsv->{statusOut};
while ( $_ = $p->getline ) {
my ( $args, $buf );
my $out = $self->p->HANDLER->tsv->{statusOut};
if ( $ENV{LLNGSTATUSHOST} ) {
foreach ( 64322 .. 64331 ) {
if ( $out =
IO::Socket::INET->new( Proto => 'udp', LocalPort => $_ ) )
{
$args = " host="
. ( $ENV{LLNGSTATUSCLIENT} || 'localhost' ) . ":$_";
last;
}
}
}
unless ($out) {
return $self->p->sendError( $req, 'No status connection' );
}
$p->print("STATUS json=1$args\n");
while ( $_ = $out->getline ) {
last if (/^END$/);
$buf .= $_;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment