224eab822d
koha.psgi example and plackup.sh script to run any Koha site intranet or opac interface under Plack with optional multi-process Starman server plackup.sh site-name [intranet] site-name is used to find config /etc/koha/sites/site-name/koha-conf.xml All configuration is specified in koha.psgi, which you are welcome to edit and tune according to your development needs (enable memcache, enable/disable debugging modules for plack and so on). For deployment of opac or intranet you would probably want to take a look in plackup.sh and enable starman as web server (which is pre-forking server written in perl) and put some web server in front of it to serve static web files (e.g. ngnix, apache) When you are happy with it, rename koha.psgi and plackup.sh it to site name and save it for safe-keeping. This commit message is included in patch as README.plack because it includes useful information for people using plack for first time. Test scenario: 1. install plack and dependencies, as documented at http://wiki.koha-community.org/wiki/Plack 2. start ./plackup.sh sitename i[ntranet] 3. open intranet page http://localhost:5001/ and verify that it redirects to http://localhost:5001/cgi-bin/koha/mainpage.pl 4. start ./plackup.sh sitename 5. open OPAC http://localhost:5000/ and verify that it redirects to http://localhost:5000/cgi-bin/koha/opac-main.pl 6. next step is to take a look into koha.psgi and enable additional debug modules, save file and reload page (plackup will reload code automatically) Signed-off-by: Magnus Enger <magnus@enger.priv.no> Works as advertised. As I have explained in a comment on the bug this looks like a very good starting point, and we can argue about the details and add more options over time. Very happy to sign this off! (My earlier concern about / not working has now been taken care of, thanks Dobrica!) Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Galen Charlton <gmc@esilibrary.com>
86 lines
2.5 KiB
Perl
86 lines
2.5 KiB
Perl
#!/usr/bin/perl
|
|
use Plack::Builder;
|
|
use Plack::App::CGIBin;
|
|
use lib qw( ./lib );
|
|
use Plack::Middleware::Debug;
|
|
use Plack::App::Directory;
|
|
|
|
BEGIN {
|
|
|
|
# override configuration from startup script below:
|
|
# (requires --reload option)
|
|
|
|
$ENV{PLACK_DEBUG} = 1; # toggle debugging
|
|
|
|
# memcache change requires restart
|
|
$ENV{MEMCACHED_SERVERS} = "localhost:11211";
|
|
#$ENV{MEMCACHED_DEBUG} = 0;
|
|
|
|
$ENV{PROFILE_PER_PAGE} = 1; # reset persistant and profile counters after each page, like CGI
|
|
#$ENV{INTRANET} = 1; # usually passed from script
|
|
|
|
#$ENV{DBI_AUTOPROXY}='dbi:Gofer:transport=null;cache=DBI::Util::CacheMemory'
|
|
|
|
} # BEGIN
|
|
|
|
use C4::Context;
|
|
use C4::Languages;
|
|
use C4::Members;
|
|
use C4::Dates;
|
|
use C4::Boolean;
|
|
use C4::Letters;
|
|
use C4::Koha;
|
|
use C4::XSLT;
|
|
use C4::Branch;
|
|
use C4::Category;
|
|
=for preload
|
|
use C4::Tags; # FIXME
|
|
=cut
|
|
|
|
use Devel::Size 0.77; # 0.71 doesn't work for Koha
|
|
my $watch_capture_regex = '(C4|Koha)';
|
|
|
|
sub watch_for_size {
|
|
my @watch =
|
|
map { s/^.*$watch_capture_regex/$1/; s/\//::/g; s/\.pm$//; $_ } # fix paths
|
|
grep { /$watch_capture_regex/ }
|
|
keys %INC
|
|
;
|
|
warn "# watch_for_size ",join(' ',@watch);
|
|
return @watch;
|
|
};
|
|
|
|
my $CGI_ROOT = $ENV{INTRANET} ? $ENV{INTRANETDIR} : $ENV{OPACDIR};
|
|
warn "# using Koha ", $ENV{INTRANET} ? 'intranet' : 'OPAC', " CGI from $CGI_ROOT\n";
|
|
my $app=Plack::App::CGIBin->new(root => $CGI_ROOT);
|
|
my $home = sub {
|
|
return [ 302, [ Location => '/cgi-bin/koha/' . ( $ENV{INTRANET} ? 'mainpage.pl' : 'opac-main.pl' ) ] ];
|
|
};
|
|
|
|
builder {
|
|
|
|
# please don't use plugins which are under enable_if $ENV{PLACK_DEBUG} in production!
|
|
# they are known to leek memory
|
|
enable_if { $ENV{PLACK_DEBUG} } 'Debug', panels => [
|
|
qw(Environment Response Timer Memory),
|
|
# optional plugins (uncomment to enable) are sorted according to performance implact
|
|
# [ 'Devel::Size', for => \&watch_for_size ], # https://github.com/dpavlin/p5-plack-devel-debug-devel-size
|
|
# [ 'DBIProfile', profile => 2 ],
|
|
# [ 'DBITrace', level => 1 ], # a LOT of fine-graded SQL trace
|
|
# [ 'Profiler::NYTProf', exclude => [qw(.*\.css .*\.png .*\.ico .*\.js .*\.gif)] ],
|
|
];
|
|
|
|
# don't enable this plugin in production, since stack traces reveal too much information
|
|
# about system to potential attackers!
|
|
enable_if { $ENV{PLACK_DEBUG} } 'StackTrace';
|
|
|
|
# this enables plackup or starman to serve static files and provide working plack
|
|
# setup without need for front-end web server to serve static files
|
|
enable_if { $ENV{INTRANETDIR} } "Plack::Middleware::Static",
|
|
path => qr{^/(intranet|opac)-tmpl/},
|
|
root => "$ENV{INTRANETDIR}/koha-tmpl/";
|
|
|
|
mount "/cgi-bin/koha" => $app;
|
|
mount "/" => $home;
|
|
|
|
};
|