From 44ab2ee2790c02e2f34d4f68752fe8708d470c43 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 2 Jan 2013 23:46:32 +0000 Subject: [PATCH] Bug 9316: Add ability to install/configure nginx - Minor Corrections This patch adds minor changes to koha-plack.sh upstart script and a few corrections to permissions and missing directory locations to quiet errors This patch should be applied after Elliott Davis's patch. Test as before: 1) Ensure that you have nginx installed 2) Esure that you have the following packages installed libplack-perl libcgi-emulate-psgi-perl libcgi-compile-perl starman 3) Apply patch 4) Run through the make file, you will notice 5 new configuration options. 5) Make sure you choose NGiNX as your webserver 6) You may choose whatever ports you wish and also whatever DNS entries you wish 7) After you're done configuring run make 8) Run make install (you may need sudo if you've used sudo before) 9) Start plack (you may wish to copy the script to init.d) with the script in koha-dev/bin/koha-plack.sh (requires sudo) 10) TURN OFF APACHE, and start NGiNX 11) go to your web browser and see if everything fires up as normal. removed dependencies and updated init script to allow for the use of starman or plackup fixed debian control added a warning for nginx configurations modified koha.psgi to enable debugging only if plack::middleware::debug had been installed --- C4/Installer/PerlDependencies.pm | 10 --- Makefile.PL | 15 +++- debian/control | 19 ++--- etc/koha-nginx.conf | 5 ++ misc/bin/koha-plack.sh | 148 ++++++++++++++++++++++++++------------ misc/bin/koha.psgi | 13 +++- rewrite-config.PL | 1 + skel/var/lock/koha/plack/README | 1 + skel/var/run/koha/plack/README | 1 + 9 files changed, 146 insertions(+), 67 deletions(-) mode change 100644 => 100755 misc/bin/koha-plack.sh mode change 100644 => 100755 misc/bin/koha.psgi create mode 100644 skel/var/lock/koha/plack/README create mode 100644 skel/var/run/koha/plack/README diff --git a/C4/Installer/PerlDependencies.pm b/C4/Installer/PerlDependencies.pm index 020b8ad..832b59a 100644 --- a/C4/Installer/PerlDependencies.pm +++ b/C4/Installer/PerlDependencies.pm @@ -284,11 +284,6 @@ 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', @@ -299,11 +294,6 @@ our $PERL_DEPS = { '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 8dd7bcc..613c1fa 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -196,6 +196,14 @@ Directory for Zebra's data files. Directory for Zebra's UNIX-domain sockets. +=item PLACK_LOCK_DIR + +Directory for Plack's lock files. + +=item PLACK_RUN_DIR + +Directory for Plack's UNIX-domain sockets. + =item MISC_DIR Directory for for miscellaenous scripts, among other @@ -298,7 +306,8 @@ 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/plack' => { target => 'PLACK_RUN_DIR', trimdir => -1 }, + './skel/var/lock/koha/plack' => { target => 'PLACK_LOCK_DIR', trimdir => 6 }, './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 }, @@ -583,6 +592,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_LOCK_DIR => ['var', 'lock', 'plack'], PLACK_RUN_DIR => ['var', 'run', 'plack'], ); @@ -1289,6 +1299,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_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'plack'); $dirmap{'PLACK_RUN_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'run', 'plack'); } elsif ($mode eq 'dev') { my $curdir = File::Spec->rel2abs(File::Spec->curdir()); @@ -1320,6 +1331,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_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'plack'); $dirmap{'PLACK_RUN_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'run', 'plack'); } else { # mode is standard, i.e., 'fhs' @@ -1343,6 +1355,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_LOCK_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lock', $package, 'plack'); $dirmap{'PLACK_RUN_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'run', $package, 'plack'); } diff --git a/debian/control b/debian/control index 3541883..47b4671 100644 --- a/debian/control +++ b/debian/control @@ -6,12 +6,9 @@ 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: 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, +Build-Depends: EEEK: unknown package for Data::Pagination, libalgorithm-checkdigits-perl, + libanyevent-http-perl, libanyevent-perl, libauthen-cas-client-perl, libbiblio-endnotestyle-perl, @@ -49,6 +46,8 @@ Build-Depends: EEEK: unknown package for AnyEvent::HTTP, libgravatar-url-perl, libhtml-format-perl, libhtml-scrubber-perl, + libhttp-cookies-perl, + libhttp-message-perl, libhttp-oai-perl, libjson-any-perl, libjson-perl, @@ -88,6 +87,7 @@ Build-Depends: EEEK: unknown package for AnyEvent::HTTP, libtemplate-perl, libtemplate-plugin-htmltotext-perl, libtest-deep-perl, + libtest-harness-perl | perl-modules, libtest-mockmodule-perl, libtest-simple-perl | perl-modules, libtest-strict-perl, @@ -189,12 +189,10 @@ Description: Other dep. for koha daemon, debconf, etc.). Package: koha-perldeps -Depends: EEEK: unknown package for AnyEvent::HTTP, - EEEK: unknown package for Data::Pagination, +Depends: 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-http-perl, libanyevent-perl, libauthen-cas-client-perl, libbiblio-endnotestyle-perl, @@ -232,6 +230,8 @@ Depends: EEEK: unknown package for AnyEvent::HTTP, libgravatar-url-perl, libhtml-format-perl, libhtml-scrubber-perl, + libhttp-cookies-perl, + libhttp-message-perl, libhttp-oai-perl, libjson-any-perl, libjson-perl, @@ -271,6 +271,7 @@ Depends: EEEK: unknown package for AnyEvent::HTTP, libtemplate-perl, libtemplate-plugin-htmltotext-perl, libtest-deep-perl, + libtest-harness-perl | perl-modules, libtest-mockmodule-perl, libtest-simple-perl | perl-modules, libtest-strict-perl, diff --git a/etc/koha-nginx.conf b/etc/koha-nginx.conf index 27de0fd..3732985 100644 --- a/etc/koha-nginx.conf +++ b/etc/koha-nginx.conf @@ -1,3 +1,8 @@ +#USE THIS AT YOUR OWN RISK# +#DEVELOPMENT ONLY# +#NOT RECOMMENDED FOR PRODUCTION# +#02/06/2013 + upstream backendurl { server unix:__PLACK_RUN_DIR__/plack.sock; } diff --git a/misc/bin/koha-plack.sh b/misc/bin/koha-plack.sh old mode 100644 new mode 100755 index 9478984..e0f1632 --- a/misc/bin/koha-plack.sh +++ b/misc/bin/koha-plack.sh @@ -1,4 +1,4 @@ -#!/bin/sh -e +#!/bin/bash # This file is part of Koha. # @@ -15,59 +15,119 @@ # 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 +### BEGIN INIT INFO +# Provides: koha-plack-daemon # 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 +# Required-Stop: $syslog $remote_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Plack server daemon 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__ +NAME=KOHA +LOGDIR=__LOG_DIR__ +USER=www-data +GROUP=www-data RUNDIR=__PLACK_RUN_DIR__ -PIDFILE=$RUNDIR/plack.pid +LOCKDIR=__PLACK_LOCK_DIR__ +PIDFILE=$LOCKDIR/plack.pid +APP_PSGI=__SCRIPT_DIR__/koha.psgi +FCGI_LISTEN=$RUNDIR/plack.sock +#FCGI_LISTEN=127.0.0.1:5000 +OPTIONS="--listen $FCGI_LISTEN --access-log $LOGDIR/koha-access.log --error-log $LOGDIR/koha-error.log -M FindBin --max-requests 50 -E deployment $APP_PSGI" +DAEMON=$(which starman) + if [ ! -x "$DAEMON" ] ; then + OPTIONS="-s FCGI --listen $FCGI_LISTEN -E production --app $APP_PSGI --access-log $LOGDIR/koha-access.log --error-log $LOGDIR/koha-error.log" + DAEMON=$(which plackup) + fi -# Use one of these lines to choose between TCP port and UNIX socket listeners -SOCKET=$RUNDIR/plack.sock -#PORT=5000 +[ -f /lib/lsb/init-functions ] && . /lib/lsb/init-functions -case "$1" in - start) - echo "Starting Koha Plack Daemon" +start() +{ + log_daemon_msg "Starting plack server" "$NAME" + start-stop-daemon -b -m --start --quiet --pidfile "$PIDFILE" --exec $DAEMON -- $OPTIONS + sleep 3 + chown -R $USER:$GROUP $FCGI_LISTEN + chown -R $USER:$GROUP $LOCKDIR + if [ $? != 0 ]; then + log_end_msg 1 + exit 1 + else + log_end_msg 0 + fi +} - # 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 +signal() +{ - 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" + if [ "$1" = "stop" ]; then + SIGNAL="TERM" + log_daemon_msg "Stopping plack server" "$NAME" + else + if [ "$1" = "reload" ]; then + SIGNAL="HUP" + log_daemon_msg "Reloading plack server" "$NAME" + else + echo "ERR: wrong parameter given to signal()" + exit 1 + fi + fi + if [ -f "$PIDFILE" ]; then + start-stop-daemon --stop --signal $SIGNAL --quiet --pidfile "$PIDFILE" + if [ $? = 0 ]; then + log_end_msg 0 + else + SIGNAL="KILL" + start-stop-daemon --stop --signal $SIGNAL --quiet --pidfile "$PIDFILE" + if [ $? != 0 ]; then + log_end_msg 1 + [ $2 != 0 ] || exit 0 + else + rm "$PIDFILE" + log_end_msg 0 + fi fi - starman $opt __SCRIPT_DIR__/koha.psgi - - if [ $SOCKET ]; then - chown $USER:$GROUP $SOCKET - chmod 660 $SOCKET + if [ "$SIGNAL" = "KILL" ]; then + rm -f "$PIDFILE" fi - ;; + else + log_end_msg 0 + fi +} + +case "$1" in + start) + start + ;; + + force-start) + start + ;; + stop) - start-stop-daemon --stop --pidfile $PIDFILE - ;; + signal stop 0 + ;; + + force-stop) + signal stop 0 + ;; + + reload) + signal reload 0 + ;; + + force-reload|restart) + signal stop 1 + sleep 2 + start + ;; + *) - echo "Usage: koha-plack {start|stop}" - exit 1 - ;; -esac \ No newline at end of file + echo "Usage: /etc/init.d/$NAME {start|force-start|stop|force-stop|reload|restart|force-reload}" + exit 1 + ;; +esac + +exit 0 \ No newline at end of file diff --git a/misc/bin/koha.psgi b/misc/bin/koha.psgi old mode 100644 new mode 100755 index 014eec5..010907a --- a/misc/bin/koha.psgi +++ b/misc/bin/koha.psgi @@ -10,7 +10,6 @@ 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; @@ -22,16 +21,24 @@ use C4::Koha; use C4::XSLT; use C4::Branch; use C4::Category; +use Module::Load::Conditional qw[can_load check_install requires]; + +my $use_list = { + +}; + +if(can_load( modules => { Plack::Middleware::Debug => undef} ) && $ENV{KOHA_DEBUG}){ + my $panels = Plack::Middleware::Debug->default_panels; +} 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} + $ENV{KOHA_DEBUG} } 'Debug', panels => [[ 'DBITrace', level => 1 ], @$panels ]; enable "Plack::Middleware::Static"; diff --git a/rewrite-config.PL b/rewrite-config.PL index 58490f7..774ae1b 100644 --- a/rewrite-config.PL +++ b/rewrite-config.PL @@ -124,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_LOCK_DIR__' => "$prefix/var/lock/plack", '__PLACK_RUN_DIR__' => "$prefix/var/run/plack", '__ZEBRA_MARC_FORMAT__' => 'marc21', '__ZEBRA_LANGUAGE__' => 'en', diff --git a/skel/var/lock/koha/plack/README b/skel/var/lock/koha/plack/README new file mode 100644 index 0000000..6c11be4 --- /dev/null +++ b/skel/var/lock/koha/plack/README @@ -0,0 +1 @@ +Plack lock dir diff --git a/skel/var/run/koha/plack/README b/skel/var/run/koha/plack/README new file mode 100644 index 0000000..fa44b0b --- /dev/null +++ b/skel/var/run/koha/plack/README @@ -0,0 +1 @@ +Plack Unix-domain sockets -- 1.7.10.4