Commit e51c39cf authored by Yadd's avatar Yadd
Browse files

Enable custom functions with FastCGI server (#583)

parent 91228b57
...@@ -10,3 +10,6 @@ PID=/var/run/llng-fastcgi-server/llng-fastcgi-server.pid ...@@ -10,3 +10,6 @@ PID=/var/run/llng-fastcgi-server/llng-fastcgi-server.pid
# User and GROUP # User and GROUP
USER=www-data USER=www-data
GROUP=www-data GROUP=www-data
# Custom functions file
#CUSTOM_FUNCTIONS_FILE=/var/lib/lemonldap-ng/myfile.pm
...@@ -37,6 +37,10 @@ fi ...@@ -37,6 +37,10 @@ fi
DAEMON_OPTS="-p ${PID} -u ${USER} -g ${GROUP} -s ${SOCKET}" 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_server() {
# Start the daemon/service # Start the daemon/service
# #
......
...@@ -10,3 +10,6 @@ PID=__FASTCGISOCKDIR__/llng-fastcgi-server.pid ...@@ -10,3 +10,6 @@ PID=__FASTCGISOCKDIR__/llng-fastcgi-server.pid
# User and GROUP # User and GROUP
USER=__USER__ USER=__USER__
GROUP=__GROUP__ GROUP=__GROUP__
# Custom functions file
#CUSTOM_FUNCTIONS_FILE=/var/lib/lemonldap-ng/myfile.pm
...@@ -37,6 +37,10 @@ fi ...@@ -37,6 +37,10 @@ fi
DAEMON_OPTS="-p ${PID} -u ${USER} -g ${GROUP} -s ${SOCKET}" 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_server() {
# Start the daemon/service # Start the daemon/service
# #
......
...@@ -10,13 +10,14 @@ use Lemonldap::NG::Handler::SharedConf; ...@@ -10,13 +10,14 @@ use Lemonldap::NG::Handler::SharedConf;
our %opts; our %opts;
my %_apps; my %_apps;
getopts( 'Fn:p:s:u:g:', \%opts ); getopts( 'Fn:p:s:u:g:f:', \%opts );
$opts{n} ||= $ENV{NPROC} || 7; $opts{n} ||= $ENV{NPROC} || 7;
$opts{p} ||= $ENV{PID} || '__FASTCGISOCKDIR__/llng-fastcgi.pid'; $opts{p} ||= $ENV{PID} || '__FASTCGISOCKDIR__/llng-fastcgi.pid';
$opts{s} ||= $ENV{SOCKET} || '__FASTCGISOCKDIR__/llng-fastcgi.sock'; $opts{s} ||= $ENV{SOCKET} || '__FASTCGISOCKDIR__/llng-fastcgi.sock';
$opts{u} ||= $ENV{USER}; $opts{u} ||= $ENV{USER};
$opts{g} ||= $ENV{GROUP}; $opts{g} ||= $ENV{GROUP};
$opts{f} ||= $ENV{CUSTOM_FUNCTIONS_FILE};
if ( $opts{g} ) { if ( $opts{g} ) {
my $grp = getgrnam( $opts{g} ) or warn "Can't change uid to $opts{g}"; my $grp = getgrnam( $opts{g} ) or warn "Can't change uid to $opts{g}";
...@@ -28,6 +29,11 @@ if ( $opts{u} ) { ...@@ -28,6 +29,11 @@ if ( $opts{u} ) {
POSIX::setuid($uid); POSIX::setuid($uid);
} }
if($opts{f}) {
eval {require $opts{f}};
die $@ if($@);
}
my %builder = ( my %builder = (
handler => sub { handler => sub {
require Lemonldap::NG::Handler::Nginx; require Lemonldap::NG::Handler::Nginx;
...@@ -68,6 +74,9 @@ my $app = sub { ...@@ -68,6 +74,9 @@ my $app = sub {
die "Unknown PSGI type $type"; 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(); Lemonldap::NG::Handler::SharedConf->init();
my $server = Plack::Runner->new(); my $server = Plack::Runner->new();
......
...@@ -5,6 +5,7 @@ use strict; ...@@ -5,6 +5,7 @@ use strict;
use base 'Lemonldap::NG::Handler::API::PSGI'; use base 'Lemonldap::NG::Handler::API::PSGI';
*cgiName = *Lemonldap::NG::Handler::API::PSGI::cgiName; *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 # In server mode, headers are not passed to a PSGI application but returned
# to the server # to the server
......
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