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

Fix status for Apache (closes: #1448)

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