pkgsrc-WIP-changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

FCGI:: Daemon is a small FastCGI server for use as CGI-wrapper suitable for Perl scripts being served by the nginx web server.



Module Name:	pkgsrc-wip
Committed By:	ast <ast%NetBSD.org@localhost>
Pushed By:	ast
Date:		Sun Feb 7 23:16:46 2016 +0100
Changeset:	c38492d02b3cdabbf04069af096690d88408e6d7

Added Files:
	p5-FCGI-Daemon/DESCR
	p5-FCGI-Daemon/Makefile
	p5-FCGI-Daemon/PLIST
	p5-FCGI-Daemon/distinfo
	p5-FCGI-Daemon/files/fcgi_daemon.sh
	p5-FCGI-Daemon/patches/patch-bsd1
	p5-FCGI-Daemon/patches/patch-bsd2
	p5-FCGI-Daemon/patches/patch-bsd3
	p5-FCGI-Daemon/patches/patch-bsd4
	p5-FCGI-Daemon/patches/patch-bsd5
	p5-FCGI-Daemon/patches/patch-bsd6

Log Message:
FCGI::Daemon is a small FastCGI server for use as CGI-wrapper
suitable for Perl scripts being served by the nginx web server.

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=c38492d02b3cdabbf04069af096690d88408e6d7

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 p5-FCGI-Daemon/DESCR                | 17 +++++++++
 p5-FCGI-Daemon/Makefile             | 47 +++++++++++++++++++++++
 p5-FCGI-Daemon/PLIST                |  7 ++++
 p5-FCGI-Daemon/distinfo             | 12 ++++++
 p5-FCGI-Daemon/files/fcgi_daemon.sh | 76 +++++++++++++++++++++++++++++++++++++
 p5-FCGI-Daemon/patches/patch-bsd1   | 23 +++++++++++
 p5-FCGI-Daemon/patches/patch-bsd2   | 15 ++++++++
 p5-FCGI-Daemon/patches/patch-bsd3   | 37 ++++++++++++++++++
 p5-FCGI-Daemon/patches/patch-bsd4   | 54 ++++++++++++++++++++++++++
 p5-FCGI-Daemon/patches/patch-bsd5   | 57 ++++++++++++++++++++++++++++
 p5-FCGI-Daemon/patches/patch-bsd6   | 28 ++++++++++++++
 11 files changed, 373 insertions(+)

