Hi,

nobody who cares about this ;-(?

On Sam 22.12.2007 02:27, Aleksandar Lazic wrote:
Hi,

here are know the first steps for a better integration with nginx
(http://nginx.net/) and lighty (http://www.lighttpd.net/).

They are able to connect to fast-cgi (fcgi) backends and the fcgi can
behave like a apache with mod_perl ;-)

The files are:

index_new.fpl => the starting point it forks 5 (n_processes), write a
                 pidfile (pid_fname). In this file depending on the
                 request uri ($ENV{'REQUEST_URI'}) the different
                 interfaces will be called.

fcgi-startup.pl => is mainly a copy from apache2-httpd-new.include.conf
otrs-2.2.4.diff => I have changed some small parts in the otrs System an
                   this are the diffs.
otrs.nginx.conf => nginx configfile. Please pay attention that the
                   socket (fastcgi_pass && FCGI_SOCKET_PATH) is rw for
                   both users (otrs && nginx).

TODOs:

I have only tested it with a small setup.
Better and bigger testing.
Documentation.

start/stop script. I try to decide which process managment system to us,
please can somebody help to find a 'good' way which you can go.

POE::Component::Pool::Thread
(http://search.cpan.org/~tag/POE-Component-Pool-Thread-0.015/Thread.pm)

PTools::Proc::NWay
http://search.cpan.org/~ccobb/PTools-Proc-NWay-0.09/lib/PTools/Proc/NWay.pm

Daemon::Generic
http://search.cpan.org/~muir/Daemon-Generic-0.51/lib/Daemon/Generic.pod

Generic POE solution e.g.
http://poe.perl.org/?POE_Cookbook/Web_Server_With_Forking

DJB's Daemontools http://cr.yp.to/daemontools.html

Other Ideas ;-)

Please tell me what you think and if this is the way otrs is able to go
;-)

Thanks & greetings

Aleks

#!/usr/bin/perl -w
# --
# bin/fcgi-bin/index.fpl - the global FastCGI handle file (incl. auth) for OTRS
# Copyright (C) 2001-2006 OTRS GmbH, http://otrs.org/
# --
# $Id: index.fpl,v 1.4 2006/08/26 17:33:32 martin Exp $
# --
# This program 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 of the License, 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, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
# --

if (not defined $ENV{'FCGI_SOCKET_PATH'}){
 die "Please export the 'FCGI_SOCKET_PATH'";
}

# use ../../ as lib location
use FindBin qw($Bin);
use lib "$Bin/../..";
use lib "$Bin/../../Kernel/cpan-lib";

use vars qw($VERSION @INC);
$VERSION = '$Revision: 1.4 $';
$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/;

# check @INC for mod_perl (add lib path for "require module"!)
push (@INC, "$Bin/../..", "$Bin/../../Kernel/cpan-lib");

# Imports the library; required line
use CGI::Fast;
use strict;
use FCGI::ProcManager;

# load agent web interface
use Kernel::System::Web::InterfaceAgent();

require "scripts/fcgi-startup.pl";

# create common objects
my %CommonObject = ();
$CommonObject{ConfigObject} = Kernel::Config->new();
$CommonObject{LogObject} = Kernel::System::Log->new(
   LogPrefix => 'FCGI-Starter',
   ConfigObject => $CommonObject{ConfigObject},
);
#$CommonObject{MainObject} = Kernel::System::Main->new(%CommonObject);
#$CommonObject{DBObject} = Kernel::System::DB->new(%CommonObject);

my $proc_manager = FCGI::ProcManager->new({ n_processes => 5 , pid_fname => 
'fcgi.pid' });

# 0=off;1=on;
my $Debug = 03;
my $FCGI_Mode = 1;
#my $Cnt = 0;

$proc_manager->pm_manage();

# Response loop
while (my $WebRequest = new CGI::Fast) {

 my $Interface;

 $CommonObject{LogObject}->Log(
           Priority => 'Debug',
           Message =>  "index_new.fpl:".$ENV{'REQUEST_URI'},
 );

   $proc_manager->pm_pre_dispatch();

   if ( $ENV{'REQUEST_URI'} =~ /index\.fpl/o ){
     # create new object
     $Interface= Kernel::System::Web::InterfaceAgent->new(Debug => $Debug, 
WebRequest => $WebRequest ,
                                                           FCGI_Mode => 
$FCGI_Mode);
   } elsif ( $ENV{'REQUEST_URI'} =~ /customer\.fpl/o ){
     # create new object
     $Interface = Kernel::System::Web::InterfaceCustomer->new(Debug => $Debug, 
WebRequest => $WebRequest);
   } elsif ( $ENV{'REQUEST_URI'} =~ /public\.fpl/o ){
     # create new object
     $Interface = Kernel::System::Web::InterfacePublic->new(Debug => $Debug, 
WebRequest => $WebRequest);
   }

   $Interface->Run();

   $proc_manager->pm_post_dispatch();

#    $Cnt++;
#    print STDERR "This is connection number $Cnt\n";
}


