diff options
author | ivan <ivan> | 2010-05-18 18:49:59 +0000 |
---|---|---|
committer | ivan <ivan> | 2010-05-18 18:49:59 +0000 |
commit | e70abd21bab68b23488f7ef1ee2e693a3b365691 (patch) | |
tree | 75986ffa9ba6ab4f961f9033468a1344e1653408 /rt/bin | |
parent | b4b0c7e72d7eaee2fbfc7022022c9698323203dd (diff) |
import rt 3.8.8
Diffstat (limited to 'rt/bin')
-rwxr-xr-x | rt/bin/fastcgi_server | 252 | ||||
-rw-r--r-- | rt/bin/fastcgi_server.in | 252 | ||||
-rwxr-xr-x | rt/bin/mason_handler.fcgi | 25 | ||||
-rw-r--r-- | rt/bin/mason_handler.fcgi.in | 25 | ||||
-rwxr-xr-x | rt/bin/mason_handler.scgi | 7 | ||||
-rw-r--r-- | rt/bin/mason_handler.scgi.in | 7 | ||||
-rwxr-xr-x | rt/bin/rt | 5 | ||||
-rw-r--r-- | rt/bin/rt.in | 5 | ||||
-rwxr-xr-x | rt/bin/standalone_httpd | 2 | ||||
-rwxr-xr-x | rt/bin/standalone_httpd.in | 2 | ||||
-rwxr-xr-x | rt/bin/webmux.pl | 154 | ||||
-rw-r--r-- | rt/bin/webmux.pl.in | 154 |
12 files changed, 684 insertions, 206 deletions
diff --git a/rt/bin/fastcgi_server b/rt/bin/fastcgi_server new file mode 100755 index 000000000..7c0935dfe --- /dev/null +++ b/rt/bin/fastcgi_server @@ -0,0 +1,252 @@ +#!/usr/bin/perl +# BEGIN BPS TAGGED BLOCK {{{ +# +# COPYRIGHT: +# +# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC +# <jesse@bestpractical.com> +# +# (Except where explicitly superseded by other copyright notices) +# +# +# LICENSE: +# +# This work is made available to you under the terms of Version 2 of +# the GNU General Public License. A copy of that license should have +# been provided with this software, but in any event can be snarfed +# from www.gnu.org. +# +# This work 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., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301 or visit their web page on the internet at +# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. +# +# +# CONTRIBUTION SUBMISSION POLICY: +# +# (The following paragraph is not intended to limit the rights granted +# to you to modify and distribute this software under the terms of +# the GNU General Public License and is only of importance to you if +# you choose to contribute your changes and enhancements to the +# community by submitting them to Best Practical Solutions, LLC.) +# +# By intentionally submitting any modifications, corrections or +# derivatives to this work, or any other work intended for use with +# Request Tracker, to Best Practical Solutions, LLC, you confirm that +# you are the copyright holder for those contributions and you grant +# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, +# royalty-free, perpetual, license to use, copy, create derivative +# works based on those contributions, and sublicense and distribute +# those contributions and any derivatives thereof. +# +# END BPS TAGGED BLOCK }}} + +=head1 NAME + +fastcgi_server - external FastCGI server for RT + +=head1 USAGE + + # get help + fastcgi_server -h + + # start a server using defaults + fastcgi_server + + # start server with custom option + fastcgi_server --socket /path/to/socket -n 5 + fastcgi_server --port 12345 -n 5 + +=head1 DESCRIPTION + +This is a forking external FastCGI server for RT, it can be used +with apache and other servers supporting FastCGI technology. + +An advantage is lower memory usage because of sharing memory +between process. It's easier to setup this with nginx and other +servers that can not maintain pool of fastcgi servers, apache +can do this. + +Disadvantage is that you have to start this server yourself and +monitor it, web servers wouldn't be able to restart it on crash. + +=head1 OPTIONS + +=over 4 + +=item -h, --help - get help + +=item -n, --nprocesses - number of processes to start, by default 10 + +=item -s, --socket - socket path, by default F<RT/var/path/fastcgi.sock> +usually F</opt/rt3/var/fastcgi.sock>. + +=item -p, --port - port to use instead of socket, by default socket is +used. + +=item --pidfile - pid file path, by default F<RT/var/path/fastcgi.pid>. + +=back + +=head1 SERVER CONFIGURATION + +=head2 nginx + +Below you can find example of minimal config for nginx to run RT +with this FastCGI server. It's not ideal, but a good enough start. + + worker_processes 1; + events { worker_connections 1024; } + + pid /opt/rt3/var/nginx/server.pid; + error_log /opt/rt3/var/nginx/error.log debug; + + http { + access_log /opt/rt3/var/nginx/access.log; + + server { + listen 8080; + server_name localhost; + + location / { + root /opt/rt3/share/html; + fastcgi_pass unix:/opt/rt3/var/fastcgi.sock; + + fastcgi_param QUERY_STRING $query_string; + fastcgi_param REQUEST_METHOD $request_method; + fastcgi_param CONTENT_TYPE $content_type; + fastcgi_param CONTENT_LENGTH $content_length; + fastcgi_param PATH_INFO $fastcgi_script_name; + } + + location /NoAuth/images/ { + alias /opt/rt3/share/html/NoAuth/images/; + } + } + } + +=head1 lighttpd + +Server config: + + server.name = "localhost" + server.port = 80 + + server.username = "rt_web_user" + server.groupname = "rt_web_group" + + server.pid-file = "/opt/rt3/var/lighthttpd/server.pid" + server.errorlog = "/opt/rt3/var/lighthttpd/error.log" + + server.document-root = "/opt/rt3/share/html" + + server.modules = ( "mod_fastcgi" ) + fastcgi.server = ( + "/" => (( + "socket" => "/opt/rt3/var/fastcgi.sock", + "check-local" => "disable", + "fix-root-scriptname" => "enable", + )) + ) + +=cut + + +use strict; +use warnings; +no warnings qw(once); + +package RT::Interface::Web::FCGI::Server; +use base qw(FCGI::ProcManager); + +package main; + +use Getopt::Long; + +my %opt = ( + help => 0, + socket => '', + port => 0, + nprocesses => 10, + pidfile => '', +); + +GetOptions( + 'h|help!' => \$opt{'help'}, + 's|socket=s' => \$opt{'socket'}, + 'p|port=s' => \$opt{'port'}, + 'n|nprocesses=s' => \$opt{'nprocesses'}, + 'pidfile=s' => \$opt{'pidfile'}, +); + +if ( $opt{'help'} ) { + require Pod::Usage; + Pod::Usage::pod2usage( + -message => "", + -exitval => $opt{'help'}? 0 : 1, + -verbose => 99, + -sections => $opt{'help'}? 'NAME|USAGE|DESCRIPTION|OPTIONS' : 'NAME|USAGE', + ); +} + +$ENV{'RT_WEBMUX_HEAVY_LOAD'} = 1; +use File::Basename; +require (dirname(__FILE__) .'/webmux.pl'); + +unless ( $opt{'socket'} && $opt{'port'} ) { + require File::Spec; + $opt{'socket'} = File::Spec->catfile($RT::VarPath, 'fastcgi.sock'); +} +elsif ( $opt{'port'} ) { + $opt{'socket'} = ':'. $opt{'port'}; +} +$ENV{'FCGI_SOCKET_PATH'} = $opt{'socket'}; + +$opt{'pidfile'} ||= File::Spec->catfile($RT::VarPath, 'fastcgi.pid'); + +require CGI::Fast; + +my $proc_manager = RT::Interface::Web::FCGI::Server->new({ + n_processes => $opt{'nprocesses'} || 10, + pid_fname => $opt{'pidfile'}, +}); + +$proc_manager->pm_manage(); + +while ( my $cgi = CGI::Fast->new ) { + $proc_manager->pm_pre_dispatch; + + $ENV{'PATH'} = '/bin:/usr/bin'; + $ENV{'CDPATH'} = '' if defined $ENV{'CDPATH'}; + $ENV{'SHELL'} = '/bin/sh' if defined $ENV{'SHELL'}; + $ENV{'ENV'} = '' if defined $ENV{'ENV'}; + $ENV{'IFS'} = '' if defined $ENV{'IFS'}; + + Module::Refresh->refresh if RT->Config->Get('DevelMode'); + RT::ConnectToDatabase(); + + my $interp = $RT::Mason::Handler->interp; + if ( + !$interp->comp_exists( $cgi->path_info ) + && $interp->comp_exists( $cgi->path_info . "/index.html" ) + ) { + $cgi->path_info( $cgi->path_info . "/index.html" ); + } + + local $@; + eval { $RT::Mason::Handler->handle_cgi_object($cgi); }; + if ($@) { + $RT::Logger->crit($@); + } + RT::Interface::Web::Handler->CleanupRequest; + + $proc_manager->pm_post_dispatch; +} + +1; diff --git a/rt/bin/fastcgi_server.in b/rt/bin/fastcgi_server.in new file mode 100644 index 000000000..a63714488 --- /dev/null +++ b/rt/bin/fastcgi_server.in @@ -0,0 +1,252 @@ +#!@PERL@ +# BEGIN BPS TAGGED BLOCK {{{ +# +# COPYRIGHT: +# +# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC +# <jesse@bestpractical.com> +# +# (Except where explicitly superseded by other copyright notices) +# +# +# LICENSE: +# +# This work is made available to you under the terms of Version 2 of +# the GNU General Public License. A copy of that license should have +# been provided with this software, but in any event can be snarfed +# from www.gnu.org. +# +# This work 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., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301 or visit their web page on the internet at +# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. +# +# +# CONTRIBUTION SUBMISSION POLICY: +# +# (The following paragraph is not intended to limit the rights granted +# to you to modify and distribute this software under the terms of +# the GNU General Public License and is only of importance to you if +# you choose to contribute your changes and enhancements to the +# community by submitting them to Best Practical Solutions, LLC.) +# +# By intentionally submitting any modifications, corrections or +# derivatives to this work, or any other work intended for use with +# Request Tracker, to Best Practical Solutions, LLC, you confirm that +# you are the copyright holder for those contributions and you grant +# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, +# royalty-free, perpetual, license to use, copy, create derivative +# works based on those contributions, and sublicense and distribute +# those contributions and any derivatives thereof. +# +# END BPS TAGGED BLOCK }}} + +=head1 NAME + +fastcgi_server - external FastCGI server for RT + +=head1 USAGE + + # get help + fastcgi_server -h + + # start a server using defaults + fastcgi_server + + # start server with custom option + fastcgi_server --socket /path/to/socket -n 5 + fastcgi_server --port 12345 -n 5 + +=head1 DESCRIPTION + +This is a forking external FastCGI server for RT, it can be used +with apache and other servers supporting FastCGI technology. + +An advantage is lower memory usage because of sharing memory +between process. It's easier to setup this with nginx and other +servers that can not maintain pool of fastcgi servers, apache +can do this. + +Disadvantage is that you have to start this server yourself and +monitor it, web servers wouldn't be able to restart it on crash. + +=head1 OPTIONS + +=over 4 + +=item -h, --help - get help + +=item -n, --nprocesses - number of processes to start, by default 10 + +=item -s, --socket - socket path, by default F<RT/var/path/fastcgi.sock> +usually F</opt/rt3/var/fastcgi.sock>. + +=item -p, --port - port to use instead of socket, by default socket is +used. + +=item --pidfile - pid file path, by default F<RT/var/path/fastcgi.pid>. + +=back + +=head1 SERVER CONFIGURATION + +=head2 nginx + +Below you can find example of minimal config for nginx to run RT +with this FastCGI server. It's not ideal, but a good enough start. + + worker_processes 1; + events { worker_connections 1024; } + + pid /opt/rt3/var/nginx/server.pid; + error_log /opt/rt3/var/nginx/error.log debug; + + http { + access_log /opt/rt3/var/nginx/access.log; + + server { + listen 8080; + server_name localhost; + + location / { + root /opt/rt3/share/html; + fastcgi_pass unix:/opt/rt3/var/fastcgi.sock; + + fastcgi_param QUERY_STRING $query_string; + fastcgi_param REQUEST_METHOD $request_method; + fastcgi_param CONTENT_TYPE $content_type; + fastcgi_param CONTENT_LENGTH $content_length; + fastcgi_param PATH_INFO $fastcgi_script_name; + } + + location /NoAuth/images/ { + alias /opt/rt3/share/html/NoAuth/images/; + } + } + } + +=head1 lighttpd + +Server config: + + server.name = "localhost" + server.port = 80 + + server.username = "rt_web_user" + server.groupname = "rt_web_group" + + server.pid-file = "/opt/rt3/var/lighthttpd/server.pid" + server.errorlog = "/opt/rt3/var/lighthttpd/error.log" + + server.document-root = "/opt/rt3/share/html" + + server.modules = ( "mod_fastcgi" ) + fastcgi.server = ( + "/" => (( + "socket" => "/opt/rt3/var/fastcgi.sock", + "check-local" => "disable", + "fix-root-scriptname" => "enable", + )) + ) + +=cut + + +use strict; +use warnings; +no warnings qw(once); + +package RT::Interface::Web::FCGI::Server; +use base qw(FCGI::ProcManager); + +package main; + +use Getopt::Long; + +my %opt = ( + help => 0, + socket => '', + port => 0, + nprocesses => 10, + pidfile => '', +); + +GetOptions( + 'h|help!' => \$opt{'help'}, + 's|socket=s' => \$opt{'socket'}, + 'p|port=s' => \$opt{'port'}, + 'n|nprocesses=s' => \$opt{'nprocesses'}, + 'pidfile=s' => \$opt{'pidfile'}, +); + +if ( $opt{'help'} ) { + require Pod::Usage; + Pod::Usage::pod2usage( + -message => "", + -exitval => $opt{'help'}? 0 : 1, + -verbose => 99, + -sections => $opt{'help'}? 'NAME|USAGE|DESCRIPTION|OPTIONS' : 'NAME|USAGE', + ); +} + +$ENV{'RT_WEBMUX_HEAVY_LOAD'} = 1; +use File::Basename; +require (dirname(__FILE__) .'/webmux.pl'); + +unless ( $opt{'socket'} && $opt{'port'} ) { + require File::Spec; + $opt{'socket'} = File::Spec->catfile($RT::VarPath, 'fastcgi.sock'); +} +elsif ( $opt{'port'} ) { + $opt{'socket'} = ':'. $opt{'port'}; +} +$ENV{'FCGI_SOCKET_PATH'} = $opt{'socket'}; + +$opt{'pidfile'} ||= File::Spec->catfile($RT::VarPath, 'fastcgi.pid'); + +require CGI::Fast; + +my $proc_manager = RT::Interface::Web::FCGI::Server->new({ + n_processes => $opt{'nprocesses'} || 10, + pid_fname => $opt{'pidfile'}, +}); + +$proc_manager->pm_manage(); + +while ( my $cgi = CGI::Fast->new ) { + $proc_manager->pm_pre_dispatch; + + $ENV{'PATH'} = '/bin:/usr/bin'; + $ENV{'CDPATH'} = '' if defined $ENV{'CDPATH'}; + $ENV{'SHELL'} = '/bin/sh' if defined $ENV{'SHELL'}; + $ENV{'ENV'} = '' if defined $ENV{'ENV'}; + $ENV{'IFS'} = '' if defined $ENV{'IFS'}; + + Module::Refresh->refresh if RT->Config->Get('DevelMode'); + RT::ConnectToDatabase(); + + my $interp = $RT::Mason::Handler->interp; + if ( + !$interp->comp_exists( $cgi->path_info ) + && $interp->comp_exists( $cgi->path_info . "/index.html" ) + ) { + $cgi->path_info( $cgi->path_info . "/index.html" ); + } + + local $@; + eval { $RT::Mason::Handler->handle_cgi_object($cgi); }; + if ($@) { + $RT::Logger->crit($@); + } + RT::Interface::Web::Handler->CleanupRequest; + + $proc_manager->pm_post_dispatch; +} + +1; diff --git a/rt/bin/mason_handler.fcgi b/rt/bin/mason_handler.fcgi index 4fe888a93..0439a3b06 100755 --- a/rt/bin/mason_handler.fcgi +++ b/rt/bin/mason_handler.fcgi @@ -46,23 +46,16 @@ # those contributions and any derivatives thereof. # # END BPS TAGGED BLOCK }}} -package RT::Mason; - use strict; -use vars '$Handler'; -use File::Basename; +use warnings; +no warnings qw(once); -require (dirname(__FILE__) . '/webmux.pl'); +use File::Basename; +require (dirname(__FILE__) .'/webmux.pl'); # Enter CGI::Fast mode, which should also work as a vanilla CGI script. require CGI::Fast; -RT::Init(); -$Handler ||= RT::Interface::Web::Handler->new( - RT->Config->Get('MasonParameters') -); - - while ( my $cgi = CGI::Fast->new ) { # the whole point of fastcgi requires the env to get reset here.. # So we must squash it again @@ -75,12 +68,16 @@ while ( my $cgi = CGI::Fast->new ) { Module::Refresh->refresh if RT->Config->Get('DevelMode'); RT::ConnectToDatabase(); - if ( ( !$Handler->interp->comp_exists( $cgi->path_info ) ) - && ( $Handler->interp->comp_exists( $cgi->path_info . "/index.html" ) ) ) { + my $interp = $RT::Mason::Handler->interp; + if ( + !$interp->comp_exists( $cgi->path_info ) + && $interp->comp_exists( $cgi->path_info . "/index.html" ) + ) { $cgi->path_info( $cgi->path_info . "/index.html" ); } - eval { $Handler->handle_cgi_object($cgi); }; + local $@; + eval { $RT::Mason::Handler->handle_cgi_object($cgi); }; if ($@) { $RT::Logger->crit($@); } diff --git a/rt/bin/mason_handler.fcgi.in b/rt/bin/mason_handler.fcgi.in index 48155f257..baf407d94 100644 --- a/rt/bin/mason_handler.fcgi.in +++ b/rt/bin/mason_handler.fcgi.in @@ -46,23 +46,16 @@ # those contributions and any derivatives thereof. # # END BPS TAGGED BLOCK }}} -package RT::Mason; - use strict; -use vars '$Handler'; -use File::Basename; +use warnings; +no warnings qw(once); -require (dirname(__FILE__) . '/webmux.pl'); +use File::Basename; +require (dirname(__FILE__) .'/webmux.pl'); # Enter CGI::Fast mode, which should also work as a vanilla CGI script. require CGI::Fast; -RT::Init(); -$Handler ||= RT::Interface::Web::Handler->new( - RT->Config->Get('MasonParameters') -); - - while ( my $cgi = CGI::Fast->new ) { # the whole point of fastcgi requires the env to get reset here.. # So we must squash it again @@ -75,12 +68,16 @@ while ( my $cgi = CGI::Fast->new ) { Module::Refresh->refresh if RT->Config->Get('DevelMode'); RT::ConnectToDatabase(); - if ( ( !$Handler->interp->comp_exists( $cgi->path_info ) ) - && ( $Handler->interp->comp_exists( $cgi->path_info . "/index.html" ) ) ) { + my $interp = $RT::Mason::Handler->interp; + if ( + !$interp->comp_exists( $cgi->path_info ) + && $interp->comp_exists( $cgi->path_info . "/index.html" ) + ) { $cgi->path_info( $cgi->path_info . "/index.html" ); } - eval { $Handler->handle_cgi_object($cgi); }; + local $@; + eval { $RT::Mason::Handler->handle_cgi_object($cgi); }; if ($@) { $RT::Logger->crit($@); } diff --git a/rt/bin/mason_handler.scgi b/rt/bin/mason_handler.scgi index 248c57ca2..b5769665e 100755 --- a/rt/bin/mason_handler.scgi +++ b/rt/bin/mason_handler.scgi @@ -56,18 +56,13 @@ require (dirname(__FILE__) . '/webmux.pl'); require CGI; -RT::Init(); -$Handler ||= RT::Interface::Web::Handler->new( - RT->Config->Get('MasonParameters') -); - - my $cgi = CGI->new; if ( ( !$Handler->interp->comp_exists( $cgi->path_info ) ) && ( $Handler->interp->comp_exists( $cgi->path_info . "/index.html" ) ) ) { $cgi->path_info( $cgi->path_info . "/index.html" ); } +RT::ConnectToDatabase(); $Handler->handle_cgi_object($cgi); RT::Interface::Web::Handler->CleanupRequest(); 1; diff --git a/rt/bin/mason_handler.scgi.in b/rt/bin/mason_handler.scgi.in index a853529d0..cd24bc8f8 100644 --- a/rt/bin/mason_handler.scgi.in +++ b/rt/bin/mason_handler.scgi.in @@ -56,18 +56,13 @@ require (dirname(__FILE__) . '/webmux.pl'); require CGI; -RT::Init(); -$Handler ||= RT::Interface::Web::Handler->new( - RT->Config->Get('MasonParameters') -); - - my $cgi = CGI->new; if ( ( !$Handler->interp->comp_exists( $cgi->path_info ) ) && ( $Handler->interp->comp_exists( $cgi->path_info . "/index.html" ) ) ) { $cgi->path_info( $cgi->path_info . "/index.html" ); } +RT::ConnectToDatabase(); $Handler->handle_cgi_object($cgi); RT::Interface::Web::Handler->CleanupRequest(); 1; @@ -1751,10 +1751,7 @@ Title: intro Title: introduction Text: - ** THIS IS AN UNSUPPORTED PREVIEW RELEASE ** - ** PLEASE REPORT BUGS TO rt-bugs@bestpractical.com ** - - This is a command-line interface to RT 3.0 or newer + This is a command-line interface to RT 3.0 or newer. It allows you to interact with an RT server over HTTP, and offers an interface to RT's functionality that is better-suited to automation diff --git a/rt/bin/rt.in b/rt/bin/rt.in index aa3ac33de..6ca302e19 100644 --- a/rt/bin/rt.in +++ b/rt/bin/rt.in @@ -1751,10 +1751,7 @@ Title: intro Title: introduction Text: - ** THIS IS AN UNSUPPORTED PREVIEW RELEASE ** - ** PLEASE REPORT BUGS TO rt-bugs@bestpractical.com ** - - This is a command-line interface to RT 3.0 or newer + This is a command-line interface to RT 3.0 or newer. It allows you to interact with an RT server over HTTP, and offers an interface to RT's functionality that is better-suited to automation diff --git a/rt/bin/standalone_httpd b/rt/bin/standalone_httpd index 241af8114..7b447050b 100755 --- a/rt/bin/standalone_httpd +++ b/rt/bin/standalone_httpd @@ -120,7 +120,7 @@ EOF } else { RT->ConnectToDatabase(); RT->InitSystemObjects(); - RT->InitClasses(); + RT->InitClasses( Heavy => 1 ); RT->InitPlugins(); RT->Config->PostLoadCheck(); diff --git a/rt/bin/standalone_httpd.in b/rt/bin/standalone_httpd.in index b87a33206..aa9204b68 100755 --- a/rt/bin/standalone_httpd.in +++ b/rt/bin/standalone_httpd.in @@ -120,7 +120,7 @@ EOF } else { RT->ConnectToDatabase(); RT->InitSystemObjects(); - RT->InitClasses(); + RT->InitClasses( Heavy => 1 ); RT->InitPlugins(); RT->Config->PostLoadCheck(); diff --git a/rt/bin/webmux.pl b/rt/bin/webmux.pl index cb428ad2c..c1a0c59bd 100755 --- a/rt/bin/webmux.pl +++ b/rt/bin/webmux.pl @@ -48,20 +48,62 @@ # END BPS TAGGED BLOCK }}} use strict; +package HTML::Mason::Commands; +our %session; + +package RT::Mason; + +our ($Nobody, $SystemUser, $Handler, $r); + +sub handler { + ($r) = @_; + + local $SIG{__WARN__}; + local $SIG{__DIE__}; + RT::InitSignalHandlers(); + + if ($r->content_type =~ m/^httpd\b.*\bdirectory/i) { + use File::Spec::Unix; + # Our DirectoryIndex is always index.html, regardless of httpd settings + $r->filename( File::Spec::Unix->catfile( $r->filename, 'index.html' ) ); + } + + Module::Refresh->refresh if RT->Config->Get('DevelMode'); + + RT::ConnectToDatabase(); + + my (%session, $status); + { + local $@; + $status = eval { $Handler->handle_request($r) }; + $RT::Logger->crit( $@ ) if $@; + } + undef %session; + + RT::Interface::Web::Handler->CleanupRequest(); + + return $status; +} + +package main; + +# check mod_perl version if it's mod_perl +BEGIN { + die "RT does not support mod_perl 1.99. Please upgrade to mod_perl 2.0" + if $ENV{'MOD_PERL'} + and $ENV{'MOD_PERL'} =~ m{mod_perl/(?:1\.9)}; +} + BEGIN { - $ENV{'PATH'} = '/bin:/usr/bin'; # or whatever you need + $ENV{'PATH'} = '/bin:/usr/bin'; # or whatever you need $ENV{'CDPATH'} = '' if defined $ENV{'CDPATH'}; $ENV{'SHELL'} = '/bin/sh' if defined $ENV{'SHELL'}; $ENV{'ENV'} = '' if defined $ENV{'ENV'}; $ENV{'IFS'} = '' if defined $ENV{'IFS'}; - use CGI qw(-private_tempfiles); #bring this in before mason, to make sure we - #set private_tempfiles - - die "RT does not support mod_perl 1.99. Please upgrade to mod_perl 2.0" - if $ENV{'MOD_PERL'} - and $ENV{'MOD_PERL'} =~ m{mod_perl/(?:1\.9)}; - + # bring this in before mason, to make sure we + # use private tempfiles + use CGI qw(-private_tempfiles); } # fix lib paths, some may be relative @@ -88,91 +130,47 @@ BEGIN { } } -use RT; - -package RT::Mason; - -use vars qw($Nobody $SystemUser $Handler $r); -#This drags in RT's config.pm -BEGIN { - RT::LoadConfig(); - if (RT->Config->Get('DevelMode')) { require Module::Refresh; } - RT->InitPluginPaths(); +require RT; +RT::LoadConfig(); +if ( RT->Config->Get('DevelMode') ) { + require Module::Refresh; } +RT::Init(); +# check compatibility of the DB { - require RT::Handle; - my $dsn = RT::Handle->DSN; - my $user = RT->Config->Get('DatabaseUser'); - my $pass = RT->Config->Get('DatabasePassword'); - - my $dbh = DBI->connect( - $dsn, $user, $pass, - { RaiseError => 0, PrintError => 0 }, - ); + my $dbh = $RT::Handle->dbh; if ( $dbh ) { - my ($status, $msg) = RT::Handle->CheckCompatibility( $dbh, 'post' ); + my ($status, $msg) = $RT::Handle->CheckCompatibility( $dbh, 'post' ); die $msg unless $status; } } -{ - package HTML::Mason::Commands; - use vars qw(%session); -} +require RT::Interface::Web::Handler; +$RT::Mason::Handler = RT::Interface::Web::Handler->new( + RT->Config->Get('MasonParameters') +); + +# load more for mod_perl before forking +RT::InitClasses( Heavy => 1 ) if $ENV{'MOD_PERL'} || $ENV{RT_WEBMUX_HEAVY_LOAD}; -use RT::Interface::Web; -use RT::Interface::Web::Handler; +# we must disconnect DB before fork +$RT::Handle->dbh(undef); +undef $RT::Handle; -if ($ENV{'MOD_PERL'} && !RT->Config->Get('DevelMode')) { +if ( $ENV{'MOD_PERL'} && !RT->Config->Get('DevelMode')) { # Under static_source, we need to purge the component cache # each time we restart, so newer components may be reloaded. # - # We can't do this in FastCGI or we'll blow away the component root _every_ time a new server starts - # which happens every few hits. + # We can't do this in FastCGI or we'll blow away the component + # root _every_ time a new server starts which happens every few + # hits. - use File::Path qw( rmtree ); - use File::Glob qw( bsd_glob ); - my @files = bsd_glob("$RT::MasonDataDir/obj/*"); - rmtree([ @files ], 0, 1) if @files; -} - -sub handler { - ($r) = @_; - - local $SIG{__WARN__}; - local $SIG{__DIE__}; - - if ($r->content_type =~ m/^httpd\b.*\bdirectory/i) { - use File::Spec::Unix; - # Our DirectoryIndex is always index.html, regardless of httpd settings - $r->filename( File::Spec::Unix->catfile( $r->filename, 'index.html' ) ); - } -# elsif (defined( $r->content_type )) { - #$r->content_type !~ m!(^text/|\bxml\b)!i or return -1; -# } - - Module::Refresh->refresh if RT->Config->Get('DevelMode'); - - RT::Init(); - - $Handler ||= RT::Interface::Web::Handler->new( - RT->Config->Get('MasonParameters') - ); - - my %session; - my $status; - eval { $status = $Handler->handle_request($r) }; - if ($@) { - $RT::Logger->crit($@); - } - - undef(%session); - - RT::Interface::Web::Handler->CleanupRequest(); - - return $status; + require File::Path; + require File::Glob; + my @files = File::Glob::bsd_glob("$RT::MasonDataDir/obj/*"); + File::Path::rmtree([ @files ], 0, 1) if @files; } 1; diff --git a/rt/bin/webmux.pl.in b/rt/bin/webmux.pl.in index 7e61b2775..50b959a73 100644 --- a/rt/bin/webmux.pl.in +++ b/rt/bin/webmux.pl.in @@ -48,20 +48,62 @@ # END BPS TAGGED BLOCK }}} use strict; +package HTML::Mason::Commands; +our %session; + +package RT::Mason; + +our ($Nobody, $SystemUser, $Handler, $r); + +sub handler { + ($r) = @_; + + local $SIG{__WARN__}; + local $SIG{__DIE__}; + RT::InitSignalHandlers(); + + if ($r->content_type =~ m/^httpd\b.*\bdirectory/i) { + use File::Spec::Unix; + # Our DirectoryIndex is always index.html, regardless of httpd settings + $r->filename( File::Spec::Unix->catfile( $r->filename, 'index.html' ) ); + } + + Module::Refresh->refresh if RT->Config->Get('DevelMode'); + + RT::ConnectToDatabase(); + + my (%session, $status); + { + local $@; + $status = eval { $Handler->handle_request($r) }; + $RT::Logger->crit( $@ ) if $@; + } + undef %session; + + RT::Interface::Web::Handler->CleanupRequest(); + + return $status; +} + +package main; + +# check mod_perl version if it's mod_perl +BEGIN { + die "RT does not support mod_perl 1.99. Please upgrade to mod_perl 2.0" + if $ENV{'MOD_PERL'} + and $ENV{'MOD_PERL'} =~ m{mod_perl/(?:1\.9)}; +} + BEGIN { - $ENV{'PATH'} = '/bin:/usr/bin'; # or whatever you need + $ENV{'PATH'} = '/bin:/usr/bin'; # or whatever you need $ENV{'CDPATH'} = '' if defined $ENV{'CDPATH'}; $ENV{'SHELL'} = '/bin/sh' if defined $ENV{'SHELL'}; $ENV{'ENV'} = '' if defined $ENV{'ENV'}; $ENV{'IFS'} = '' if defined $ENV{'IFS'}; - use CGI qw(-private_tempfiles); #bring this in before mason, to make sure we - #set private_tempfiles - - die "RT does not support mod_perl 1.99. Please upgrade to mod_perl 2.0" - if $ENV{'MOD_PERL'} - and $ENV{'MOD_PERL'} =~ m{mod_perl/(?:1\.9)}; - + # bring this in before mason, to make sure we + # use private tempfiles + use CGI qw(-private_tempfiles); } # fix lib paths, some may be relative @@ -88,91 +130,47 @@ BEGIN { } } -use RT; - -package RT::Mason; - -use vars qw($Nobody $SystemUser $Handler $r); -#This drags in RT's config.pm -BEGIN { - RT::LoadConfig(); - if (RT->Config->Get('DevelMode')) { require Module::Refresh; } - RT->InitPluginPaths(); +require RT; +RT::LoadConfig(); +if ( RT->Config->Get('DevelMode') ) { + require Module::Refresh; } +RT::Init(); +# check compatibility of the DB { - require RT::Handle; - my $dsn = RT::Handle->DSN; - my $user = RT->Config->Get('DatabaseUser'); - my $pass = RT->Config->Get('DatabasePassword'); - - my $dbh = DBI->connect( - $dsn, $user, $pass, - { RaiseError => 0, PrintError => 0 }, - ); + my $dbh = $RT::Handle->dbh; if ( $dbh ) { - my ($status, $msg) = RT::Handle->CheckCompatibility( $dbh, 'post' ); + my ($status, $msg) = $RT::Handle->CheckCompatibility( $dbh, 'post' ); die $msg unless $status; } } -{ - package HTML::Mason::Commands; - use vars qw(%session); -} +require RT::Interface::Web::Handler; +$RT::Mason::Handler = RT::Interface::Web::Handler->new( + RT->Config->Get('MasonParameters') +); + +# load more for mod_perl before forking +RT::InitClasses( Heavy => 1 ) if $ENV{'MOD_PERL'} || $ENV{RT_WEBMUX_HEAVY_LOAD}; -use RT::Interface::Web; -use RT::Interface::Web::Handler; +# we must disconnect DB before fork +$RT::Handle->dbh(undef); +undef $RT::Handle; -if ($ENV{'MOD_PERL'} && !RT->Config->Get('DevelMode')) { +if ( $ENV{'MOD_PERL'} && !RT->Config->Get('DevelMode')) { # Under static_source, we need to purge the component cache # each time we restart, so newer components may be reloaded. # - # We can't do this in FastCGI or we'll blow away the component root _every_ time a new server starts - # which happens every few hits. + # We can't do this in FastCGI or we'll blow away the component + # root _every_ time a new server starts which happens every few + # hits. - use File::Path qw( rmtree ); - use File::Glob qw( bsd_glob ); - my @files = bsd_glob("$RT::MasonDataDir/obj/*"); - rmtree([ @files ], 0, 1) if @files; -} - -sub handler { - ($r) = @_; - - local $SIG{__WARN__}; - local $SIG{__DIE__}; - - if ($r->content_type =~ m/^httpd\b.*\bdirectory/i) { - use File::Spec::Unix; - # Our DirectoryIndex is always index.html, regardless of httpd settings - $r->filename( File::Spec::Unix->catfile( $r->filename, 'index.html' ) ); - } -# elsif (defined( $r->content_type )) { - #$r->content_type !~ m!(^text/|\bxml\b)!i or return -1; -# } - - Module::Refresh->refresh if RT->Config->Get('DevelMode'); - - RT::Init(); - - $Handler ||= RT::Interface::Web::Handler->new( - RT->Config->Get('MasonParameters') - ); - - my %session; - my $status; - eval { $status = $Handler->handle_request($r) }; - if ($@) { - $RT::Logger->crit($@); - } - - undef(%session); - - RT::Interface::Web::Handler->CleanupRequest(); - - return $status; + require File::Path; + require File::Glob; + my @files = File::Glob::bsd_glob("$RT::MasonDataDir/obj/*"); + File::Path::rmtree([ @files ], 0, 1) if @files; } 1; |