Bug 13499: Tidy of Auth.pm
[koha.git] / debian / scripts / koha-indexer
blobc7c28588400b5d9ac439f1b09175a67ccbc008f5
1 #!/bin/bash
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/>.
19 set -e
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"
29 else
30 echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
31 exit 1
34 usage()
36 local scriptname=$(basename $0)
38 cat <<EOF
39 $scriptname
41 This script lets you manage the indexer daemon for your Koha instances.
43 Usage:
44 $scriptname [--start|--stop|--restart] [--quiet|-q] instancename1 [instancename2...]
45 $scriptname -h|--help
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
54 EOF
57 start_indexer()
59 local name=$1
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 --verbose=1 --respawn --delay=30 \
69 --user=$name-koha.$name-koha"
71 log_daemon_msg "Starting Koha indexing daemon for $name"
73 if daemon $DAEMONOPTS -- $INDEXER_DAEMON $INDEXER_PARAMS; then
74 log_end_msg 0
75 else
76 log_end_msg 1
78 else
79 log_daemon_msg "Error: Indexer already running for $name"
80 log_end_msg 1
84 stop_indexer()
86 local name=$1
88 if is_indexer_running $name; then
89 export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml"
91 DAEMONOPTS="--name=$name-koha-indexer \
92 --errlog=/var/log/koha/$name/indexer-error.log \
93 --stdout=/var/log/koha/$name/indexer.log \
94 --output=/var/log/koha/$name/indexer-output.log \
95 --verbose=1 --respawn --delay=30 \
96 --user=$name-koha.$name-koha"
98 log_daemon_msg "Stopping Koha indexing daemon for $name"
100 if daemon $DAEMONOPTS --stop -- $INDEXER_DAEMON $INDEXER_PARAMS; then
101 log_end_msg 0
102 else
103 log_end_msg 1
105 else
106 log_daemon_msg "Error: Indexer not running for $name"
107 log_end_msg 1
111 restart_indexer()
113 local name=$1
115 if is_indexer_running $name; then
116 export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml"
118 DAEMONOPTS="--name=$name-koha-indexer \
119 --errlog=/var/log/koha/$name/indexer-error.log \
120 --stdout=/var/log/koha/$name/indexer.log \
121 --output=/var/log/koha/$name/indexer-output.log \
122 --verbose=1 --respawn --delay=30 \
123 --user=$name-koha.$name-koha"
125 log_daemon_msg "Stopping Koha indexing daemon for $name"
127 if daemon $DAEMONOPTS --restart -- $INDEXER_DAEMON $INDEXER_PARAMS; then
128 log_end_msg 0
129 else
130 log_end_msg 1
132 else
133 log_daemon_msg "Error: Indexer not running for $name"
134 log_end_msg 1
138 set_action()
140 if [ "$op" = "" ]; then
141 op=$1
142 else
143 die "Error: only one action can be specified."
147 op=""
148 quiet="no"
150 # Read command line parameters
151 while [ $# -gt 0 ]; do
153 case "$1" in
154 -h|--help)
155 usage ; exit 0 ;;
156 -q|--quiet)
157 quiet="yes"
158 shift ;;
159 --start)
160 set_action "start"
161 shift ;;
162 --stop)
163 set_action "stop"
164 shift ;;
165 --restart)
166 set_action "restart"
167 shift ;;
169 die "Error: invalid option switch ($1)" ;;
171 # We expect the remaining stuff are the instance names
172 break ;;
173 esac
175 done
177 # Check if an alternate indexer has been set
178 if [ -z $ALTERNATE_INDEXER_DAEMON ]; then
179 INDEXER_DAEMON="$ALTERNATE_INDEXER_DAEMON"
180 else
181 # We default to rebuild_zebra.pl if no alternate indexer set
182 INDEXER_DAEMON="${KOHA_HOME}/bin/migration_tools/rebuild_zebra.pl"
185 if [ $INDEXER_TIMEOUT -lt 1 ]; then
186 # Something's wrong, default to 5 seconds
187 INDEXER_TIMEOUT=5
190 if [ -z $INDEXER_PARAMS ]; then
191 # Default to the parameters required by rebuild_zebra.pl
192 INDEXER_PARAMS="-daemon -x -sleep $INDEXER_TIMEOUT"
195 if [ -z $PERL5LIB ]; then
196 PERL5LIB="/usr/share/koha/lib"
199 export PERL5LIB
201 if [ $# -gt 0 ]; then
202 # We have at least one instance name
203 for name in "$@"; do
205 if is_instance $name; then
207 case $op in
208 "start")
209 start_indexer $name
211 "stop")
212 stop_indexer $name
214 "restart")
215 restart_indexer $name
217 esac
219 else
220 if [ "$quiet" = "no" ]; then
221 log_daemon_msg "Error: Invalid instance name $name"
222 log_end_msg 1
226 done
227 else
228 if [ "$quiet" = "no" ]; then
229 warn "Error: you must provide at least one instance name"
233 exit 0