From 4adc4ee5f8d3e113b62094552be6c80942289c3e Mon Sep 17 00:00:00 2001 From: =?utf8?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 and is installed by the package. It also adds the following helper functions to koha-functions.sh: - is_plack_enabled - is_plack_running Done: - koha-plack script - suitable psgi file To test this patches you will need to install - starman - libplack-middleware-reverseproxy-perl [1] Yeah, a single file. Because we will be relying on multiple mount points for each "app" (i.e. 'opac' and 'intranet', and 'api' ;-) ) Signed-off-by: Josef Moravec Signed-off-by: Jonathan Druart Signed-off-by: Tomas Cohen Arazi --- debian/koha-common.install | 1 + debian/scripts/koha-functions.sh | 31 ++++ debian/scripts/koha-plack | 302 +++++++++++++++++++++++++++++++ debian/templates/plack.psgi | 71 ++++++++ 4 files changed, 405 insertions(+) create mode 100755 debian/scripts/koha-plack create mode 100644 debian/templates/plack.psgi diff --git a/debian/koha-common.install b/debian/koha-common.install index bdd5eca191..85bac738eb 100644 --- a/debian/koha-common.install +++ b/debian/koha-common.install @@ -20,6 +20,7 @@ debian/scripts/koha-foreach usr/sbin debian/scripts/koha-indexer usr/sbin debian/scripts/koha-list usr/sbin debian/scripts/koha-mysql usr/sbin +debian/scripts/koha-plack usr/sbin debian/scripts/koha-rebuild-zebra usr/sbin debian/scripts/koha-remove usr/sbin debian/scripts/koha-reset-passwd usr/sbin diff --git a/debian/scripts/koha-functions.sh b/debian/scripts/koha-functions.sh index 8090fc534c..06ca274427 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 0000000000..c0da9d156e --- /dev/null +++ b/debian/scripts/koha-plack @@ -0,0 +1,302 @@ +#!/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 < /dev/null | grep -q ${module}; then + missing_modules="${missing_modules}${module} " + fi + done + + if [ "${apache_version_ok}" != "yes" ]; then + warn "WARNING: koha-plack requires Apache 2.4.x and you don't have that." + fi + + if [ "${missing_modules}" != "" ]; then + cat 1>&2 <. + +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; + return $q; + }; +} + +C4::Context->disable_syspref_cache(); + +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.39.5