git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH/RFC] gitweb: Run in FastCGI mode if gitweb script has .fcgi extension
@ 2010-06-05 21:11 Jakub Narebski
  2010-06-05 21:12 ` Ævar Arnfjörð Bjarmason
  2010-06-06 20:09 ` [PATCH/RFC v2] " Jakub Narebski
  0 siblings, 2 replies; 4+ messages in thread
From: Jakub Narebski @ 2010-06-05 21:11 UTC (permalink / raw)
  To: git; +Cc: Sam Vilain, Jakub Narebski

If the name of the script ($SCRIPT_NAME or $SCRIPT_FILENAME CGI
environment variable, or __FILE__ literal) ends with '.fcgi'
extension, run gitweb in FastCGI mode, as if it was run with
'--fastcgi' / '--fcgi' option.

This is intended for easy deploying gitweb using FastCGI
interface.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
This patch is based on a0446e7 commit (gitweb: Add support for
FastCGI, using CGI::Fast, 2010-05-07), currently in 'next' 
(from 'jn/gitweb-fastcgi' branch).

I have not actually tested that it runs as FastCGI script.

Now to run gitweb using FastCGI, all one has to do is to rename it
from gitweb.cgi to gitweb.fcgi.  And of course configure web server
to run it using FastCGI interface.

 gitweb/gitweb.perl |   21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index c42c16f..47ef993 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1056,19 +1056,24 @@ our $is_last_request = sub { 1 };
 our ($pre_dispatch_hook, $post_dispatch_hook, $pre_listen_hook);
 our $CGI = 'CGI';
 our $cgi;
