Created
May 20, 2010 21:26
-
-
Save jnareb/408135 to your computer and use it in GitHub Desktop.
plackup_conf from git-instaweb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plackup_conf () { | |
cat > "$fqgitdir/gitweb/gitweb.psgi" <<GITWEB_PSGI_EOF | |
#!$PERL | |
# gitweb - simple web interface to track changes in git repositories | |
# PSGI wrapper (see http://plackperl.org) | |
use strict; | |
use IO::Handle; | |
use Plack::Builder; | |
use Plack::App::WrapCGI; | |
use CGI::Emulate::PSGI 0.07; # minimum version required to work with gitweb | |
my \$app = builder { | |
open my \$access_log_fh, '>', "$fqgitdir/gitweb/access.log" | |
or die "Couldn't open access log '$fqgitdir/gitweb/access.log': \$!"; | |
open my \$error_log_fh, '>', "$fqgitdir/gitweb/error.log" | |
or die "Couldn't open error log '$fqgitdir/gitweb/error.log': \$!"; | |
\$access_log_fh->autoflush(1); | |
\$error_log_fh->autoflush(1); | |
# write errors to error.log, access to access.log | |
enable 'AccessLog', | |
format => "combined", | |
logger => sub { print \$access_log_fh @_; }; | |
enable sub { | |
my \$app = shift; | |
sub { | |
my \$env = shift; | |
\$env->{'psgi.errors'} = \$error_log_fh; | |
\$app->(\$env); | |
} | |
}; | |
# gitweb currently doesn't work with $SIG{CHLD} set to 'IGNORE', | |
# because it uses 'close $fd or die...' on pipe | |
# (which in turn uses wait / waitpid). | |
enable_if { \$SIG{'CHLD'} eq 'IGNORE' } sub { | |
my \$app = shift; | |
sub { | |
my \$env = shift; | |
local \$SIG{'CHLD'} = 'DEFAULT'; | |
local \$SIG{'CLD'} = 'DEFAULT'; | |
\$app->(\$env); | |
} | |
}; | |
# serve static files, i.e. stylesheet, images, script | |
enable 'Static', | |
path => sub { m!\.(js|css|png)\$! && s!^/gitweb/!! }, | |
root => "$fqgitdir/gitweb/"; | |
# convert CGI application to PSGI app | |
Plack::App::WrapCGI->new(script => "$fqgitdir/gitweb/gitweb.cgi")->to_app; | |
}; | |
# make it runnable as standalone app, like via plackup | |
if (__FILE__ eq \$0) { | |
require Plack::Runner; | |
my \$runner = Plack::Runner->new(); | |
\$runner->parse_options(qw(--env deployment --port $port), | |
"$local" ? qw(--host 127.0.0.1) : ()); | |
\$runner->run(\$app); | |
} | |
GITWEB_PSGI_EOF | |
chmod a+x "$fqgitdir/gitweb/gitweb.psgi" | |
rm -f "$fqgitdir/gitweb/gitweb.psgi.tmp" "$conf" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment