Enable custom functions with FastCGI server (#583)

This commit is contained in:
Xavier Guimard 2016-02-28 11:51:40 +00:00
parent 91228b5767
commit e51c39cfea
6 changed files with 25 additions and 1 deletions

View File

@ -10,3 +10,6 @@ PID=/var/run/llng-fastcgi-server/llng-fastcgi-server.pid
# User and GROUP
USER=www-data
GROUP=www-data
# Custom functions file
#CUSTOM_FUNCTIONS_FILE=/var/lib/lemonldap-ng/myfile.pm

View File

@ -37,6 +37,10 @@ fi
DAEMON_OPTS="-p ${PID} -u ${USER} -g ${GROUP} -s ${SOCKET}"
if [ -z "$CUSTOM_FUNCTIONS_FILE" ]; then
DAEMON_OPTS="$DAEMON_OPTS -f ${CUSTOM_FUNCTIONS_FILE}"
fi
start_server() {
# Start the daemon/service
#

View File

@ -10,3 +10,6 @@ PID=__FASTCGISOCKDIR__/llng-fastcgi-server.pid
# User and GROUP
USER=__USER__
GROUP=__GROUP__
# Custom functions file
#CUSTOM_FUNCTIONS_FILE=/var/lib/lemonldap-ng/myfile.pm

View File

@ -37,6 +37,10 @@ fi
DAEMON_OPTS="-p ${PID} -u ${USER} -g ${GROUP} -s ${SOCKET}"
if [ -z "$CUSTOM_FUNCTIONS_FILE" ]; then
DAEMON_OPTS="$DAEMON_OPTS -f ${CUSTOM_FUNCTIONS_FILE}"
fi
start_server() {
# Start the daemon/service
#

View File

@ -10,13 +10,14 @@ use Lemonldap::NG::Handler::SharedConf;
our %opts;
my %_apps;
getopts( 'Fn:p:s:u:g:', \%opts );
getopts( 'Fn:p:s:u:g:f:', \%opts );
$opts{n} ||= $ENV{NPROC} || 7;
$opts{p} ||= $ENV{PID} || '__FASTCGISOCKDIR__/llng-fastcgi.pid';
$opts{s} ||= $ENV{SOCKET} || '__FASTCGISOCKDIR__/llng-fastcgi.sock';
$opts{u} ||= $ENV{USER};
$opts{g} ||= $ENV{GROUP};
$opts{f} ||= $ENV{CUSTOM_FUNCTIONS_FILE};
if ( $opts{g} ) {
my $grp = getgrnam( $opts{g} ) or warn "Can't change uid to $opts{g}";
@ -28,6 +29,11 @@ if ( $opts{u} ) {
POSIX::setuid($uid);
}
if($opts{f}) {
eval {require $opts{f}};
die $@ if($@);
}
my %builder = (
handler => sub {
require Lemonldap::NG::Handler::Nginx;
@ -68,6 +74,9 @@ my $app = sub {
die "Unknown PSGI type $type";
};
# Hook for customFunctions initialization
use Lemonldap::NG::Handler::API::PSGI::Server;
$Lemonldap::NG::Handler::API::mode = 'PSGI::Server';
Lemonldap::NG::Handler::SharedConf->init();
my $server = Plack::Runner->new();

View File

@ -5,6 +5,7 @@ use strict;
use base 'Lemonldap::NG::Handler::API::PSGI';
*cgiName = *Lemonldap::NG::Handler::API::PSGI::cgiName;
*uri_with_args = *Lemonldap::NG::Handler::API::PSGI::uri_with_args;
# In server mode, headers are not passed to a PSGI application but returned
# to the server