From 9e355ae444f1f51eda9f71ea8e205c0343e11323 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 14 Sep 2012 15:26:12 -0300 Subject: [PATCH] [SIGNED OFF] Bug 8773 - Start per-instance koha-index-daemon in .deb setup Short: Launch an indexing daemon (rebuild_zebra.pl -daemon) process for each enabled instance. Enabling/disabling the use of the indexer is handled by global configuration variables in /etc/default/koha-common. Also provides 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.[1] Using the indexer daemon could remain "experimental" until it gets more testing; so is disabled by default initially. To enable the use of the indexer the user has to tweak the /etc/default/koha-common config file. Specifically the USE_INDEXER_DAEMON variable, which is clearly explained in the file. Frecquency defaults to 5 sec, and can be changed by tweaking the /etc/default/koha-common config file too. This patch uses rebuild_zebra.pl in daemon mode, but it is crafted to allow changing the indexing daemon and passing specific option switches it might need. Regards To+ [1] This is the .deb version of http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=8519 Sponsored-by: Universidad Nacional de Cordoba Signed-off-by: Martin Renvoize --- debian/docs/koha-common.xml | 7 ++ debian/docs/koha-indexer.xml | 86 ++++++++++++++ debian/koha-common.cron.d | 1 + debian/koha-common.default | 37 +++++- debian/koha-common.init | 12 ++ debian/koha-common.install | 1 + debian/scripts/koha-create | 7 ++ debian/scripts/koha-functions.sh | 13 +++ debian/scripts/koha-indexer | 233 ++++++++++++++++++++++++++++++++++++++ 9 files changed, 396 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 @@ Stop Zebra for named Koha instances. + + + + + Manage the indexer daemon for named Koha instances. + + 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 @@ +
+koha-indexer + +Koha is the first free software library automation package. + + The Koha Community + http://koha-community.org/ + + + + + + + koha-indexer + 8 + + + + koha-indexer + Manage the indexer daemon for Koha instances. + UNIX/Linux + + + + + koha-indexer + |||||| + instancename + + + + Options + + + + + + + Start the indexer daemon for the desired Koha instances. + + + + + + + Stop the indexer daemon for the desired Koha instances. + + + + + + + Restart the indexer daemon for the desired Koha instances. + + + + + + + Make the script quiet about non existent instance names. Useful when calling koha-indexer from another scripts. + + + + + + + Show usage information. + + + + + + + Description + The koha-indexer script lets you manage your Koha instances indexer daemon. + + + See also + + /etc/default/koha-common + + + + + +
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 2f4dc40..66bc611 100644 --- a/debian/koha-common.default +++ b/debian/koha-common.default @@ -1,5 +1,40 @@ -## General koha-common default options +## General koha-common default options file PERL5LIB="/usr/share/koha/lib" +KOHA_HOME="/usr/share/koha" + +## Background record indexing +# +# The following options control the use of an indexing daemon for +# Koha instances. +# +# More information can be found here: +# +# http://wiki.koha-community.org/wiki/PackagesIndexDaemon +# +# IMPORTANT: You should comment the relevant line in /etc/cron.d/koha-common +# (the one that calls koha-rebuild-zebra) +# +# USE_INDEXER_DAEMON: "no" | "yes" +# +USE_INDEXER_DAEMON="no" + +# Set an alternate indexer daemon. The default is to use the rebuild_zebra.pl +# in daemon mode. +# +# Example: ALTERNATE_INDEXER_DAEMON="koha-index-daemon" +# +# ALTERNATE_INDEXER_DAEMON="" + +# Lookup/indexing frecquency (in seconds) for the indexing daemon. +# +# The default value is 5 +# +INDEXER_TIMEOUT=5 + +# Parameters to be passed to the indexer daemon. Useful for alternate indexers. +# Defaults to INDEXER_PARAMS="-daemon -x -sleep $INDEXER_TIMEOUT" +# +# INDEXER_PARAMS="" ## End of general koha-common default options 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 90a06d9..bdd5eca 100644 --- a/debian/koha-common.install +++ b/debian/koha-common.install @@ -17,6 +17,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 841ef86..6891ac1 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 . +# Read configuration variable file if it is present +[ -r /etc/default/koha-common ] && . /etc/default/koha-common set -e @@ -642,6 +644,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-functions.sh b/debian/scripts/koha-functions.sh index d1a3c04..8090fc5 100755 --- a/debian/scripts/koha-functions.sh +++ b/debian/scripts/koha-functions.sh @@ -108,6 +108,19 @@ is_zebra_running() 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 +} + get_instances() { find /etc/koha/sites -mindepth 1 -maxdepth 1\ diff --git a/debian/scripts/koha-indexer b/debian/scripts/koha-indexer new file mode 100755 index 0000000..c7c2858 --- /dev/null +++ b/debian/scripts/koha-indexer @@ -0,0 +1,233 @@ +#!/bin/bash +# +# koha-indexer - Manage Indexer Daemons for Koha instances +# Copyright 2014 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 . + +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 <