+sub configure_as_fcgi {
+	require CGI::Fast;
+	our $CGI = 'CGI::Fast';
+
+	my $request_number = 0;
+	# let each child service 100 requests
+	our $is_last_request = sub { ++$request_number > 100 };
+}
 sub evaluate_argv {
+	my $script_name = $ENV{'SCRIPT_NAME'} || $ENV{'SCRIPT_FILENAME'} || __FILE__;
+	configure_as_fcgi()
+		if $script_name =~ /\.fcgi$/;
+
 	return unless (@ARGV);
 
 	require Getopt::Long;
 	Getopt::Long::GetOptions(
-		'fastcgi|fcgi|f' => sub {
-			require CGI::Fast;
-			our $CGI = 'CGI::Fast';
-
-			my $request_number = 0;
-			# let each child service 100 requests
-			our $is_last_request = sub { ++$request_number > 100 };
-		},
+		'fastcgi|fcgi|f' => \&configure_as_fcgi,
 		'nproc|n=i' => sub {
 			my ($arg, $val) = @_;
 			return unless eval { require FCGI::ProcManager; 1; };
-- 
1.7.0.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH/RFC] gitweb: Run in FastCGI mode if gitweb script has  .fcgi extension
  2010-06-05 21:11 [PATCH/RFC] gitweb: Run in FastCGI mode if gitweb script has .fcgi extension Jakub Narebski
@ 2010-06-05 21:12 ` Ævar Arnfjörð Bjarmason
  2010-06-06 20:09 ` [PATCH/RFC v2] " Jakub Narebski
  1 sibling, 0 replies; 4+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2010-06-05 21:12 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: git, Sam Vilain

On Sat, Jun 5, 2010 at 21:11, Jakub Narebski <jnareb@gmail.com> wrote:
> If the name of the script ($SCRIPT_NAME or $SCRIPT_FILENAME CGI
> environment variable, or __FILE__ literal) ends with '.fcgi'
> extension, run gitweb in FastCGI mode, as if it was run with
> '--fastcgi' / '--fcgi' option.

Looks good to me, it'll make deploying on e.g. Apache a lot easier,
and doubtless most other web servers too.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH/RFC v2] gitweb: Run in FastCGI mode if gitweb script has .fcgi extension
  2010-06-05 21:11 [PATCH/RFC] gitweb: Run in FastCGI mode if gitweb script has .fcgi extension Jakub Narebski
  2010-06-05 21:12 ` Ævar Arnfjörð Bjarmason
@ 2010-06-06 20:09 ` Jakub Narebski
  2010-06-06 20:18   ` Pavan Kumar Sunkara
  1 sibling, 1 reply; 4+ messages in thread
From: Jakub Narebski @ 2010-06-06 20:09 UTC (permalink / raw)
  To: git; +Cc: Sam Vilain, Ævar Arnfjörð Bjarmason

If the name of the script ($SCRIPT_NAME or $SCRIPT_FILENAME CGI
environment variable, or __FILE__ literal) ends with '.fcgi'
extension, run gitweb in FastCGI mode, as if it was run with
'--fastcgi' / '--fcgi' option.

This is intended for easy deploying of gitweb using FastCGI
interface.

Includes update to gitweb/INSTALL.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
This patch differs from previous version only in that it now includes
change to gitweb/INSTALL.  Can anyone check if the information stated
there is correct?

This patch is based on a0446e7 commit (gitweb: Add support for
FastCGI, using CGI::Fast, 2010-05-07), currently in 'next' 
(from 'jn/gitweb-fastcgi' branch).

I have not actually tested that it runs as FastCGI script.

 gitweb/INSTALL     |   28 ++++++++++++++++++++++++++++
 gitweb/gitweb.perl |   21 +++++++++++++--------
 2 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/gitweb/INSTALL b/gitweb/INSTALL
index d484d76..617c9f4 100644
--- a/gitweb/INSTALL
+++ b/gitweb/INSTALL
@@ -230,12 +230,26 @@ $projects_list variable in gitweb config):
 	perl -- /var/www/cgi-bin/gitweb.cgi
 
 
+Running gitweb using FastCGI interface
+--------------------------------------
+
+To run gitweb as FastCGI script (using FastCGI interface), rather than
+plain CGI script, you need to either pass '--fastcgi' or '--fcgi' parameter
+to gitweb script, or rename it to 'gitweb.fcgi' (to end with '.fcgi'
+extension).  To run gitweb using FastCGI interface you need CGI::Fast
+and FCGI Perl modules installed.
+
+You can also pass '--nproc=<n>' parameter to gitweb script to configure how
+many FCGI::ProcManager processes to use.
+
+
 Requirements
 ------------
 
  - Core git tools
  - Perl
  - Perl modules: CGI, Encode, Fcntl, File::Find, File::Basename.
+   To run gitweb using FastCGI interface CGI::Fast and FCGI are needed.
  - web server
 
 
@@ -272,3 +286,17 @@ See also "Webserver configuration" section in README file for gitweb
 	    Order allow,deny
 	    Allow from all
 	</Directory>
+
+- Apache2, gitweb installed as 'gitweb.fcgi' FastCGI script,
+  under /var/www/fcgi-bin/
+
+	LoadModule fcgid_module modules/mod_fcgid.so
+
+	Alias /fcgi-bin "/var/www/fcgi-bin"
+
+	<Directory "/var/www/fcgi-bin">
+	    SetHandler fcgid-script
+	    Options +ExecCGI
+	    Order allow,deny
+	    Allow from all
+	</Directory>
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index c42c16f..47ef993 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1056,19 +1056,24 @@ our $is_last_request = sub { 1 };
 our ($pre_dispatch_hook, $post_dispatch_hook, $pre_listen_hook);
 our $CGI = 'CGI';
 our $cgi;
+sub configure_as_fcgi {
+	require CGI::Fast;
+	our $CGI = 'CGI::Fast';
+
+	my $request_number = 0;
+	# let each child service 100 requests
+	our $is_last_request = sub { ++$request_number > 100 };
+}
 sub evaluate_argv {
+	my $script_name = $ENV{'SCRIPT_NAME'} || $ENV{'SCRIPT_FILENAME'} || __FILE__;
+	configure_as_fcgi()
+		if $script_name =~ /\.fcgi$/;
+
 	return unless (@ARGV);
 
 	require Getopt::Long;
 	Getopt::Long::GetOptions(
-		'fastcgi|fcgi|f' => sub {
-			require CGI::Fast;
-			our $CGI = 'CGI::Fast';
-
-			my $request_number = 0;
-			# let each child service 100 requests
-			our $is_last_request = sub { ++$request_number > 100 };
-		},
+		'fastcgi|fcgi|f' => \&configure_as_fcgi,
 		'nproc|n=i' => sub {
 			my ($arg, $val) = @_;
 			return unless eval { require FCGI::ProcManager; 1; };
-- 
1.7.0.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH/RFC v2] gitweb: Run in FastCGI mode if gitweb script has  .fcgi extension
  2010-06-06 20:09 ` [PATCH/RFC v2] " Jakub Narebski
@ 2010-06-06 20:18   ` Pavan Kumar Sunkara
  0 siblings, 0 replies; 4+ messages in thread
From: Pavan Kumar Sunkara @ 2010-06-06 20:18 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: git, Sam Vilain, Ævar Arnfjörð Bjarmason

> @@ -1056,19 +1056,24 @@ our $is_last_request = sub { 1 };
>  our ($pre_dispatch_hook, $post_dispatch_hook, $pre_listen_hook);
>  our $CGI = 'CGI';
>  our $cgi;
> +sub configure_as_fcgi {
> +       require CGI::Fast;
> +       our $CGI = 'CGI::Fast';
> +
> +       my $request_number = 0;
> +       # let each child service 100 requests
> +       our $is_last_request = sub { ++$request_number > 100 };
> +}

You missed to put a new line in here.

>  sub evaluate_argv {
> +       my $script_name = $ENV{'SCRIPT_NAME'} || $ENV{'SCRIPT_FILENAME'} || __FILE__;
> +       configure_as_fcgi()
> +               if $script_name =~ /\.fcgi$/;
> +
>        return unless (@ARGV);
>
>        require Getopt::Long;
>        Getopt::Long::GetOptions(
> -               'fastcgi|fcgi|f' => sub {
> -                       require CGI::Fast;
> -                       our $CGI = 'CGI::Fast';
> -
> -                       my $request_number = 0;
> -                       # let each child service 100 requests
> -                       our $is_last_request = sub { ++$request_number > 100 };
> -               },
> +               'fastcgi|fcgi|f' => \&configure_as_fcgi,
>                'nproc|n=i' => sub {
>                        my ($arg, $val) = @_;
>                        return unless eval { require FCGI::ProcManager; 1; };
> --
> 1.7.0.1

Thanks,
Pavan.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-06-06 20:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-05 21:11 [PATCH/RFC] gitweb: Run in FastCGI mode if gitweb script has .fcgi extension Jakub Narebski
2010-06-05 21:12 ` Ævar Arnfjörð Bjarmason
2010-06-06 20:09 ` [PATCH/RFC v2] " Jakub Narebski
2010-06-06 20:18   ` Pavan Kumar Sunkara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).