From 5b13811bbcd274b8e692635ab6ce2b14466da3d9 Mon Sep 17 00:00:00 2001 From: Elliott Davis Date: Mon, 24 Dec 2012 18:46:01 -0500 Subject: [PATCH] Bug 9316: Add ability to install/configure nginx fix for debian control Plack::Middleware::Debug and Starman have no packages --- C4/Installer/PerlDependencies.pm | 20 +++++++++ Makefile.PL | 86 +++++++++++++++++++++++++++++++++++++- debian/control | 24 ++++++++--- etc/koha-httpd.conf | 12 +++--- etc/koha-nginx.conf | 52 +++++++++++++++++++++++ misc/bin/koha-plack.sh | 73 ++++++++++++++++++++++++++++++++ misc/bin/koha.psgi | 43 +++++++++++++++++++ rewrite-config.PL | 6 +++ 8 files changed, 302 insertions(+), 14 deletions(-) create mode 100644 etc/koha-nginx.conf create mode 100644 misc/bin/koha-plack.sh create mode 100644 misc/bin/koha.psgi diff --git a/C4/Installer/PerlDependencies.pm b/C4/Installer/PerlDependencies.pm index 16144f9..f69a733 100644 --- a/C4/Installer/PerlDependencies.pm +++ b/C4/Installer/PerlDependencies.pm @@ -284,6 +284,26 @@ our $PERL_DEPS = { 'required' => '1', 'min_ver' => '3.15' }, + 'Starman' => { + 'usage' => 'preforking PSGI/PLACK web server', + 'required' => '0', + 'min_ver' => '0.300' + }, + 'CGI::Emulate::PSGI' => { + 'usage' => 'PLACK', + 'required' => '0', + 'min_ver' => '0.10' + }, + 'CGI::Compile' => { + 'usage' => 'PLACK CGI Compilation', + 'required' => '0', + 'min_ver' => '0.15' + }, + 'Plack::Middleware::Debug' => { + 'usage' => 'PLACK Debugging', + 'required' => '0', + 'min_ver' => '0.1' + }, 'Class::Factory::Util' => { 'usage' => 'Core', 'required' => '1', diff --git a/Makefile.PL b/Makefile.PL index 6c6e186..0191cc0 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -298,6 +298,7 @@ my $target_map = { './skel' => 'NONE', './skel/var/log/koha' => { target => 'LOG_DIR', trimdir => -1 }, './skel/var/spool/koha' => { target => 'BACKUP_DIR', trimdir => -1 }, + './skel/var/run/koha/plack' => { target => 'PLACK_RUN_DIR', trimdir => -1 }, './skel/var/run/koha/zebradb' => { target => 'ZEBRA_RUN_DIR', trimdir => -1 }, './skel/var/lock/koha/zebradb/authorities' => { target => 'ZEBRA_LOCK_DIR', trimdir => 6 }, './skel/var/lib/koha/zebradb/authorities/key' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 }, @@ -345,6 +346,26 @@ Koha from a git clone with no fuss). Directory under which most components will go. Default value will vary depending on INSTALL_MODE. +=item WEBSERVER + +Type of WebServer ( Apache2 or NGINX). + +=item INTRANET_DNS + +Set the DNS entry for staff client + +=item OPAC_DNS + +Set the DNS entry for OPAC + +=item INTRANET_PORT + +Set the port for the staff client + +=item OPAC_PORT + +Set the port for the OPAC + =item DB_TYPE Type of DBMS (e.g., mysql or Pg). @@ -405,6 +426,11 @@ System group that will own Koha's files. # default configuration options my %config_defaults = ( + 'WEBSERVER' => 'apache2', + 'INTRANET_DNS' => 'localhost', + 'OPAC_DNS' => 'localhost', + 'INTRANET_PORT' => '8080', + 'OPAC_PORT' => '80', 'DB_TYPE' => 'mysql', 'DB_HOST' => 'localhost', 'DB_NAME' => 'koha', @@ -464,6 +490,7 @@ else { my %valid_config_values = ( 'INSTALL_MODE' => { 'standard' => 1, 'single' => 1, 'dev' => 1 }, 'DB_TYPE' => { 'mysql' => 1, 'Pg' => 1 }, + 'WEBSERVER' => { 'apache2' => 1, 'nginx' => 1 }, 'INSTALL_ZEBRA' => { 'yes' => 1, 'no' => 1 }, 'INSTALL_SRU' => { 'yes' => 1, 'no' => 1 }, 'AUTH_INDEX_MODE' => { 'grs1' => 1, 'dom' => 1 }, @@ -496,15 +523,27 @@ get_file_map($target_map, $dirtree, $file_map, $config{'INSTALL_ZEBRA'} eq "yes" my $pl_files = { 'rewrite-config.PL' => [ 'blib/KOHA_CONF_DIR/koha-conf.xml', - 'blib/KOHA_CONF_DIR/koha-httpd.conf', + 'blib/KOHA_CONF_DIR/koha-nginx.conf', 'blib/ZEBRA_CONF_DIR/etc/default.idx', - 'blib/MISC_DIR/koha-install-log' + 'blib/MISC_DIR/koha-install-log', ], 'fix-perl-path.PL' => [ # this script ensures the correct shebang line for the platform installed on... 'blib' ], }; +if ($config{'WEBSERVER'} eq "apache2"){ + push @{ $pl_files->{'rewrite-config.PL'} }, ( + 'blib/KOHA_CONF_DIR/koha-httpd.conf', + ); +} +else { + push @{ $pl_files->{'rewrite-config.PL'} }, ( + 'blib/SCRIPT_DIR/koha.psgi', + 'blib/SCRIPT_DIR/koha-plack.sh', + ); +} + if ($config{'INSTALL_ZEBRA'} eq "yes") { push @{ $pl_files->{'rewrite-config.PL'} }, ( 'blib/ZEBRA_CONF_DIR/etc/passwd', @@ -559,6 +598,7 @@ my %test_suite_override_dirs = ( ZEBRA_LOCK_DIR => ['var', 'lock', 'zebradb'], ZEBRA_DATA_DIR => ['var', 'lib', 'zebradb'], ZEBRA_RUN_DIR => ['var', 'run', 'zebradb'], + PLACK_RUN_DIR => ['var', 'run', 'plack'], ); WriteMakefile( @@ -865,6 +905,45 @@ Group); } $msg = q( +Please specify which WebServer you will use +to serve data in Koha. The choices are Apache2 and +NGINX; please note that at the moment +NGINX support is highly experimental. + +WebServer to use); + $msg .= _add_valid_values_disp('WEBSERVER', $valid_values); + $config{'WEBSERVER'} = _get_value('WEBSERVER', $msg, $defaults->{'WEBSERVER'}, $valid_values, $install_log_values); + + $msg = q( +Please specify which WebServer you will use +to serve data in Koha. The choices are Apache2 and +NGINX; please note that at the moment +NGINX support is highly experimental. + +Intranet DNS Settings); + $config{'INTRANET_DNS'} = _get_value('INTRANET_DNS', $msg, $defaults->{'INTRANET_DNS'}, $valid_values, $install_log_values); + + $msg = q( +Please specify if you would like a DNS +entry for the Koha Staff Client. + +OPAC DNS Settings); + $config{'OPAC_DNS'} = _get_value('OPAC_DNS', $msg, $defaults->{'OPAC_DNS'}, $valid_values, $install_log_values); + + $msg = q( +Please specify the port you would +like the Koha Staff Client to use. + +Intranet Port Settings); + $config{'INTRANET_PORT'} = _get_value('INTRANET_PORT', $msg, $defaults->{'INTRANET_PORT'}, $valid_values, $install_log_values); + $msg = q( +Please specify if you would like a DNS +entry for the Koha Staff Client. + +OPAC Port Settings); + $config{'OPAC_PORT'} = _get_value('OPAC_PORt', $msg, $defaults->{'OPAC_PORT'}, $valid_values, $install_log_values); + + $msg = q( Please specify which database engine you will use to store data in Koha. The choices are MySQL and PostgreSQL; please note that at the moment @@ -1237,6 +1316,7 @@ sub get_target_directories { $dirmap{'BACKUP_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'spool'); $dirmap{'ZEBRA_DATA_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb'); $dirmap{'ZEBRA_RUN_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'run', 'zebradb'); + $dirmap{'PLACK_RUN_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'run', 'plack'); } elsif ($mode eq 'dev') { my $curdir = File::Spec->rel2abs(File::Spec->curdir()); $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir($curdir); @@ -1267,6 +1347,7 @@ sub get_target_directories { $dirmap{'BACKUP_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'spool'); $dirmap{'ZEBRA_DATA_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb'); $dirmap{'ZEBRA_RUN_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'run', 'zebradb'); + $dirmap{'PLACK_RUN_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'run', 'plack'); } else { # mode is standard, i.e., 'fhs' $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'cgi-bin'); @@ -1289,6 +1370,7 @@ sub get_target_directories { $dirmap{'BACKUP_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'spool', $package); $dirmap{'ZEBRA_DATA_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lib', $package, 'zebradb'); $dirmap{'ZEBRA_RUN_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'run', $package, 'zebradb'); + $dirmap{'PLACK_RUN_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'run', $package, 'plack'); } _get_env_overrides(\%dirmap); diff --git a/debian/control b/debian/control index 4447f10..3541883 100644 --- a/debian/control +++ b/debian/control @@ -6,13 +6,19 @@ Standards-Version: 3.8.4 # NOTA BENE: Build dependencies end up as runtime dependencies as well. # See debian/rules, the override_dh_gencontrol rules. # There are some exceptions. -Build-Depends: libalgorithm-checkdigits-perl, - libanyevent-http-perl, +Build-Depends: EEEK: unknown package for AnyEvent::HTTP, + EEEK: unknown package for Data::Pagination, + EEEK: unknown package for Data::Paginator, + EEEK: unknown package for Plack::Middleware::Debug, + EEEK: unknown package for Starman, + libalgorithm-checkdigits-perl, libanyevent-perl, libauthen-cas-client-perl, libbiblio-endnotestyle-perl, libbusiness-isbn-perl, libcache-memcached-fast-perl, + libcgi-compile-perl, + libcgi-emulate-psgi-perl, libcgi-pm-perl | perl-modules, libcgi-session-driver-memcached-perl, libcgi-session-perl, @@ -22,7 +28,6 @@ Build-Depends: libalgorithm-checkdigits-perl, libclass-accessor-perl, libclass-factory-util-perl, libdata-ical-perl, - libdata-paginator-perl, libdate-calc-perl, libdate-manip-perl, libdatetime-event-ical-perl, @@ -78,6 +83,7 @@ Build-Depends: libalgorithm-checkdigits-perl, libscalar-list-utils-perl, libschedule-at-perl, libsms-send-perl, + libstring-random-perl, libstring-rewriteprefix-perl, libtemplate-perl, libtemplate-plugin-htmltotext-perl, @@ -183,13 +189,19 @@ Description: Other dep. for koha daemon, debconf, etc.). Package: koha-perldeps -Depends: libalgorithm-checkdigits-perl, - libanyevent-http-perl, +Depends: EEEK: unknown package for AnyEvent::HTTP, + EEEK: unknown package for Data::Pagination, + EEEK: unknown package for Data::Paginator, + EEEK: unknown package for Plack::Middleware::Debug, + EEEK: unknown package for Starman, + libalgorithm-checkdigits-perl, libanyevent-perl, libauthen-cas-client-perl, libbiblio-endnotestyle-perl, libbusiness-isbn-perl, libcache-memcached-fast-perl, + libcgi-compile-perl, + libcgi-emulate-psgi-perl, libcgi-pm-perl | perl-modules, libcgi-session-driver-memcached-perl, libcgi-session-perl, @@ -199,7 +211,6 @@ Depends: libalgorithm-checkdigits-perl, libclass-accessor-perl, libclass-factory-util-perl, libdata-ical-perl, - libdata-paginator-perl, libdate-calc-perl, libdate-manip-perl, libdatetime-event-ical-perl, @@ -255,6 +266,7 @@ Depends: libalgorithm-checkdigits-perl, libscalar-list-utils-perl, libschedule-at-perl, libsms-send-perl, + libstring-random-perl, libstring-rewriteprefix-perl, libtemplate-perl, libtemplate-plugin-htmltotext-perl, diff --git a/etc/koha-httpd.conf b/etc/koha-httpd.conf index dc82d08..f0edb61 100644 --- a/etc/koha-httpd.conf +++ b/etc/koha-httpd.conf @@ -3,11 +3,11 @@ #NameVirtualHost * ## OPAC - + ServerAdmin __WEBMASTER_EMAIL__ DocumentRoot __OPAC_WWW_DIR__ - ServerName __WEBSERVER_HOST__ -# ServerAlias opac.mydomain.com + ServerName __OPAC_DNS__:__OPAC_PORT__ +# ServerAlias __OPAC_DNS__ ScriptAlias /cgi-bin/koha/ "__OPAC_CGI_DIR__/opac/" ScriptAlias /index.html "__OPAC_CGI_DIR__/opac/opac-main.pl" ScriptAlias /opac-search.pl "__OPAC_CGI_DIR__/opac/opac-search.pl" @@ -97,11 +97,11 @@ ## Intranet - + ServerAdmin __WEBMASTER_EMAIL__ DocumentRoot __INTRANET_WWW_DIR__ - ServerName __WEBSERVER_HOST__:__WEBSERVER_PORT_LIBRARIAN__ -# ServerAlias intranet.mydomain.com + ServerName __INTRANET_DNS__:__INTRANET_PORT__ +# ServerAlias __INTRANET_DNS__ ScriptAlias /cgi-bin/koha/ "__INTRANET_CGI_DIR__/" ScriptAlias /index.html "__INTRANET_CGI_DIR__/mainpage.pl" ScriptAlias /search "__INTRANET_CGI_DIR__/search.pl" diff --git a/etc/koha-nginx.conf b/etc/koha-nginx.conf new file mode 100644 index 0000000..33f96b8 --- /dev/null +++ b/etc/koha-nginx.conf @@ -0,0 +1,52 @@ +upstream backendurl { + server unix:__PLACK_RUN_DIR__/plack.sock; +} + +server { + listen __OPAC_PORT__; + server_name __OPAC_DNS__; + access_log __LOG_DIR__/nginx-opac-access.log; + root __OPAC_WWW_DIR__; + + rewrite ^/$ /cgi-bin/koha/opac-main.pl; + rewrite ^/cgi-bin/koha/(.*)$ /cgi-bin/koha/opac/$1; + + location / { + try_files $uri @plack; + } + location /opac-tmpl/ { + root __OPAC_WWW_DIR__; + } + + location @plack { + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_pass http://backendurl; + } +} + +server { + listen __INTRANET_PORT__; + server_name __INTRANET_DNS__; + access_log __LOG_DIR__/nginx-intranet-access.log; + root __INTRANET_WWW_DIR__; + + rewrite ^/$ /cgi-bin/koha/mainpage.pl; + + location / { + try_files $uri @plack; + } + location /intranet-tmpl/ { + root __INTRANET_WWW_DIR__; + } + + location @plack { + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_pass http://backendurl; + } +} \ No newline at end of file diff --git a/misc/bin/koha-plack.sh b/misc/bin/koha-plack.sh new file mode 100644 index 0000000..3a2bd5a --- /dev/null +++ b/misc/bin/koha-plack.sh @@ -0,0 +1,73 @@ +#!/bin/sh -e + +# This file is part of Koha. +# +# Koha 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. +# +# Koha 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 +# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, +# Suite 330, Boston, MA 02111-1307 USA + +### BEGIN INIT INFO# Provides: koha-plack +# Required-Start: $syslog $remote_fs +# Required-Stop: $syslog $remote_fs# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6# Short-Description: Plack server for Koha +### END INIT INFO + +export KOHA_CONF=__KOHA_CONF_DIR__/koha-conf.xml +#export OPACDIR=__OPAC_WWW_DIR__ +#export INTRANETDIR=__OPAC_WWW_DIR__ +export LOGDIR=__LOG_DIR__ +USER=__KOHA_USER__ +GROUP=__KOHA_GROUP__ +RUNDIR=__PLACK_RUN_DIR__ +PIDFILE=$RUNDIR/plack.pid + +# Use one of these lines to choose between TCP port and UNIX socket listeners +SOCKET=$RUNDIR/plack.sock +#PORT=5000 + +case "$1" in + start) + echo "Starting Koha Plack Daemon" + + # create run and lock directories if needed; + # /var/run and /var/lock are completely cleared at boot + # on some platforms + if [ ! -d $RUNDIR ]; then + umask 022 + mkdir -p $RUNDIR + if [ $EUID -eq 0 ]; then + chown $USER:$GROUP $RUNDIR + fi + fi + + opt="$opt --access-log $LOGDIR/koha-access.log --error-log $LOGDIR/koha-error.log" + opt="$opt -M FindBin --max-requests 50 --workers 2 -E deployment" + if [ $SOCKET ]; then + opt="$opt --listen $SOCKET -D --pid $PIDFILE" + elif [ $PORT ]; then + opt="$opt --port $PORT -D --pid $PIDFILE" + fi + starman $opt __SCRIPT_DIR__/koha.psgi + + if [ $SOCKET ]; then + chown $USER:$GROUP $SOCKET + chmod 775 $SOCKE + fi + ;; + stop) + start-stop-daemon --stop --pidfile $PIDFILE + ;; + *) + echo "Usage: koha-plack {start|stop}" + exit 1 + ;; +esac \ No newline at end of file diff --git a/misc/bin/koha.psgi b/misc/bin/koha.psgi new file mode 100644 index 0000000..2023f50 --- /dev/null +++ b/misc/bin/koha.psgi @@ -0,0 +1,43 @@ +#!/usr/bin/perl + +BEGIN { + $ENV{'KOHA_CONF'} = '__KOHA_CONF_DIR__/koha-conf.xml'; + $ENV{'PERL5LIB'} = '__PERL_MODULE_DIR__'; +} + +use lib("__PERL_MODULE_DIR__"); +use lib("__PERL_MODULE_DIR__/installer"); +use Plack::Builder; +use Plack::App::CGIBin; +use Plack::App::Directory; +use Plack::Middleware::Debug; +use Plack::App::URLMap; +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; + +C4::Context->disable_syspref_cache(); + +my $intra=Plack::App::CGIBin->new(root => "__INTRANET_CGI_DIR__" ); + +my $opac = Plack::App::CGIBin->new(root => "__OPAC_CGI_DIR__"); +my $panels = Plack::Middleware::Debug->default_panels; +builder { + enable_if{ + $ENV{DEBUG} + } 'Debug', panels => [[ 'DBITrace', level => 1 ], @$panels ]; + + enable "Plack::Middleware::Static"; + + enable 'StackTrace'; + + mount '/cgi-bin/koha/' => $intra; + mount '/cgi-bin/koha/opac' => $opac; +}; diff --git a/rewrite-config.PL b/rewrite-config.PL index 02715ab..58490f7 100644 --- a/rewrite-config.PL +++ b/rewrite-config.PL @@ -82,6 +82,11 @@ $prefix = $ENV{'INSTALL_BASE'} || "/usr"; %configuration = ( "__KOHA_INSTALLED_VERSION__" => "no_version_found", "__LOG_DIR__" => "/var/log", + "__WEBSERVER__" => "apache2", + "__INTRANET_DNS__" => "localhost", + "__OPAC_DNS__" => "localhost", + "__OPAC_PORT__" => "80", + "__INTRANET_PORT__" => "8080", "__DB_TYPE__" => "mysql", "__DB_NAME__" => "koha", "__DB_HOST__" => $myhost, @@ -119,6 +124,7 @@ $prefix = $ENV{'INSTALL_BASE'} || "/usr"; '__ZEBRA_LOCK_DIR__' => "$prefix/var/lock/zebradb", '__ZEBRA_DATA_DIR__' => "$prefix/var/lib/zebradb", '__ZEBRA_RUN_DIR__' => "$prefix/var/run/zebradb", + '__PLACK_RUN_DIR__' => "$prefix/var/run/plack", '__ZEBRA_MARC_FORMAT__' => 'marc21', '__ZEBRA_LANGUAGE__' => 'en', '__ZEBRA_TOKENIZER_STMT__' => 'charmap word-phrase-utf.chr', -- 1.7.2.5