2016-02-04 23:10:17 +01:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
use Plack::Runner;
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use POSIX;
|
|
|
|
use Getopt::Std;
|
|
|
|
|
|
|
|
our %opts;
|
|
|
|
my %_apps;
|
|
|
|
|
2016-06-09 13:45:08 +02:00
|
|
|
getopts( 'Fn:p:s:u:g:f:e:', \%opts );
|
2016-02-04 23:10:17 +01:00
|
|
|
|
2016-06-09 13:45:08 +02:00
|
|
|
$SIG{'PIPE'} = 'IGNORE';
|
|
|
|
|
|
|
|
$opts{e} ||= $ENV{ENGINE} || 'FCGI';
|
2016-02-15 19:06:20 +01:00
|
|
|
$opts{n} ||= $ENV{NPROC} || 7;
|
|
|
|
$opts{p} ||= $ENV{PID} || '__FASTCGISOCKDIR__/llng-fastcgi.pid';
|
|
|
|
$opts{s} ||= $ENV{SOCKET} || '__FASTCGISOCKDIR__/llng-fastcgi.sock';
|
2016-02-04 23:10:17 +01:00
|
|
|
$opts{u} ||= $ENV{USER};
|
|
|
|
$opts{g} ||= $ENV{GROUP};
|
2016-02-28 12:51:40 +01:00
|
|
|
$opts{f} ||= $ENV{CUSTOM_FUNCTIONS_FILE};
|
2016-02-04 23:10:17 +01:00
|
|
|
|
|
|
|
if ( $opts{g} ) {
|
|
|
|
my $grp = getgrnam( $opts{g} ) or warn "Can't change uid to $opts{g}";
|
2016-02-16 09:21:34 +01:00
|
|
|
POSIX::setgid($grp);
|
2016-02-04 23:10:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( $opts{u} ) {
|
|
|
|
my $uid = getpwnam( $opts{u} ) or warn "Can't change uid to $opts{u}";
|
|
|
|
POSIX::setuid($uid);
|
|
|
|
}
|
|
|
|
|
2016-06-09 13:45:08 +02:00
|
|
|
if ( $opts{f} ) {
|
|
|
|
eval { require $opts{f} };
|
|
|
|
die $@ if ($@);
|
2016-02-28 12:51:40 +01:00
|
|
|
}
|
|
|
|
|
2016-02-04 23:10:17 +01:00
|
|
|
my %builder = (
|
|
|
|
handler => sub {
|
|
|
|
require Lemonldap::NG::Handler::Nginx;
|
|
|
|
return Lemonldap::NG::Handler::Nginx->run( {} );
|
|
|
|
},
|
2016-07-16 08:05:36 +02:00
|
|
|
reload => sub {
|
|
|
|
require Lemonldap::NG::Handler::Nginx;
|
|
|
|
return Lemonldap::NG::Handler::Nginx->reload();
|
|
|
|
},
|
2016-02-11 13:09:53 +01:00
|
|
|
status => sub {
|
|
|
|
require Lemonldap::NG::Handler::Nginx;
|
|
|
|
return Lemonldap::NG::Handler::Nginx->status();
|
|
|
|
},
|
2016-02-04 23:10:17 +01:00
|
|
|
manager => sub {
|
|
|
|
require Lemonldap::NG::Manager;
|
|
|
|
return Lemonldap::NG::Manager->run( {} );
|
|
|
|
},
|
2016-02-18 11:50:02 +01:00
|
|
|
cgi => sub {
|
2016-02-04 23:10:17 +01:00
|
|
|
require CGI::Emulate::PSGI;
|
|
|
|
require CGI::Compile;
|
2016-02-07 09:32:46 +01:00
|
|
|
return sub {
|
2016-02-16 09:56:03 +01:00
|
|
|
my $script = $_[0]->{SCRIPT_FILENAME};
|
2016-02-07 09:32:46 +01:00
|
|
|
return $_apps{$script}->(@_) if ( $_apps{$script} );
|
|
|
|
$_apps{$script} =
|
|
|
|
CGI::Emulate::PSGI->handler( CGI::Compile->compile($script) );
|
2016-02-08 13:57:56 +01:00
|
|
|
return $_apps{$script}->(@_);
|
2016-02-07 09:32:46 +01:00
|
|
|
};
|
2016-02-04 23:10:17 +01:00
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
unless ($>) {
|
|
|
|
die "Refuse to run as root. Aborting";
|
|
|
|
}
|
|
|
|
|
|
|
|
my $app = sub {
|
|
|
|
my $type = $_[0]->{LLTYPE} || 'handler';
|
|
|
|
return $_apps{$type}->(@_) if ( defined $_apps{$type} );
|
|
|
|
if ( defined $builder{$type} ) {
|
|
|
|
$_apps{$type} = $builder{$type}->();
|
|
|
|
return $_apps{$type}->(@_);
|
|
|
|
}
|
|
|
|
die "Unknown PSGI type $type";
|
|
|
|
};
|
|
|
|
|
2016-02-28 12:51:40 +01:00
|
|
|
# Hook for customFunctions initialization
|
2016-03-17 23:19:44 +01:00
|
|
|
use Lemonldap::NG::Handler::PSGI::API;
|
|
|
|
Lemonldap::NG::Handler::PSGI::API->init();
|
2016-02-11 13:09:53 +01:00
|
|
|
|
2016-02-04 23:10:17 +01:00
|
|
|
my $server = Plack::Runner->new();
|
|
|
|
$server->parse_options(
|
2016-06-09 13:45:08 +02:00
|
|
|
'-s' => $opts{e},
|
2016-02-04 23:10:17 +01:00
|
|
|
'-E' => 'deployment',
|
|
|
|
'--pid' => $opts{p},
|
|
|
|
'--nproc' => $opts{n},
|
2016-02-09 00:26:15 +01:00
|
|
|
'--socket' => $opts{s},
|
2016-02-04 23:10:17 +01:00
|
|
|
'--proc-title' => 'llng-fastcgi-server',
|
2016-02-21 07:43:01 +01:00
|
|
|
( $opts{F} ? () : '--daemonize' ),
|
2016-02-04 23:10:17 +01:00
|
|
|
'--no-default-middleware',
|
|
|
|
);
|
|
|
|
|
|
|
|
$server->run($app);
|
2016-02-07 09:32:40 +01:00
|
|
|
__END__
|
2016-02-04 23:10:17 +01:00
|
|
|
|
2016-02-07 09:32:40 +01:00
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
=encoding utf8
|
|
|
|
|
|
|
|
llng-fastcgi-server - FastCGI server used to provide Lemonldap::NG services to
|
|
|
|
Nginx
|
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
|
|
|
# Start server listening to /run/llng.sock with 10 process
|
|
|
|
llng-fastcgi-server -u nobody -g nobody -s /run/llng.sock -n 10
|
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
llng-fastcgi-server has been designed provides Lemonldap::NG services to Nginx.
|
|
|
|
Portal, manager and handler will be compiled only is used. So this FastCGI
|
|
|
|
server can be used on every Lemonldap::NG server even if it needs only some
|
|
|
|
parts (isolated handlers, portal,...).
|
|
|
|
|
2016-06-09 13:45:08 +02:00
|
|
|
=head1 PARAMETERS
|
|
|
|
|
|
|
|
Each parameter can be set by an option or a environment variable.
|
|
|
|
|
|
|
|
=over
|
|
|
|
|
|
|
|
=item -p ($ENV{PID}): pid file
|
|
|
|
|
|
|
|
=item -u ($ENV{USER}): user
|
|
|
|
|
|
|
|
=item -g ($ENV{GROUP}): group
|
|
|
|
|
|
|
|
=item -n ($ENV{NPROC}): Number of processus for FCGI
|
|
|
|
|
|
|
|
=item -e ($ENV{ENGINE}): Plack::Handler engine, default to FCGI
|
|
|
|
|
|
|
|
=item -s ($ENV{SOCKET}): Unix socket
|
|
|
|
|
|
|
|
=item -f ($ENV{CUSTOM_FUNCTIONS_FILE}): file to load for custom functions
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
2016-02-07 09:32:40 +01:00
|
|
|
=head1 SEE ALSO
|
|
|
|
|
|
|
|
L<http://lemonldap-ng.org/>
|
|
|
|
|
|
|
|
=head1 AUTHORS
|
|
|
|
|
|
|
|
=over
|
|
|
|
|
|
|
|
=item Clement Oudot, E<lt>clem.oudot@gmail.comE<gt>
|
|
|
|
|
|
|
|
=item Xavier Guimard, E<lt>x.guimard@free.frE<gt>
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
=head1 BUG REPORT
|
|
|
|
|
|
|
|
Use OW2 system to report bug or ask for features:
|
|
|
|
L<http://jira.ow2.org>
|
|
|
|
|
|
|
|
=head1 DOWNLOAD
|
|
|
|
|
|
|
|
Lemonldap::NG is available at
|
|
|
|
L<http://forge.objectweb.org/project/showfiles.php?group_id=274>
|
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE
|
|
|
|
|
|
|
|
=over
|
|
|
|
|
|
|
|
=item Copyright (C) 2008-2016 by Xavier Guimard, E<lt>x.guimard@free.frE<gt>
|
|
|
|
|
|
|
|
=item Copyright (C) 2008-2016 by Clément Oudot, E<lt>clem.oudot@gmail.comE<gt>
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see L<http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
=cut
|