View | Details | Raw Unified | Return to bug 7844
Collapse All | Expand All

(-)a/misc/plack/README.plack (+31 lines)
Line 0 Link Here
1
Bug 7844 - plack intranet tooling for developers
2
3
koha.psgi example and plackup.sh script to run any Koha site
4
intranet or opac interface under plack with optional multi-process
5
Starman server
6
7
  plackup.sh site-name [intranet]
8
9
site-name is used to find config /etc/koha/sites/site-name/koha-conf.xml
10
11
All configuration is specified in koha.psgi, which you are welcomed to edit
12
and tune according to your development needs.
13
14
When you are happy with it, rename it to site name and save it for safe-keeping.
15
16
Test scenario:
17
1. install plack and dependencies, using ./cpanm-install.pl
18
19
2. start ./plackup.sh sitename
20
21
3. open intranet page http://localhost:5001/cgi-bin/koha/mainpage.pl
22
   and verify that it works
23
24
4. start ./plackup.sh sitename i[ntranet]
25
26
5. open OPAC http://localhost:5000/cgi-bin/koha/opac-main.pl
27
   and verify that it works
28
29
6. next step is to take a look into koha.psgi and enable additional
30
   debug modules, save file and reload page (plackup will reload
31
   code automatically)
(-)a/misc/plack/koha.psgi (+78 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
use Plack::Builder;
3
use Plack::App::CGIBin;
4
use lib qw( ./lib );
5
use Plack::Middleware::Debug;
6
use Plack::App::Directory;
7
8
BEGIN {
9
10
# override configuration from startup script below:
11
# (requires --reload option)
12
13
$ENV{PLACK_DEBUG} = 1; # toggle debugging
14
15
# memcache change requires restart
16
$ENV{MEMCACHED_SERVERS} = "localhost:11211";
17
#$ENV{MEMCACHED_DEBUG} = 0;
18
19
$ENV{PROFILE_PER_PAGE} = 1; # reset persistant and profile counters after each page, like CGI
20
#$ENV{INTRANET} = 1; # usually passed from script
21
22
#$ENV{DBI_AUTOPROXY}='dbi:Gofer:transport=null;cache=DBI::Util::CacheMemory'
23
24
} # BEGIN
25
26
use C4::Context;
27
use C4::Languages;
28
use C4::Members;
29
use C4::Dates;
30
use C4::Boolean;
31
use C4::Letters;
32
use C4::Koha;
33
use C4::XSLT;
34
use C4::Branch;
35
use C4::Category;
36
=for preload
37
use C4::Tags; # FIXME
38
=cut
39
40
use Devel::Size 0.77; # 0.71 doesn't work for Koha
41
my $watch_capture_regex = '(C4|Koha)';
42
43
sub watch_for_size {
44
	my @watch =
45
	map { s/^.*$watch_capture_regex/$1/; s/\//::/g; s/\.pm$//; $_ } # fix paths
46
	grep { /$watch_capture_regex/ }
47
	keys %INC
48
	;
49
	warn "# watch_for_size ",join(' ',@watch);
50
	return @watch;
51
};
52
53
my $CGI_ROOT = $ENV{INTRANET} ? $ENV{INTRANETDIR} : $ENV{OPACDIR};
54
warn "# using Koha ", $ENV{INTRANET} ? 'intranet' : 'OPAC', " CGI from $CGI_ROOT\n";
55
my $app=Plack::App::CGIBin->new(root => $CGI_ROOT);
56
57
builder {
58
59
	enable_if { $ENV{PLACK_DEBUG} } 'Debug',  panels => [
60
 		qw(Koha Persistant),
61
		qw(Environment Response Timer Memory),
62
		# optional plugins (uncomment to enable) are sorted according to performance implact
63
#		[ 'Devel::Size', for => \&watch_for_size ], # https://github.com/dpavlin/p5-plack-devel-debug-devel-size
64
#		[ 'DBIProfile', profile => 2 ],
65
#		[ 'DBITrace', level => 1 ], # a LOT of fine-graded SQL trace
66
#		[ 'Profiler::NYTProf', exclude => [qw(.*\.css .*\.png .*\.ico .*\.js .*\.gif)] ],
67
	];
68
69
	enable_if { $ENV{PLACK_DEBUG} } 'StackTrace';
70
71
	enable_if { $ENV{INTRANETDIR} } "Plack::Middleware::Static",
72
		path => qr{^/(intranet|opac)-tmpl/},
73
		root => "$ENV{INTRANETDIR}/koha-tmpl/";
74
75
	mount "/cgi-bin/koha" => $app;
76
77
};
78
(-)a/misc/plack/plackup.sh (-1 / +53 lines)
Line 0 Link Here
0
- 
1
#!/bin/sh -xe
2
3
# This is plack startup script for Koha
4
5
# ./plackup.sh [site] [intranet]
6
7
site=$1
8
test ! -z "$site" && shift || site=srvgit # default
9
10
export KOHA_CONF=/etc/koha/sites/$site/koha-conf.xml
11
export LOGDIR="$( sudo -u $site-koha xmlstarlet sel -t -v 'yazgfs/config/logdir' $KOHA_CONF )"
12
export INTRANETDIR="$( sudo -u $site-koha xmlstarlet sel -t -v 'yazgfs/config/intranetdir' $KOHA_CONF )"
13
export OPACDIR="$( sudo -u $site-koha xmlstarlet sel -t -v 'yazgfs/config/opacdir' $KOHA_CONF | sed 's,/cgi-bin/opac,,' )"
14
15
dir=`dirname $0`
16
17
# enable memcache - it's safe even on installation which don't have it
18
# since Koha has check on C4::Context
19
#export MEMCACHED_SERVERS=localhost:11211
20
# pass site name as namespace to perl code
21
export MEMCACHED_NAMESPACE=$site
22
#export MEMCACHED_DEBUG=1
23
24
if [ ! -e "$INTRANETDIR/C4" ] ; then
25
	echo "intranetdir in $KOHA_CONF doesn't point to Koha git checkout"
26
	exit 1
27
fi
28
29
if [ -z "$1" ] ; then # type anything after site name for intranet!
30
	INTRANET=0
31
	PORT=5000
32
else
33
	INTRANET=1
34
	PORT=5001
35
	shift # pass rest of arguments to plackup
36
fi
37
export INTRANET # pass to plack
38
39
# uncomment to enable logging
40
#opt="$opt --access-log $LOGDIR/opac-access.log --error-log $LOGDIR/opac-error.log"
41
42
# --max-requests 50 decreased from 1000 to keep memory usage sane
43
# --workers 4       number of cores on machine
44
#test "$INTRANET" != 1 && \ # don't use Starman for intranet
45
opt="$opt --server Starman -M FindBin --max-requests 50 --workers 4"
46
47
# -E deployment     turn off access log on STDOUT
48
opt="$out -E deployment"
49
50
# comment out reload in production!
51
opt="$opt --reload -R $INTRANETDIR/C4 -R $INTRANETDIR/Koha"
52
53
sudo -E -u $site-koha plackup --port $PORT -I $INTRANETDIR -I $INTRANETDIR/installer $opt $* $dir/koha.psgi

Return to bug 7844