diffs:
diff --git a/p5-FCGI-Daemon/DESCR b/p5-FCGI-Daemon/DESCR
new file mode 100644
index 0000000..9305022
--- /dev/null
+++ b/p5-FCGI-Daemon/DESCR
@@ -0,0 +1,17 @@
+FCGI::Daemon is a small FastCGI server for use as CGI-wrapper for
+CGI applications.
+
+Like mod_perl FCGI-Daemon stay persistent in memory and accelerate
+unmodified CGI applications written in Perl.
+
+FCGI-Daemon run CGI scripts with RLIMITs and predefined number of
+workers.
+
+It was developed as replacement for cgiwrap-fcgi.pl
+(http://wiki.nginx.org/SimpleCGI) and fcgiwrap
+(http://nginx.localdomain.pl/wiki/FcgiWrap).
+
+FCGI-Daemon check for executable in path and correctly set PATH_INFO
+environment variable which is crucial for some CGI applications
+like fossil (http://fossil-scm.org). (Lack of this functionality
+make cgiwrap-fcgi.pl unsuitable for some scripts.)
diff --git a/p5-FCGI-Daemon/Makefile b/p5-FCGI-Daemon/Makefile
new file mode 100644
index 0000000..41e4871
--- /dev/null
+++ b/p5-FCGI-Daemon/Makefile
@@ -0,0 +1,47 @@
+# $NetBSD$
+
+PKGBASE=        FCGI-Daemon
+DISTNAME=       ${PKGBASE}-0.20151226
+PKGNAME=        p5-${DISTNAME}
+PKGREVISION=    1
+CATEGORIES=     www perl5
+MASTER_SITES=   ${MASTER_SITE_PERL_CPAN:=FCGI/}
+
+MAINTAINER=     ast%NetBSD.org@localhost
+HOMEPAGE=       http://search.cpan.org/dist/FCGI-Daemon/
+COMMENT=        Perl-aware Fast CGI daemon for use with nginx web server
+LICENSE=        gnu-agpl-v3
+
+USE_TOOLS+=     perl:run
+
+DEPENDS+=       p5-FCGI>=0.71:../../www/p5-FCGI
+DEPENDS+=       p5-BSD-Resource>=1.29:../../devel/p5-BSD-Resource
+DEPENDS+=       p5-FCGI-ProcManager>=0.18:../../www/p5-FCGI-ProcManager
+
+FCGID_EG_DIR=   share/examples/fcgi-daemon
+FCGID_NGINX=    nginx/common.conf nginx/ikiwiki.conf nginx/sample.conf
+
+INSTALLATION_DIRS+= ${FCGID_EG_DIR} ${FCGID_EG_DIR}/nginx
+INSTALLATION_DIRS+= ${PERL5_SUB_INSTALLVENDORMAN3DIR}
+INSTALLATION_DIRS+= ${PERL5_SUB_INSTALLVENDORLIB}/FCGI
+
+REPLACE_PERL=   lib/FCGI/Daemon.pm
+
+RCD_SCRIPTS=    fcgi_daemon
+
+do-install:
+	${INSTALL_SCRIPT} \
+		${WRKSRC}/blib/lib/FCGI/Daemon.pm \
+			${DESTDIR}${PREFIX}/${PERL5_SUB_INSTALLVENDORLIB}/FCGI
+	${INSTALL_MAN} \
+		${WRKSRC}/blib/man3/FCGI::Daemon.3 \
+			${DESTDIR}${PREFIX}/${PERL5_SUB_INSTALLVENDORMAN3DIR}
+
+post-install:
+.for file in ${FCGID_NGINX}
+	${INSTALL_DATA} ${WRKSRC}/examples/${file} \
+		${DESTDIR}${PREFIX}/${FCGID_EG_DIR}/nginx
+.endfor
+
+.include "../../lang/perl5/module.mk"
+.include "../../mk/bsd.pkg.mk"
diff --git a/p5-FCGI-Daemon/PLIST b/p5-FCGI-Daemon/PLIST
new file mode 100644
index 0000000..4d05ea1
--- /dev/null
+++ b/p5-FCGI-Daemon/PLIST
@@ -0,0 +1,7 @@
+@comment $NetBSD$
+share/examples/rc.d/fcgi_daemon
+share/examples/fcgi-daemon/nginx/common.conf
+share/examples/fcgi-daemon/nginx/ikiwiki.conf
+share/examples/fcgi-daemon/nginx/sample.conf
+${PERL5_SUB_INSTALLVENDORLIB}/FCGI/Daemon.pm
+lib/perl5/vendor_perl/man/man3/FCGI::Daemon.3
diff --git a/p5-FCGI-Daemon/distinfo b/p5-FCGI-Daemon/distinfo
new file mode 100644
index 0000000..80f3491
--- /dev/null
+++ b/p5-FCGI-Daemon/distinfo
@@ -0,0 +1,12 @@
+$NetBSD$
+
+SHA1 (FCGI-Daemon-0.20151226.tar.gz) = 75b43915cfd860b5ad9072a6cc472267eef40804
+RMD160 (FCGI-Daemon-0.20151226.tar.gz) = 8f56061adb572e43d3c7cde9c7416a9920a4c16f
+SHA512 (FCGI-Daemon-0.20151226.tar.gz) = 67e0e92a8a01400c70a219f9df7c30a1f67c0ee0ea9506f0dbf388473a9931d64f2a5d7f4b34329241ae5c5bd1caf55dfce4f1dd1b5f4d6f6c7ee4615612dd14
+Size (FCGI-Daemon-0.20151226.tar.gz) = 23375 bytes
+SHA1 (patch-bsd1) = bd6eef790759a1eb2df143f888820b47fbce4d3c
+SHA1 (patch-bsd2) = adedc89ffc5cfc2289ebad569e495273d80df3cf
+SHA1 (patch-bsd3) = 0a59d856c66b0f8dc829c858fd4caf58660ff281
+SHA1 (patch-bsd4) = 31491220625b8691962dd354d588a081dcf52229
+SHA1 (patch-bsd5) = c504b293a68cb07429914a0d6b00fe7c72cab8e0
+SHA1 (patch-bsd6) = b09927b4637f0fc9bc8bd2eed0e606cc2ca7cfa5
diff --git a/p5-FCGI-Daemon/files/fcgi_daemon.sh b/p5-FCGI-Daemon/files/fcgi_daemon.sh
new file mode 100755
index 0000000..2ff32f1
--- /dev/null
+++ b/p5-FCGI-Daemon/files/fcgi_daemon.sh
@@ -0,0 +1,76 @@
+#!/bin/sh
+#
+# $NetBSD$
+#
+
+# PROVIDE: fcgi_daemon
+# REQUIRE: DAEMON
+# BEFORE:  LOGIN
+
+$_rc_subr_loaded . /etc/rc.subr
+
+name="fcgi_daemon"
+pidfile="/var/run/${name}.pid"
+sockfile="/var/run/${name}.sock"
+rcvar=$name
+
+start_cmd="fcgi_daemon_start"
+status_cmd="fcgi_daemon_status"
+stop_cmd="fcgi_daemon_stop"
+
+extra_commands="status"
+
+fcgi_daemon_args="-p ${pidfile} -s ${sockfile} -u nginx -g nginx -w 2 -d"
+
+cmd_args=${fcgi_daemon_flags:-$fcgi_daemon_args}
+
+perl='/usr/pkg/bin/perl'
+[ -x ${perl} ] || { echo "Missing ${perl}">&2; exit 1; }
+
+cmd=`${perl} -MFCGI::Daemon -e 'print $INC{"FCGI/Daemon.pm"}' 2>/dev/null`
+[ -f "${cmd}" ] || { echo "Missing FCGI::Daemon Perl module">&2; exit 1; }
+
+fcgi_daemon_start()
+{
+    /usr/bin/env - ${perl} ${cmd} ${cmd_args}
+    if [ $? -eq 0 ]; then
+        echo "$name manager and workers started."
+    else
+        echo "$name failed to start."
+    fi
+}
+
+fcgi_daemon_status()
+{
+    local pids p t
+
+    pids=`/usr/bin/pgrep FCGI::Daemon`
+    [ -z "$pids" ] && { echo "No $name running."; exit 1; }
+
+    # list all FCGI::Daemon processes
+    t=/bin/cat
+    for p in $pids; do
+        /bin/ps -ouser,group,pid,ppid,cpu,vsz,rss,wchan,time,command -p $p | $t
+        t='/usr/bin/tail -1'
+    done
+
+    # list all socket files
+    /usr/bin/sockstat -l | /usr/bin/head -1
+    /usr/bin/sockstat -l | /usr/bin/grep ${sockfile}
+
+    return 0
+}
+
+fcgi_daemon_stop()
+{
+    kill `cat ${pidfile} 2>/dev/null` >/dev/null 2>&1
+    if [ $? -eq 0 ]; then
+        echo "$name stopped."
+    else
+        echo "Failed to stop $name."
+        fcgi_daemon_status
+    fi
+}
+
+load_rc_config $name
+run_rc_command "$1"
diff --git a/p5-FCGI-Daemon/patches/patch-bsd1 b/p5-FCGI-Daemon/patches/patch-bsd1
new file mode 100644
index 0000000..16ab651
--- /dev/null
+++ b/p5-FCGI-Daemon/patches/patch-bsd1
@@ -0,0 +1,23 @@
+$NetBSD$
+
+Use POSIX calls setgid and setuid to non-root user when running as
+"root" daemon; add debug flag.
+
+--- lib/FCGI/Daemon.pm.orig	2015-12-26 09:28:53.000000000 +0100
++++ lib/FCGI/Daemon.pm	2016-02-07 18:03:39.000000000 +0100
+@@ -7,12 +7,15 @@
+ our $VERSION = '0.20151226';
+ use 5.14.2;
+ use English '-no_match_vars';
++use POSIX;
+ use BSD::Resource;                      # on Debian available as libbsd-resource-perl
+ use FCGI 0.71;                          # on Debian available as libfcgi-perl
+ use FCGI::ProcManager 0.18;             # on Debian available as libfcgi-procmanager-perl
+ use Getopt::Std;
+ use autouse 'Pod::Usage'=>qw(pod2usage);
+ 
++my $DEBUG = 0;
++
+ =head1 NAME
+ 
+ FCGI::Daemon - Perl-aware Fast CGI daemon for use with nginx web server.
diff --git a/p5-FCGI-Daemon/patches/patch-bsd2 b/p5-FCGI-Daemon/patches/patch-bsd2
new file mode 100644
index 0000000..7392306
--- /dev/null
+++ b/p5-FCGI-Daemon/patches/patch-bsd2
@@ -0,0 +1,15 @@
+$NetBSD$
+
+Attempt to unlink each file one by one.
+
+--- lib/FCGI/Daemon.pm.orig	2015-12-26 09:28:53.000000000 +0100
++++ lib/FCGI/Daemon.pm	2016-02-07 18:03:39.000000000 +0100
+@@ -39,7 +42,7 @@
+ sub dieif {
+     if($ARG[0]){
+         my $err=$ARG[1];
+-        unlink @o{'pidfile','sockfile'};
++        unlink $o{$_} for qw(pidfile sockfile);
+         print "Error - $err:\n",$ARG[0],"\n";
+         exit 1;
+     }
diff --git a/p5-FCGI-Daemon/patches/patch-bsd3 b/p5-FCGI-Daemon/patches/patch-bsd3
new file mode 100644
index 0000000..2bc0f00
--- /dev/null
+++ b/p5-FCGI-Daemon/patches/patch-bsd3
@@ -0,0 +1,37 @@
+$NetBSD$
+
+Use only $EFFECTIVE_USER_ID to discrimiate if we need to set[gu]id
+and don't install signal handlers INT and TERM as FCGI::ProcManager
+does that.
+
+--- lib/FCGI/Daemon.pm.orig	2015-12-26 09:28:53.000000000 +0100
++++ lib/FCGI/Daemon.pm	2016-02-07 18:03:39.000000000 +0100
+@@ -62,26 +65,18 @@
+     $o{file_pattern}=$o{'f'}||qr{\.pl};
+     $o{leak_threshold}=$o{'l'}||1.3;
+ 
+-    if($REAL_USER_ID==$EFFECTIVE_USER_ID and $EFFECTIVE_USER_ID==0){        # if run as root
++    if($EFFECTIVE_USER_ID==0){
+         $o{gid}=$o{g}||'www-data'; $o{gid_num}=scalar getgrnam($o{gid});
+         $o{uid}=$o{u}||'www-data'; $o{uid_num}=scalar getpwnam($o{uid});
+     }
+ 
+-    local $SIG{INT}= local $SIG{TERM}= sub{
+-        # actually FCGI::ProcManager override our TERM handler so .sock and .pid files will be removed only by sysv script... :(
+-        $o{fcgi_pm}->pm_remove_pid_file() if $o{fcgi_pm};
+-        unlink @o{'sockfile','pidfile'};
+-        $o{fcgi_pm}->pm_die() if $o{fcgi_pm};   #pm_die() does not return
+-        exit 0;
+-    };
+-
+     # daemonize
+     if($o{'d'}){
+         chdir '/';                              # this is good practice for unmounting
+         local $PROGRAM_NAME='FCGI::Daemon';
+         defined(my $pid=fork) or die "Can't fork: $!";
+         exit if $pid;
+-        eval {use POSIX qw(setsid); POSIX::setsid();} or die q{Can't start a new session: }.$OS_ERROR;
++        POSIX::setsid() or die q{Can't start a new session: }.$OS_ERROR;
+         open *STDIN,'<','/dev/null';
+         open *STDOUT,'>>','/dev/null';
+         open *STDERR,'>>','/dev/null';
diff --git a/p5-FCGI-Daemon/patches/patch-bsd4 b/p5-FCGI-Daemon/patches/patch-bsd4
new file mode 100644
index 0000000..1a5f00b
--- /dev/null
+++ b/p5-FCGI-Daemon/patches/patch-bsd4
@@ -0,0 +1,54 @@
+$NetBSD$
+
+Add debug flag and prepare to remove files in pm_die() routine
+
+--- lib/FCGI/Daemon.pm.orig	2015-12-26 09:28:53.000000000 +0100
++++ lib/FCGI/Daemon.pm	2016-02-07 18:03:39.000000000 +0100
+@@ -94,24 +89,38 @@
+                                         pid_fname=>$o{pidfile}
+                                       });
+     print "Opening socket $o{sockfile}\n";
++    $o{socket_fh} = FCGI::OpenSocket($o{sockfile},$o{prefork}*$o{queue});
+     my $rqst=FCGI::Request(\*STDIN,\*STDOUT,\*STDERR,\%req_env,
+-             FCGI::OpenSocket($o{sockfile},$o{prefork}*$o{queue}),
+-             FCGI::FAIL_ACCEPT_ON_INTR())
++             $o{socket_fh}, FCGI::FAIL_ACCEPT_ON_INTR())
+         or die "Error: Unable to create FCGI::Request...";
+ 
+-    if(defined $o{gid_num} and defined $o{uid_num}){                # if run as root
+-        chown $o{uid_num},$o{gid_num},$o{sockfile}                  # chown SOCKfile
++    if($EFFECTIVE_USER_ID==0){
++        chown $o{uid_num},$o{gid_num},$o{sockfile}
+             or dieif($OS_ERROR,'Unable to chown SOCKfile');
+     }
+ 
+     $o{fcgi_pm}->pm_manage();   # from now on we are worker process
+ 
++    if ($DEBUG) {
++        use Data::Dumper;
++        $Data::Dumper::Indent = 1;
++        warn Data::Dumper->Dump([\%o],['o']);
++    }
++
+     # drop privileges if run as root
+-    if(defined $o{gid_num} and defined $o{uid_num}){
+-        local $REAL_GROUP_ID= local $EFFECTIVE_GROUP_ID= getgrnam($o{gid});
+-            dieif($OS_ERROR,'Unable to change group_id to '.$o{gid});
+-        local $REAL_USER_ID= local $EFFECTIVE_USER_ID= getpwnam($o{uid});
+-            dieif($OS_ERROR,'Unable to change user_id to '.$o{uid});
++    my $old_euid = $EFFECTIVE_USER_ID;
++    if ($old_euid==0) {
++        POSIX::setgid($o{gid_num}) or dieif($OS_ERROR,
++            "UID $old_euid couldn't change group to $o{gid} ($o{gid_num})");
++        POSIX::setuid($o{uid_num}) or dieif($OS_ERROR,
++            "UID $old_euid couldn't change user to $o{uid} ($o{uid_num})");
++    }
++
++    if ($DEBUG) {
++        warn "REAL_USER_ID = $REAL_USER_ID";
++        warn "EFFECTIVE_USER_ID = $EFFECTIVE_USER_ID";
++        warn "REAL_GROUP_ID = $REAL_GROUP_ID";
++        warn "EFFECTIVE_GROUP_ID = $EFFECTIVE_GROUP_ID";
+     }
+ 
+     ## set rlimit(s)
diff --git a/p5-FCGI-Daemon/patches/patch-bsd5 b/p5-FCGI-Daemon/patches/patch-bsd5
new file mode 100644
index 0000000..d1d8cb6
--- /dev/null
+++ b/p5-FCGI-Daemon/patches/patch-bsd5
@@ -0,0 +1,57 @@
+$NetBSD$
+
+Instead of using a non-portable /proc/$$/status read to get memory
+usage on Linux, use a non-portable /bin/ps command on BSD platforms.
+
+--- lib/FCGI/Daemon.pm.orig	2015-12-26 09:28:53.000000000 +0100
++++ lib/FCGI/Daemon.pm	2016-02-07 18:03:39.000000000 +0100
+@@ -171,21 +180,37 @@
+                 delete $main::{$_};
+             }
+ 
+-            if(open my $STAT,'<',"/proc/$$/status"){
+-                my %stat;
+-                while(my ($k,$v)=split /\:\s+/,<$STAT>){
+-                    chop $v;
+-                    $stat{$k}=$v;
++            exit unless --$o{max_evals};
++
++            # exit if child takes too much resident memory
++            my %stat = ();
++            if ( $OSNAME =~ m{bsd}oi ) {
++                if (open my $STAT,'-|',"/bin/ps -o vsz,rss -p $$") {
++                    while(<$STAT>) {
++                        if ( m{^\s*(\d+)\s+(\d+)$}o ) {
++                             $stat{VmSize} = $1;
++                             $stat{VmRSS} = $2;
++                             last;
++                        }
++                    }
++                    close $STAT;
+                 }
+-                close $STAT;
+-                # check if child takes too much resident memory and terminate if necessary
+-                if($stat{VmSize}/$stat{VmRSS}<$o{leak_threshold}){
+-                    print {*STDERR} 'fcgi-daemon :: terminating child - memory leak? '
+-                    ."VmSize:$stat{VmSize}; VmRSS:$stat{VmRSS}; Ratio:".$stat{VmSize}/$stat{VmRSS};
+-                    exit;
++            } else {
++                if(open my $STAT,'<',"/proc/$$/status"){
++                    while(my ($k,$v)=split /\:\s+/,<$STAT>){
++                        chop $v;
++                        $stat{$k}=$v;
++                    }
++                    close $STAT;
+                 }
+             }
+-            exit unless --$o{max_evals};
++            if ( $stat{VmSize} && $stat{VmRSS}
++                   && ($stat{VmSize}/$stat{VmRSS}<$o{leak_threshold}) ) {
++                 die 'fcgi-daemon :: terminating child - memory leak? '
++                     ."VmSize:$stat{VmSize}; VmRSS:$stat{VmRSS}; Ratio:"
++                     .$stat{VmSize}/$stat{VmRSS};
++            }
++
+             next REQ_LOOP;
+         }
+ 
diff --git a/p5-FCGI-Daemon/patches/patch-bsd6 b/p5-FCGI-Daemon/patches/patch-bsd6
new file mode 100644
index 0000000..ef57446
--- /dev/null
+++ b/p5-FCGI-Daemon/patches/patch-bsd6
@@ -0,0 +1,28 @@
+$NetBSD$
+
+Close socket when running as root (manager) and remove files in
+pm_die() routine.
+
+--- lib/FCGI/Daemon.pm.orig	2015-12-26 09:28:53.000000000 +0100
++++ lib/FCGI/Daemon.pm	2016-02-07 18:03:39.000000000 +0100
+@@ -243,6 +268,20 @@
+     return;
+ }
+ 
++# close socket as manager
++sub managing_init {
++    # manager (running as root) doesn't need to listen on the socket
++    close $o{socket_fh} if $EFFECTIVE_USER_ID==0;
++    return $o{fcgi_pm}->managing_init(shift @_);
++}
++
++# exit cleanly
++sub pm_die {
++    # manager (running as root) can remove these better
++    unlink $o{$_} for qw(pidfile sockfile);
++    return $o{fcgi_pm}->pm_die(shift @_);
++}
++
+ # overriding process names
+ sub FCGI::ProcManager::pm_change_process_name {
+     my ($self,$name)=@_;


Home | Main Index | Thread Index | Old Index