3 # koha-indexer - Manage Indexer Daemons for Koha instances
4 # Copyright 2014 Tomás Cohen Arazi @ Universidad Nacional de Córdoba
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 .
/lib
/lsb
/init-functions
23 # Read configuration variable file if it is present
24 [ -r /etc
/default
/koha-common
] && .
/etc
/default
/koha-common
26 # include helper functions
27 if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
28 .
"/usr/share/koha/bin/koha-functions.sh"
30 echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
36 local scriptname
=$
(basename $0)
41 This script lets you manage the indexer daemon for your Koha instances.
44 $scriptname [--start|--stop|--restart] [--quiet|-q] instancename1 [instancename2...]
47 --start Start the indexer daemon for the specified instances
48 --stop Stop the indexer daemon for the specified instances
49 --restart Restart the indexer daemon for the specified instances
50 --quiet|-q Make the script quiet about non existent instance names
51 (useful for calling from another scripts).
52 --help|-h Display this help message
61 if ! is_indexer_running
$name; then
62 export KOHA_CONF
="/etc/koha/sites/$name/koha-conf.xml"
64 DAEMONOPTS
="--name=$name-koha-indexer \
65 --errlog=/var/log/koha/$name/indexer-error.log \
66 --stdout=/var/log/koha/$name/indexer.log \
67 --output=/var/log/koha/$name/indexer-output.log \
68 --pidfiles=/var/run/koha/$name/ \
69 --verbose=1 --respawn --delay=30 \
70 --user=$name-koha.$name-koha"
72 log_daemon_msg
"Starting Koha indexing daemon for $name"
74 if daemon
$DAEMONOPTS -- $INDEXER_DAEMON $INDEXER_PARAMS; then
80 log_daemon_msg
"Error: Indexer already running for $name"
89 if is_indexer_running
$name; then
90 export KOHA_CONF
="/etc/koha/sites/$name/koha-conf.xml"
92 DAEMONOPTS
="--name=$name-koha-indexer \
93 --errlog=/var/log/koha/$name/indexer-error.log \
94 --stdout=/var/log/koha/$name/indexer.log \
95 --output=/var/log/koha/$name/indexer-output.log \
96 --pidfiles=/var/run/koha/$name/ \
97 --verbose=1 --respawn --delay=30 \
98 --user=$name-koha.$name-koha"
100 log_daemon_msg
"Stopping Koha indexing daemon for $name"
102 if daemon
$DAEMONOPTS --stop -- $INDEXER_DAEMON $INDEXER_PARAMS; then
108 log_daemon_msg
"Error: Indexer not running for $name"
117 if is_indexer_running
$name; then
118 export KOHA_CONF
="/etc/koha/sites/$name/koha-conf.xml"
120 DAEMONOPTS
="--name=$name-koha-indexer \
121 --errlog=/var/log/koha/$name/indexer-error.log \
122 --stdout=/var/log/koha/$name/indexer.log \
123 --output=/var/log/koha/$name/indexer-output.log \
124 --pidfiles=/var/run/koha/$name/ \
125 --verbose=1 --respawn --delay=30 \
126 --user=$name-koha.$name-koha"
128 log_daemon_msg
"Stopping Koha indexing daemon for $name"
130 if daemon
$DAEMONOPTS --restart -- $INDEXER_DAEMON $INDEXER_PARAMS; then
136 log_daemon_msg
"Error: Indexer not running for $name"
143 if [ "$op" = "" ]; then
146 die
"Error: only one action can be specified."
153 # Read command line parameters
154 while [ $# -gt 0 ]; do
172 die
"Error: invalid option switch ($1)" ;;
174 # We expect the remaining stuff are the instance names
180 # Check if an alternate indexer has been set
181 if [ ! -z $ALTERNATE_INDEXER_DAEMON ]; then
182 INDEXER_DAEMON
="$ALTERNATE_INDEXER_DAEMON"
184 # We default to rebuild_zebra.pl if no alternate indexer set
185 INDEXER_DAEMON
="${KOHA_HOME}/bin/migration_tools/rebuild_zebra.pl"
188 if [ $INDEXER_TIMEOUT -lt 1 ]; then
189 # Something's wrong, default to 5 seconds
193 if [ -z $INDEXER_PARAMS ]; then
194 # Default to the parameters required by rebuild_zebra.pl
195 INDEXER_PARAMS
="-daemon -x -sleep $INDEXER_TIMEOUT"
198 if [ -z $PERL5LIB ]; then
199 PERL5LIB
="/usr/share/koha/lib"
204 if [ $# -gt 0 ]; then
205 # We have at least one instance name
208 if is_instance
$name; then
218 restart_indexer
$name
223 if [ "$quiet" = "no" ]; then
224 log_daemon_msg
"Error: Invalid instance name $name"
231 if [ "$quiet" = "no" ]; then
232 warn
"Error: you must provide at least one instance name"