From 7fc39538421b9c3903d2c75bd8aab5eb488cc2fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Cohen=20Arazi?= Date: Wed, 4 Mar 2015 00:19:40 +0100 Subject: [PATCH] Bug 13791: Plack out-of-the-box support on packages This patch introduces a koha-plack script that controls running Plack processes for each instance. They are run using 'starman', listening on a Unix Domain Socket (UDS): /var/run/koha//plack.sock The plack configuration file[1] is expected to be on: /etc/koha/plack.psgi It also adds the following helper functions to koha-functions.sh: - is_plack_enabled - is_plack_running Done: - koha-plack script - suitable psgi file TODO (by priority): - changes to koha-create - configurable workers/max-reqs (per instance?) - allow per instance psgi file (debugging?) and fallback to shipped - tab completion in bash [1] Yeah, a single file. Because we will be relying on multiple mount points for each "app" (i.e. 'opac' and 'intranet', and 'api' ;-) ) --- debian/scripts/koha-functions.sh | 31 +++++ debian/scripts/koha-plack | 256 +++++++++++++++++++++++++++++++++++++++ debian/templates/plack.psgi | 71 +++++++++++ 3 files changed, 358 insertions(+) create mode 100755 debian/scripts/koha-plack create mode 100644 debian/templates/plack.psgi diff --git a/debian/scripts/koha-functions.sh b/debian/scripts/koha-functions.sh index 8090fc5..06ca274 100755 --- a/debian/scripts/koha-functions.sh +++ b/debian/scripts/koha-functions.sh @@ -121,6 +121,37 @@ is_indexer_running() fi } +is_plack_enabled() +{ + local site=$1 + local instancefile=$(get_apache_config_for $site) + + if [ "$instancefile" = "" ]; then + return 1 + fi + + if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-opac-plack.conf' \ + "$instancefile" && \ + grep -q '^[[:space:]]*Include /etc/koha/apache-shared-intranet-plack.conf' \ + "$instancefile" ; then + return 1 + else + return 0 + fi +} + +is_plack_running() +{ + local instancename=$1 + + if start-stop-daemon --pidfile "/var/run/koha/${instancename}/plack.pid" \ + --status ; then + return 0 + else + return 1 + fi +} + get_instances() { find /etc/koha/sites -mindepth 1 -maxdepth 1\ diff --git a/debian/scripts/koha-plack b/debian/scripts/koha-plack new file mode 100755 index 0000000..bc44cea --- /dev/null +++ b/debian/scripts/koha-plack @@ -0,0 +1,256 @@ +#!/bin/bash +# +# Copyright 2015 Theke Solutions +# +# This file is part of Koha. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +set -e + +. /lib/lsb/init-functions + +# Read configuration variable file if it is present +[ -r /etc/default/koha-common ] && . /etc/default/koha-common + +# include helper functions +if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then + . "/usr/share/koha/bin/koha-functions.sh" +else + echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2 + exit 1 +fi + +usage() +{ + local scriptname=$(basename $0) + + cat <. + +use lib("/usr/share/koha/lib"); +use lib("/usr/share/koha/lib/installer"); + +use Plack::Builder; +use Plack::App::CGIBin; +use Plack::App::Directory; +use Plack::App::URLMap; + +# Pre-load libraries +use C4::Boolean; +use C4::Branch; +use C4::Category; +use C4::Dates; +use C4::Koha; +use C4::Languages; +use C4::Letters; +use C4::Members; +use C4::XSLT; +use Koha::Database; + +use CGI qw(-utf8 ); # we will loose -utf8 under plack, otherwise +{ + no warnings 'redefine'; + my $old_new = \&CGI::new; + *CGI::new = sub { + my $q = $old_new->( @_ ); + $CGI::PARAM_UTF8 = 1; + C4::Context->clear_syspref_cache(); + return $q; + }; +} + +my $intranet = Plack::App::CGIBin->new( + root => '/usr/share/koha/intranet/cgi-bin' +); + +my $opac = Plack::App::CGIBin->new( + root => '/usr/share/koha/opac/cgi-bin/opac' +); + +# my $api = Plack::App::CGIBin->new( +# root => '/usr/share/koha/api/' +# ); + +builder { + + enable "ReverseProxy"; + enable "Plack::Middleware::Static"; + + mount '/opac' => $opac; + mount '/intranet' => $intranet; + # mount '/api' => $api; +}; + -- 2.5.0