Only in otrs-2.2.4_fcgi/bin/fcgi-bin: index_new.fpl
diff -ru otrs-2.2.4/Kernel/System/DB.pm otrs-2.2.4_fcgi/Kernel/System/DB.pm
+++ otrs-2.2.4_fcgi/Kernel/System/DB.pm 2007-12-20 13:06:49.000000000 +0100
@@ -76,6 +76,8 @@
    # 0=off; 1=updates; 2=+selects; 3=+Connects;
    $Self->{Debug} = $Param{Debug} || 0;

+    $Self->{FCGI_Mode} = $Param{FCGI_Mode} || 0;
+
    # check needed objects
    foreach (qw(ConfigObject LogObject MainObject)) {
        if ($Param{$_}) {
@@ -794,7 +796,9 @@

sub DESTROY {
    my $Self = shift;
-    $Self->Disconnect();
+    if (!$Self->{FCGI_Mode}) {
+      $Self->Disconnect();
+    }
    return 1;
}
1;
diff -ru otrs-2.2.4/Kernel/System/Web/InterfaceAgent.pm 
otrs-2.2.4_fcgi/Kernel/System/Web/InterfaceAgent.pm
+++ otrs-2.2.4_fcgi/Kernel/System/Web/InterfaceAgent.pm 2007-12-20 
13:05:55.000000000 +0100
@@ -67,6 +67,8 @@
    # get debug level
    $Self->{Debug} = $Param{Debug} || 0;

+    $Self->{FCGI_Mode} = $Param{FCGI_Mode} || 0;
+
    # performance log
    $Self->{PerformanceLogStart} = time();

@@ -707,16 +709,29 @@
            Comment => 'Please contact your admin'
        );
    }
+
+
    # debug info
    if ($Self->{Debug}) {
-        $Self->{LogObject}->Log(
-            Priority => 'debug',
+      $Self->{LogObject}->Log(
+           Priority => 'debug',
            Message => 'Global handle stopped.',
        );
    }
-    # db disconnect && undef %Param
-    $Self->{DBObject}->Disconnect();
-    undef %Param;
+
+    if (!$Self->{FCGI_Mode}) {
+      # db disconnect && undef %Param
+      $Self->{DBObject}->Disconnect();
+    }else{
+      if ($Self->{Debug}) {
+      $Self->{LogObject}->Log(
+           Priority => 'debug',
+            Message => 'DB connection NOT Disconnected.',
+        );
+    }
+    }
+
+      undef %Param;
}

1;
Only in otrs-2.2.4_fcgi/scripts: fcgi-startup.pl

user  nobody;
worker_processes  5;

#error_log  logs/error.log;
#error_log  logs/error.log  debug;
#error_log  logs/error.log  notice;
error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
   worker_connections  1024;
}


http {
   include       mime.types;
   default_type  application/octet-stream;

   log_format timing '$remote_addr [$time_local] $request $status '
                     'msec $msec upstream_response_time $upstream_response_time 
'
                     'upstream_status $upstream_status';

   access_log  logs/access.log combined;

   sendfile        on;
   #tcp_nopush     on;

   #keepalive_timeout  0;
   keepalive_timeout  65;

   #gzip  on;

   # another virtual host using mix of IP-, name-, and port-based configuration
   #
   server {
       listen       8000;
       server_name  _;

       client_max_body_size 15m;

       location /otrs-web {
         alias /home/otrs/download/otrs/otrs-2.2.4/var/httpd/htdocs;
       }

       location / {
           root   /opt/otrs/var/httpd/htdocs/;
           # FCGI_SOCKET_PATH in the fcgi-process env
           fastcgi_pass   unix:/home/otrs/sock/otrs.sock;
           fastcgi_index index.fpl;
           fastcgi_param  SCRIPT_FILENAME  
/opt/otrs/bin/fcgi-bin$fastcgi_script_name;
           include        fastcgi_params;
#            index  index.html index.htm;
       }
   }
}

_______________________________________________
OTRS mailing list: dev - Webpage: http://otrs.org/
Archive: http://lists.otrs.org/pipermail/dev
To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/dev
_______________________________________________
OTRS mailing list: dev - Webpage: http://otrs.org/
Archive: http://lists.otrs.org/pipermail/dev
To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/dev

Reply via email to