[Koha-patches] [PATCH] Bug 7844 - plack intranet tooling for developers

Dobrica Pavlinusic dpavlin at rot13.org
Sat Mar 31 02:49:20 CEST 2012


koha.psgi example and script to run any Koha site intranet or opac under plack

This means that it will use sudo to switch to correct site-koha user for
configuration and plack process

It also defines new enviroment variables:

PLACK_DEBUG=1  - turn Plack debug panels on
PLACK_MINIFY=1 - minify JavaScript and CSS which saves us ~10k on each page load

Test scenario:
1. install plack and dependencies, using ./cpanm-install.pl

2. start ./intranet-plack.sh sitename

3. open intranet page http://localhost:5001/cgi-bin/koha/mainpage.pl
   and verify that it works

4. start ./opac-plack.sh sitename

5. open OPAC http://localhost:5000/cgi-bin/koha/opac-main.pl
   and very that it works

6. start PLACK_DEBUG=1 ./intranet-plack.sh sitename
   and verify that debug console is available
---
 misc/plack/cpanm-install.sh  |    8 +++++++
 misc/plack/intranet-plack.sh |   17 +++++++++++++++
 misc/plack/koha.psgi         |   45 ++++++++++++++++++++++++++++++++++++++++++
 misc/plack/opac-plack.sh     |   17 +++++++++++++++
 4 files changed, 87 insertions(+), 0 deletions(-)
 create mode 100755 misc/plack/cpanm-install.sh
 create mode 100755 misc/plack/intranet-plack.sh
 create mode 100644 misc/plack/koha.psgi
 create mode 100755 misc/plack/opac-plack.sh

diff --git a/misc/plack/cpanm-install.sh b/misc/plack/cpanm-install.sh
new file mode 100755
index 0000000..589cb73
--- /dev/null
+++ b/misc/plack/cpanm-install.sh
@@ -0,0 +1,8 @@
+#!/bin/sh -xe
+
+sudo cpan App::cpanminus
+cpanm --sudo Task::Plack \
+	Plack::Middleware::Static::Minifier \
+	Plack::Middleware::Debug::Profiler::NYTProf \
+	Plack::Middleware::Debug::DBIProfile
+
diff --git a/misc/plack/intranet-plack.sh b/misc/plack/intranet-plack.sh
new file mode 100755
index 0000000..2e87659
--- /dev/null
+++ b/misc/plack/intranet-plack.sh
@@ -0,0 +1,17 @@
+#!/bin/sh -xe
+
+site=ffzg
+test ! -z "$1" && site=$1
+dir=`dirname $0`
+
+export KOHA_CONF=/etc/koha/sites/$site/koha-conf.xml 
+export INTRANETDIR="$( sudo -u $site-koha xmlstarlet sel -t -v 'yazgfs/config/intranetdir' $KOHA_CONF )"
+
+if [ ! -e "$INTRANETDIR/C4" ] ; then
+	echo "intranetdir in $KOHA_CONF doesn't point to Koha git checkout"
+	exit 1
+fi
+
+# CGI scripts are automatically reloaded
+opt="--reload -R $INTRANETDIR/C4"
+sudo -E -u $site-koha plackup -I $INTRANETDIR -I $INTRANETDIR/installer $opt --port 5001 $dir/koha.psgi
diff --git a/misc/plack/koha.psgi b/misc/plack/koha.psgi
new file mode 100644
index 0000000..2989eab
--- /dev/null
+++ b/misc/plack/koha.psgi
@@ -0,0 +1,45 @@
+#!/usr/bin/perl
+use Plack::Builder;
+use Plack::App::CGIBin;
+use Plack::Middleware::Debug;
+use Plack::App::Directory;
+
+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;
+
+my $app=Plack::App::CGIBin->new(root => $ENV{INTRANETDIR} || $ENV{OPACDIR});
+
+builder {
+
+	enable_if { $ENV{PLACK_DEBUG} } 'Debug',  panels => [
+		qw(Environment Response Timer Memory),
+#		[ 'Profiler::NYTProf', exclude => [qw(.*\.css .*\.png .*\.ico .*\.js .*\.gif)] ],
+#		[ 'DBITrace', level => 1 ], # a LOT of fine-graded SQL trace
+		[ 'DBIProfile', profile => 2 ],
+	];
+
+	enable_if { $ENV{PLACK_DEBUG} } 'StackTrace';
+
+	enable_if { $ENV{INTRANETDIR} } "Plack::Middleware::Static",
+		path => qr{^/intranet-tmpl/}, root => '/srv/koha/koha-tmpl/';
+
+	enable_if { $ENV{OPACDIR} } "Plack::Middleware::Static",
+		path => qr{^/opac-tmpl/}, root => '/srv/koha/koha-tmpl/';
+
+	enable_if { $ENV{PLACK_MINIFIER} } "Plack::Middleware::Static::Minifier",
+		path => qr{^/(intranet|opac)-tmpl/},
+		root => './koha-tmpl/';
+
+
+	mount "/cgi-bin/koha" => $app;
+
+};
+
diff --git a/misc/plack/opac-plack.sh b/misc/plack/opac-plack.sh
new file mode 100755
index 0000000..6b7f586
--- /dev/null
+++ b/misc/plack/opac-plack.sh
@@ -0,0 +1,17 @@
+#!/bin/sh -xe
+
+# --max-requests decreased from 1000 to 50 to keep memory usage sane
+# --workers 8 which is number of cores on machine
+
+site=ffzg
+test ! -z "$1" && site=$1 && shift
+dir=`dirname $0`
+
+export KOHA_CONF=/etc/koha/sites/$site/koha-conf.xml 
+export OPACDIR="$( sudo -u $site-koha xmlstarlet sel -t -v 'yazgfs/config/opacdir' $KOHA_CONF | sed 's,/cgi-bin/opac,,' )"
+export LOGDIR="$( sudo -u $site-koha xmlstarlet sel -t -v 'yazgfs/config/logdir' $KOHA_CONF )"
+
+# uncomment to enable logging
+#opt="$opt --access-log $LOGDIR/opac-access.log --error-log $LOGDIR/opac-error.log"
+#opt="$opt --server Starman -M FindBin --max-requests 50 --workers 4 -E deployment"
+sudo -E -u $site-koha plackup -I $OPACDIR/.. $opt $* $dir/koha.psgi
-- 
1.7.2.5



More information about the Koha-patches mailing list