Bugzilla – Attachment 22135 Details for
Bug 8773
Add per-instance koha-index-daemon in .deb setup
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 8773 - Start per-instance koha-index-daemon in .deb setup
Bug-8773---Start-per-instance-koha-index-daemon-in.patch (text/plain), 17.03 KB, created by
Chris Cormack
on 2013-10-20 23:32:36 UTC
(
hide
)
Description:
Bug 8773 - Start per-instance koha-index-daemon in .deb setup
Filename:
MIME Type:
Creator:
Chris Cormack
Created:
2013-10-20 23:32:36 UTC
Size:
17.03 KB
patch
obsolete
>From e65f8ba8e520af9f14af52207c9a87cdc6325904 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@gmail.com> >Date: Fri, 14 Sep 2012 15:26:12 -0300 >Subject: [PATCH] Bug 8773 - Start per-instance koha-index-daemon in .deb setup > >Short: > >Launch a koha-index-daemon (from Koha::Contrib::tamil) process for each >enabled instance. Enabling/disabling the use of the indexer is handled >using a new(ly introduced) /etc/default/koha-common config file that >can be used for other stuff too, and is the Debian way of handling >init scripts control variables[1]. > >Also provide command line tools to manage the running indexer daemons >for your instances. > >Long: > >Using an indexing daemon avoids launching a new interpreter each time >the cron triggers the indexing, and also allows sub-minute incremental >reindexing, a requirement from our librarians.[2] > >Using the indexer daemon should remain "experimental" so is disabled by >default. To enable the use of the indexer the user has to tweak the >/etc/default/koha-common config file (introduced by this patch). Specifically >the USE_INDEXER_DAEMON variable, which is clearly explained in the file. > >Update frecquency defaults to 30 sec, and can be changed by tweaking the >/etc/default/koha-common config file too. > >This patch relies on Koha::Contrib::Tamil's koha-index-daemon script [3], >but could be easily adjusted to use another if we got a new one (SolR?). >As Robin proposed it checks for availability of the relevant files before >trying to spawn the daemon. > >If there's something I could change to make this patches better just let me know. > >Note: there was a problem Robin found regarding the spawned processes forgetting >the PERL5LIB and/or KOHA_CONF env variables, this is fixed in this version >with the inclusion of the 'export' keyword for the relevant variables. > >Edit: fixed koha-create to call the koha-indexer script instead, and added >-q to make koha-inxeder quiet (useful for the init script). > >Regards >To+ > >[1] Section 9.3.2 of http://www.debian.org/doc/debian-policy/ch-opersys.html >[2] This is the .deb version of http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=8519 >[3] The default cronjob that is set using the debian/koha-common.cron.d file >is being disbaled by this patch to avoid collision. > >Sponsored-by: Universidad Nacional de Cordoba >Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz> >--- > debian/docs/koha-common.xml | 7 ++ > debian/docs/koha-indexer.xml | 86 ++++++++++++++ > debian/koha-common.cron.d | 1 + > debian/koha-common.default | 20 +++- > debian/koha-common.init | 12 ++ > debian/koha-common.install | 1 + > debian/scripts/koha-create | 7 ++ > debian/scripts/koha-indexer | 277 +++++++++++++++++++++++++++++++++++++++++++ > 8 files changed, 410 insertions(+), 1 deletion(-) > create mode 100644 debian/docs/koha-indexer.xml > create mode 100755 debian/scripts/koha-indexer > >diff --git a/debian/docs/koha-common.xml b/debian/docs/koha-common.xml >index d602aa9..2790341 100644 >--- a/debian/docs/koha-common.xml >+++ b/debian/docs/koha-common.xml >@@ -145,6 +145,13 @@ > <para>Stop Zebra for named Koha instances.</para> > </listitem> > </varlistentry> >+ >+ <varlistentry> >+ <term><option>koha-indexer</option></term> >+ <listitem> >+ <para>Manage the indexer daemon for named Koha instances.</para> >+ </listitem> >+ </varlistentry> > </variablelist> > </refsect2> > >diff --git a/debian/docs/koha-indexer.xml b/debian/docs/koha-indexer.xml >new file mode 100644 >index 0000000..66e177c >--- /dev/null >+++ b/debian/docs/koha-indexer.xml >@@ -0,0 +1,86 @@ >+<article xmlns='http://docbook.org/ns/docbook'> >+<title>koha-indexer</title> >+<info> >+<productname>Koha</productname> is the first free software library automation package. >+<author> >+ <orgname>The Koha Community</orgname> >+ <uri>http://koha-community.org/</uri> >+</author> >+</info> >+ >+<refentry xml:id="koha-indexer"> >+ >+ <refmeta> >+ <refentrytitle>koha-indexer</refentrytitle> >+ <manvolnum>8</manvolnum> >+ </refmeta> >+ >+ <refnamediv> >+ <refname>koha-indexer</refname> >+ <refpurpose>Manage the indexer daemon for Koha instances.</refpurpose> >+ <refclass>UNIX/Linux</refclass> >+ </refnamediv> >+ >+ <refsynopsisdiv> >+ <cmdsynopsis> >+ <command>koha-indexer</command> >+ <arg choice="req"><option>--start</option>|<option>--stop</option>|<option>--restart</option>|<option>--help</option>|<option>-h</option>|<option>--quiet</option>|<option>-q</option></arg> >+ <arg choice="req" rep="repeat"><replaceable>instancename</replaceable></arg> >+ </cmdsynopsis> >+ </refsynopsisdiv> >+ >+ <refsect1><title>Options</title> >+ >+ <variablelist> >+ >+ <varlistentry> >+ <term><option>--start</option></term> >+ <listitem> >+ <para>Start the indexer daemon for the desired Koha instances.</para> >+ </listitem> >+ </varlistentry> >+ >+ <varlistentry> >+ <term><option>--stop</option></term> >+ <listitem> >+ <para>Stop the indexer daemon for the desired Koha instances.</para> >+ </listitem> >+ </varlistentry> >+ >+ <varlistentry> >+ <term><option>--restart</option></term> >+ <listitem> >+ <para>Restart the indexer daemon for the desired Koha instances.</para> >+ </listitem> >+ </varlistentry> >+ >+ <varlistentry> >+ <term><option>--quiet|-q</option></term> >+ <listitem> >+ <para>Make the script quiet about non existent instance names. Useful when calling <command>koha-indexer</command> from another scripts.</para> >+ </listitem> >+ </varlistentry> >+ >+ <varlistentry> >+ <term><option>--help|-h</option></term> >+ <listitem> >+ <para>Show usage information.</para> >+ </listitem> >+ </varlistentry> >+ >+ </variablelist> >+ </refsect1> >+ >+ <refsect1><title>Description</title> >+ <para>The <command>koha-indexer</command> script lets you manage your Koha instances indexer daemon.</para> >+ </refsect1> >+ >+ <refsect1><title>See also</title> >+ <simplelist type="inline"> >+ <member><command>/etc/default/koha-common</command></member> >+ </simplelist> >+ </refsect1> >+ >+</refentry> >+ >+</article> >diff --git a/debian/koha-common.cron.d b/debian/koha-common.cron.d >index f763f30..96ff1b2 100644 >--- a/debian/koha-common.cron.d >+++ b/debian/koha-common.cron.d >@@ -6,5 +6,6 @@ > SHELL=/bin/sh > PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin > >+# Comment the following line if you want to use the experimental koha-index-daemon integration > */5 * * * * root test -x /usr/sbin/koha-rebuild-zebra && koha-rebuild-zebra -q $(koha-list --enabled) > */15 * * * * root koha-foreach --enabled --email /usr/share/koha/bin/cronjobs/process_message_queue.pl >diff --git a/debian/koha-common.default b/debian/koha-common.default >index d572f17..73b27a6 100644 >--- a/debian/koha-common.default >+++ b/debian/koha-common.default >@@ -1,3 +1,21 @@ >-## General koha-common default options >+## General koha-common default options file > > PERL5LIB="/usr/share/koha/lib" >+ >+# If you want to use the koha-index-daemon script that is part of the >+# Koha::Contrib::Tamil package instead of the cronjob, set USE_INDEXER_DAEMON >+# to "yes". More information can be found here: >+# http://wiki.koha-community.org/wiki/PackagesIndexDaemon >+# Note: You should comment the relevant line in /etc/cron.d/koha-common >+# >+# The default value is "no" >+USE_INDEXER_DAEMON="no" >+ >+# Indexer daemon script. The default is to use Tamil's >+INDEXER_DAEMON="koha-index-daemon" >+ >+# If you are using the koha-index-daemon you can set the frecquency (in sec) >+# of the indexes update. >+# >+# The default value is 30 >+INDEXER_TIMEOUT=30 >diff --git a/debian/koha-common.init b/debian/koha-common.init >index 1ba591d..241aaa6 100755 >--- a/debian/koha-common.init >+++ b/debian/koha-common.init >@@ -49,6 +49,10 @@ do_start() > koha-create-dirs $(koha-list) > koha-start-zebra $(koha-list --enabled) > koha-start-sip $(koha-list --enabled) >+ >+ if [ "$USE_INDEXER_DAEMON" = "yes" ]; then >+ koha-indexer --start --quiet $(koha-list --enabled) >+ fi > } > > # >@@ -59,6 +63,10 @@ do_stop() > # We stop everything, including disabled ones. > koha-stop-zebra $(koha-list) || true > koha-stop-sip $(koha-list) || true >+ >+ if [ "$USE_INDEXER_DAEMON" = "yes" ]; then >+ koha-indexer --stop --quiet $(koha-list --enabled) >+ fi > } > > # >@@ -68,6 +76,10 @@ do_reload() { > koha-restart-zebra $(koha-list --enabled) > koha-stop-sip $(koha-list) || true > koha-start-sip $(koha-list --enabled) >+ >+ if [ "$USE_INDEXER_DAEMON" = "yes" ]; then >+ koha-indexer --restart --quiet $(koha-list --enabled) >+ fi > } > > # >diff --git a/debian/koha-common.install b/debian/koha-common.install >index e215bde..e894f37 100644 >--- a/debian/koha-common.install >+++ b/debian/koha-common.install >@@ -16,6 +16,7 @@ debian/scripts/koha-email-disable usr/sbin > debian/scripts/koha-email-enable usr/sbin > debian/scripts/koha-enable usr/sbin > 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-rebuild-zebra usr/sbin >diff --git a/debian/scripts/koha-create b/debian/scripts/koha-create >index e8b2578..e806630 100755 >--- a/debian/scripts/koha-create >+++ b/debian/scripts/koha-create >@@ -16,6 +16,8 @@ > # You should have received a copy of the GNU General Public License > # along with this program. If not, see <http://www.gnu.org/licenses/>. > >+# Read configuration variable file if it is present >+[ -r /etc/default/koha-common ] && . /etc/default/koha-common > > set -e > >@@ -450,6 +452,11 @@ then > > # Start Zebra. > koha-start-zebra "$name" >+ >+ if [ "$USE_INDEXER_DAEMON" = "yes" ]; then >+ # Start Indexer daemon >+ koha-indexer --start "$name" >+ fi > fi > > >diff --git a/debian/scripts/koha-indexer b/debian/scripts/koha-indexer >new file mode 100755 >index 0000000..ec3a69e >--- /dev/null >+++ b/debian/scripts/koha-indexer >@@ -0,0 +1,277 @@ >+#!/bin/bash >+# >+# koha-indexer - Manage Indexer Daemons for Koha instances >+# Copyright 2012 Tomás Cohen Arazi @ Universidad Nacional de Córdoba >+# >+# 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 <http://www.gnu.org/licenses/>. >+ >+set -e >+ >+. /lib/lsb/init-functions >+ >+# Read configuration variable file if it is present >+[ -r /etc/default/koha-common ] && . /etc/default/koha-common >+ >+warn() >+{ >+ echo "$@" 1>&2 >+} >+ >+die() >+{ >+ echo "$@" 1>&2 >+ exit 1 >+} >+ >+usage() >+{ >+ local scriptname=$(basename $0) >+ >+ cat <<EOF >+$scriptname >+ >+This script lets you manage the indexer daemon for your Koha instances. >+ >+Usage: >+$scriptname [--start|--stop|--restart] [--quiet|-q] instancename1 [instancename2...] >+$scriptname -h|--help >+ >+ --start Start the indexer daemon for the specified instances >+ --stop Stop the indexer daemon for the specified instances >+ --restart Restart the indexer daemon for the specified instances >+ --quiet|-q Make the script quiet about non existent instance names >+ --help|-h Display this help message >+ >+EOF >+} >+ >+is_instance() >+{ >+ local instancename=$1 >+ >+ if find /etc/koha/sites -mindepth 1 -maxdepth 1 \ >+ -type d -printf '%f\n'\ >+ | grep -q -x -e "$instancename" ; then >+ return 0 >+ else >+ return 1 >+ fi >+} >+ >+is_indexer_running() >+{ >+ local instancename=$1 >+ >+ if daemon --name="$instancename-koha-indexer" \ >+ --user="$instancename-koha.$instancename-koha" \ >+ --running ; then >+ return 0 >+ else >+ return 1 >+ fi >+} >+ >+start_indexer() >+{ >+ local name=$1 >+ >+ if ! is_indexer_running $name; then >+ export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" >+ >+ INDEXDAEMON_OPTS="--timeout $INDEXER_TIMEOUT \ >+ --conf $KOHA_CONF \ >+ --directory /var/tmp/koha-indexer-daemon-$name" >+ >+ DAEMONOPTS="--name=$name-koha-indexer \ >+ --errlog=/var/log/koha/$name/indexer-error.log \ >+ --stdout=/var/log/koha/$name/indexer.log \ >+ --output=/var/log/koha/$name/indexer-output.log \ >+ --verbose=1 --respawn --delay=30 \ >+ --user=$name-koha.$name-koha" >+ >+ log_daemon_msg "Starting Koha indexing daemon for $name" >+ >+ if daemon $DAEMONOPTS -- $INDEXER_DAEMON $INDEXDAEMON_OPTS; then >+ log_end_msg 0 >+ else >+ log_end_msg 1 >+ fi >+ else >+ log_daemon_msg "Error: Indexer already running for $name" >+ log_end_msg 1 >+ fi >+} >+ >+stop_indexer() >+{ >+ local name=$1 >+ >+ if is_indexer_running $name; then >+ export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" >+ >+ INDEXDAEMON_OPTS="--timeout 30 \ >+ --conf $KOHA_CONF \ >+ --directory /var/tmp/koha-indexer-daemon-$name" >+ >+ DAEMONOPTS="--name=$name-koha-indexer \ >+ --errlog=/var/log/koha/$name/indexer-error.log \ >+ --stdout=/var/log/koha/$name/indexer.log \ >+ --output=/var/log/koha/$name/indexer-output.log \ >+ --verbose=1 --respawn --delay=30 \ >+ --user=$name-koha.$name-koha" >+ >+ log_daemon_msg "Stopping Koha indexing daemon for $name" >+ >+ if daemon $DAEMONOPTS --stop -- $INDEXER_DAEMON $INDEXDAEMON_OPTS; then >+ log_end_msg 0 >+ else >+ log_end_msg 1 >+ fi >+ else >+ log_daemon_msg "Error: Indexer not running for $name" >+ log_end_msg 1 >+ fi >+} >+ >+restart_indexer() >+{ >+ local name=$1 >+ >+ if is_indexer_running $name; then >+ export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" >+ >+ INDEXDAEMON_OPTS="--timeout 30 \ >+ --conf $KOHA_CONF \ >+ --directory /var/tmp/koha-indexer-daemon-$name" >+ >+ DAEMONOPTS="--name=$name-koha-indexer \ >+ --errlog=/var/log/koha/$name/indexer-error.log \ >+ --stdout=/var/log/koha/$name/indexer.log \ >+ --output=/var/log/koha/$name/indexer-output.log \ >+ --verbose=1 --respawn --delay=30 \ >+ --user=$name-koha.$name-koha" >+ >+ log_daemon_msg "Stopping Koha indexing daemon for $name" >+ >+ if daemon $DAEMONOPTS --restart -- $INDEXER_DAEMON $INDEXDAEMON_OPTS; then >+ log_end_msg 0 >+ else >+ log_end_msg 1 >+ fi >+ else >+ log_daemon_msg "Error: Indexer not running for $name" >+ log_end_msg 1 >+ fi >+} >+ >+set_action() >+{ >+ if [ "$op" = "" ]; then >+ op=$1 >+ else >+ die "Error: only one action can be specified." >+ fi >+} >+ >+op="" >+quiet="no" >+ >+# Read command line parameters >+while [ $# -gt 0 ]; do >+ >+ case "$1" in >+ -h|--help) >+ usage ; exit 0 ;; >+ -q|--quiet) >+ quiet="yes" >+ shift ;; >+ --start) >+ set_action "start" >+ shift ;; >+ --stop) >+ set_action "stop" >+ shift ;; >+ --restart) >+ set_action "restart" >+ shift ;; >+ -*) >+ die "Error: invalid option switch ($1)" ;; >+ *) >+ # We expect the remaining stuff are the instance names >+ break ;; >+ esac >+ >+done >+ >+# Some default variables >+if [ -z $INDEXER_DAEMON ]; then >+ INDEXER_DAEMON="koha-index-daemon" >+fi >+ >+if [ -z $PERL5LIB ]; then >+ PERL5LIB="/usr/share/koha/lib" >+fi >+ >+export PERL5LIB >+ >+if [ $INDEXER_TIMEOUT -lt 1 ]; then >+ # Something's wrong, default to 30 >+ INDEXER_TIMEOUT=30 >+fi >+ >+ >+if [ ! -e /usr/share/perl5/Koha/Contrib/Tamil/IndexerDaemon.pm ] ; then >+ MSG=`cat <<EOF >+Koha::Contrib::Tamil::IndexerDaemon was not found. See >+http://wiki.koha-community.org/wiki/PackagesIndexDaemon >+for instructions on setting up the indexer daemon. >+EOF` >+ >+ die $MSG >+fi >+ >+ >+if [ $# -gt 0 ]; then >+ # We have at least one instance name >+ for name in "$@"; do >+ >+ if is_instance $name; then >+ >+ case $op in >+ "start") >+ start_indexer $name >+ ;; >+ "stop") >+ stop_indexer $name >+ ;; >+ "restart") >+ restart_indexer $name >+ ;; >+ esac >+ >+ else >+ if [ "$quiet" = "no" ]; then >+ log_daemon_msg "Error: Invalid instance name $name" >+ log_end_msg 1 >+ fi >+ fi >+ >+ done >+else >+ if [ "$quiet" = "no" ]; then >+ warn "Error: you must provide at least one instance name" >+ fi >+fi >+ >+exit 0 >-- >1.8.4.rc3
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 8773
:
12248
|
12285
|
12292
|
12293
|
12294
|
12654
|
13009
|
13031
|
13050
|
13089
|
18258
|
19794
|
19798
|
19800
|
19805
|
21704
|
22135
|
23928
|
29194
|
29575
|
29669