atom feed39 messages in ru.sysoev.nginxRe: FCGI.pm ?
FromSent OnAttachments
Chris CorteseFeb 26, 2009 12:40 am 
mikeFeb 26, 2009 1:07 am 
Chris CorteseFeb 26, 2009 1:35 am 
Anoop AliasFeb 26, 2009 1:43 am 
Chris CorteseFeb 26, 2009 2:08 am 
Grzegorz NosekFeb 26, 2009 2:26 am 
Chris CorteseFeb 26, 2009 3:11 am 
Jim OhlsteinFeb 26, 2009 3:35 am 
Grzegorz NosekFeb 26, 2009 4:03 am 
mikeFeb 26, 2009 9:47 am 
Jim OhlsteinFeb 26, 2009 11:53 am 
Cliff WellsFeb 26, 2009 1:02 pm 
mikeFeb 26, 2009 2:19 pm 
Jim OhlsteinFeb 26, 2009 3:10 pm 
Chris CorteseFeb 27, 2009 2:31 am 
lubenFeb 27, 2009 6:11 am 
lubenFeb 27, 2009 6:40 am 
Grzegorz NosekFeb 28, 2009 4:17 am 
mikeFeb 28, 2009 2:03 pm 
Roger HooverMar 3, 2009 1:45 pm 
mikeMar 3, 2009 6:10 pm 
Roger HooverMar 3, 2009 8:08 pm 
Grzegorz NosekMar 4, 2009 12:40 am 
mikeMar 4, 2009 12:54 am 
Grzegorz NosekMar 4, 2009 1:42 am 
Jean-Philippe MoalMar 4, 2009 1:50 am 
mikeMar 4, 2009 2:14 am 
Roger HooverMar 4, 2009 9:03 am 
Roger HooverMar 4, 2009 9:23 am 
mikeMar 4, 2009 11:51 am 
Roger HooverMar 4, 2009 12:34 pm 
mikeMar 4, 2009 8:53 pm 
mikeMar 4, 2009 9:05 pm 
Roger HooverMar 5, 2009 9:22 am 
mikeMar 5, 2009 9:55 am 
Roger HooverMar 5, 2009 12:25 pm 
mikeMar 5, 2009 4:15 pm 
Roger HooverMar 6, 2009 5:21 pm 
mikeMar 6, 2009 6:16 pm 
Subject:Re: FCGI.pm ?
From:luben (lub@unixsol.org)
Date:Feb 27, 2009 6:11:22 am
List:ru.sysoev.nginx

Some while ago I had problems starting perl fcgi processes and the example code didn't worked for me. So I whote a little fcgi launcher, optimized for perl applications.

You could find it attached to the message. It expects to have "run" method for handling the request (CGI::Application integration) but you could change the expected method name in the code to integrate with different platforms. I could even make it an option if there is a need.

Use the code freely.

#!/usr/bin/perl use FCGI; use FCGI::ProcManager; use Getopt::Long; use POSIX qw(setsid :signal_h); use CGI; use strict;

our $socket;

my ($name,$lib,$module,$nproc,$sock,$pidfile,$daemon,$run); $nproc=2; $run ='run';

my $result = GetOptions ( 'name=s' => \$name, 'lib=s' => \$lib, 'module=s' => \$module, 'handler=s' => \$run, 'nproc=i' => \$nproc, 'socket=s' => \$sock, 'pidfile=s' => \$pidfile, 'daemon' => \$daemon); die( "$0 # required --name=$name --module=$module --socket=$sock # optional --lib=$lib --handler=$run --nproc=$nproc --pidfile=$pidfile --daemon=$daemon ]") unless $name && $module && $sock;

# patch FCGI::ProcManager to not mangle process names sub FCGI::ProcManager::managing_init { my ($this) = @_; unless ($this->no_signals()) { sigaction(SIGTERM, $this->{sigaction_no_sa_restart}) or $this->pm_warn("sigaction: SIGTERM: $!"); sigaction(SIGHUP, $this->{sigaction_no_sa_restart}) or $this->pm_warn("sigaction: SIGHUP: $!"); $FCGI::ProcManager::SIG_CODEREF = sub { $this->sig_manager(@_) }; } $this->pm_write_pid_file(); }

sub daemonize { chdir '/' or die "Can't chdir to /: $!"; defined( my $pid = fork ) or die "Can't fork: $!"; exit if $pid; setsid() or die "Can't start a new session: $!"; umask 0; }

sub main { push @INC,$lib; eval "require $module"; die "Require: $@" if $@; $0 = "fcgi-$name-manager"; my $proc_manager = FCGI::ProcManager->new( {n_processes => $nproc, pid_fname
=> $pidfile } ); $socket = FCGI::OpenSocket( $sock, 250 ); # 250 requests queue my $request= FCGI::Request( \*STDIN, \*STDOUT, \*STDERR, \%ENV, $socket,
&FCGI::FAIL_ACCEPT_ON_INTR ); $proc_manager->pm_manage(); request_loop($proc_manager,$request) if $request; FCGI::CloseSocket($socket); }

sub request_loop { my ($pm,$req) = @_; $0 = "fcgi-$name"; my $obj = eval "new $module"; die "New $module: $@" if $@; while ( $req->Accept() >=0 ) { CGI::_reset_globals; $obj->{__QUERY_OBJ} = new CGI; $obj->$run(); } }

daemonize() if $daemon; main();