diff --git a/tasks/apache.yml b/tasks/apache.yml index ceaf0a1..b349876 100644 --- a/tasks/apache.yml +++ b/tasks/apache.yml @@ -13,6 +13,7 @@ - proxy - proxy_http - ssl + - headers - cgi notify: reload apache diff --git a/tasks/plack.yml b/tasks/plack.yml index 7dcac76..dfdf188 100644 --- a/tasks/plack.yml +++ b/tasks/plack.yml @@ -1,12 +1,27 @@ +- name: create plack dir + file: + path: "{{ koha_install_dir }}/bin/plack" + state: directory + owner: koha + group: koha + +- name: deploy plack script + template: + src: koha-plack + dest: "{{ koha_install_dir }}/bin/plack" + owner: koha + group: koha + mode: 0750 + - name: deploy plack service template: - src: plack-opac.service + src: plack.service dest: /etc/systemd/system/ notify: reload systemd - name: start and activate plack service systemd: - name: plack-opac.service + name: plack.service state: started enabled: true diff --git a/templates/koha-plack b/templates/koha-plack new file mode 100755 index 0000000..228b6fe --- /dev/null +++ b/templates/koha-plack @@ -0,0 +1,278 @@ +#!/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 + +export PERL5LIB={{ koha_install_dir }}/lib + +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 + echo "WARNING: koha-plack requires Apache 2.4.x and you don't have that." + fi + + if [ "${missing_modules}" != "" ]; then + cat 1>&2 <. + +set -e + +. /lib/lsb/init-functions + +# Read configuration variable file if it is present +[ -r /etc/default/koha-common ] && . /etc/default/koha-common +export PERL5LIB=/home/koha/koha/lib + +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 + echo "WARNING: koha-plack requires Apache 2.4.x and you don't have that." + fi + + if [ "${missing_modules}" != "" ]; then + cat 1>&2 <= 3.0-6) to ensure that this file is present. +. /lib/lsb/init-functions + +# +# Function that starts the daemon/service +# +do_start() +{ + # We insure all required directories exist, including disabled ones. + koha-plack --start koha +} + +# +# Function that stops the daemon/service +# +do_stop() +{ + koha-plack --stop --quiet koha +} + +# +# Function that sends a SIGHUP to the daemon/service +# +do_reload() { + koha-plack --restart --quiet koha +} + +# +# Function that shows the status of the Plack server daemon for +# enabled instances +# +plack_status() +{ + log_daemon_msg "Plack server running for instance koha" + + if is_plack_running "koha" ; then + log_end_msg 0 + else + log_end_msg 1 + fi +} + +is_plack_running() +{ + local instancename=$1 + + if start-stop-daemon --pidfile "/var/run/koha/plack.pid" \ + --status ; then + return 0 + else + return 1 + fi +} + +case "$1" in + start) + [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" + do_start + case "$?" in + 0) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + *) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + stop) + [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" + do_stop + case "$?" in + 0) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + *) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + restart|force-reload) + # + # If the "reload" option is implemented then remove the + # 'force-reload' alias + # + log_daemon_msg "Restarting $DESC" "$NAME" + do_stop + case "$?" in + 0) + do_start + case "$?" in + 0) log_end_msg 0 ;; + *) log_end_msg 1 ;; # Failed to start + esac + ;; + *) + # Failed to stop + log_end_msg 1 + ;; + esac + ;; + status) + plack_status + ;; + *) + echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2 + exit 3 + ;; +esac + +: diff --git a/templates/plack/koha.psgi b/templates/plack/koha.psgi new file mode 100644 index 0000000..08d6a3b --- /dev/null +++ b/templates/plack/koha.psgi @@ -0,0 +1,80 @@ +#!/usr/bin/perl + +# 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 . + +use Modern::Perl; + +use lib("/home/koha/koha/lib"); +use lib("/home/koha/koha/lib/installer"); + +use Plack::Builder; +use Plack::App::CGIBin; +use Plack::App::Directory; +use Plack::App::URLMap; +use Plack::Request; + +use Mojo::Server::PSGI; + +# Pre-load libraries +use C4::Boolean; +use C4::Koha; +use C4::Languages; +use C4::Letters; +use C4::Members; +use C4::XSLT; +use Koha::Caches; +use Koha::Cache::Memory::Lite; +use Koha::Database; +use Koha::DateUtils; + +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; + Koha::Caches->flush_L1_caches(); + Koha::Cache::Memory::Lite->flush(); + return $q; + }; +} + +my $intranet = Plack::App::CGIBin->new( + root => '/home/koha/koha/intranet/cgi-bin' +)->to_app; + +my $opac = Plack::App::CGIBin->new( + root => '/home/koha/koha/opac/cgi-bin/opac' +)->to_app; + +my $apiv1 = builder { + my $server = Mojo::Server::PSGI->new; + $server->load_app('/home/koha/koha/api/v1/app.pl'); + $server->to_psgi_app; +}; + +builder { + enable "ReverseProxy"; + enable "Plack::Middleware::Static"; + # + is required so Plack doesn't try to prefix Plack::Middleware:: + enable "+Koha::Middleware::SetEnv"; + + mount '/opac' => $opac; + mount '/intranet' => $intranet; + mount '/api/v1/app.pl' => $apiv1; + +};