Bug 26145: DBIC schema changes
[koha.git] / debian / scripts / koha-indexer
blob62efb1cd8549a228b86bccc7e06fdc0939d87a40
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 --status Show the status of the indexer for the specified instances
51 --quiet|-q Make the script quiet about non existent instance names
52 (useful for calling from another scripts).
53 --help|-h Display this help message
55 EOF
58 start_indexer()
60 local name=$1
62 if ! is_indexer_running $name; then
63 export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml"
65 DAEMONOPTS="--name=$name-koha-indexer \
66 --errlog=/var/log/koha/$name/indexer-error.log \
67 --stdout=/var/log/koha/$name/indexer.log \
68 --output=/var/log/koha/$name/indexer-output.log \
69 --pidfiles=/var/run/koha/$name/ \
70 --verbose=1 --respawn --delay=30 \
71 --user=$name-koha.$name-koha"
73 log_daemon_msg "Starting Koha indexing daemon for $name"
75 if daemon $DAEMONOPTS -- $INDEXER_DAEMON $INDEXER_PARAMS; then
76 log_end_msg 0
77 else
78 log_end_msg 1
80 else
81 log_daemon_msg "Error: Indexer already running for $name"
82 log_end_msg 1
86 stop_indexer()
88 local name=$1
90 if is_indexer_running $name; then
91 export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml"
93 DAEMONOPTS="--name=$name-koha-indexer \
94 --errlog=/var/log/koha/$name/indexer-error.log \
95 --stdout=/var/log/koha/$name/indexer.log \
96 --output=/var/log/koha/$name/indexer-output.log \
97 --pidfiles=/var/run/koha/$name/ \
98 --verbose=1 --respawn --delay=30 \
99 --user=$name-koha.$name-koha"
101 log_daemon_msg "Stopping Koha indexing daemon for $name"
103 if daemon $DAEMONOPTS --stop -- $INDEXER_DAEMON $INDEXER_PARAMS; then
104 log_end_msg 0
105 else
106 log_end_msg 1
108 else
109 log_daemon_msg "Error: Indexer not running for $name"
110 log_end_msg 1
114 restart_indexer()
116 local name=$1
118 if is_indexer_running $name; then
119 export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml"
121 DAEMONOPTS="--name=$name-koha-indexer \
122 --errlog=/var/log/koha/$name/indexer-error.log \
123 --stdout=/var/log/koha/$name/indexer.log \
124 --output=/var/log/koha/$name/indexer-output.log \
125 --pidfiles=/var/run/koha/$name/ \
126 --verbose=1 --respawn --delay=30 \
127 --user=$name-koha.$name-koha"
129 log_daemon_msg "Restarting Koha indexing daemon for $name"
131 if daemon $DAEMONOPTS --restart -- $INDEXER_DAEMON $INDEXER_PARAMS; then
132 log_end_msg 0
133 else
134 log_end_msg 1
136 else
137 log_daemon_msg "Error: Indexer not running for $name"
138 log_end_msg 1
142 indexer_status()
144 local name=$1
146 if is_indexer_running ${name}; then
147 log_daemon_msg "Indexer running for ${name}"
148 log_end_msg 0
149 else
150 log_daemon_msg "Indexer not running for ${name}"
151 log_end_msg 3
155 set_action()
157 if [ "$op" = "" ]; then
158 op=$1
159 else
160 die "Error: only one action can be specified."
164 op=""
165 quiet="no"
167 # Read command line parameters
168 while [ $# -gt 0 ]; do
170 case "$1" in
171 -h|--help)
172 usage ; exit 0 ;;
173 -q|--quiet)
174 quiet="yes"
175 shift ;;
176 --start)
177 set_action "start"
178 shift ;;
179 --stop)
180 set_action "stop"
181 shift ;;
182 --restart)
183 set_action "restart"
184 shift ;;
185 --status)
186 set_action "status"
187 shift ;;
188 --debug)
189 DEBUG="-v -v"
190 shift ;;
192 die "Error: invalid option switch ($1)" ;;
194 # We expect the remaining stuff are the instance names
195 break ;;
196 esac
198 done
200 # Optionally use alternative paths for a dev install
201 adjust_paths_dev_install $1
203 # Check if an alternate indexer has been set
204 if [ ! -z $ALTERNATE_INDEXER_DAEMON ]; then
205 INDEXER_DAEMON="$ALTERNATE_INDEXER_DAEMON"
206 else
207 # We default to rebuild_zebra.pl if no alternate indexer set
208 if [ "$DEV_INSTALL" = "" ]; then
209 INDEXER_DAEMON="${KOHA_HOME}/bin/migration_tools/rebuild_zebra.pl"
210 else
211 INDEXER_DAEMON="${KOHA_HOME}/misc/migration_tools/rebuild_zebra.pl"
215 if [ $INDEXER_TIMEOUT -lt 1 ]; then
216 # Something's wrong, default to 5 seconds
217 INDEXER_TIMEOUT=5
220 if [ -z $INDEXER_PARAMS ]; then
221 # Default to the parameters required by rebuild_zebra.pl
222 INDEXER_PARAMS="-daemon -sleep $INDEXER_TIMEOUT $DEBUG"
225 # PERL5LIB has been read from etc/default
226 export PERL5LIB
228 if [ $# -gt 0 ]; then
229 # We have at least one instance name
230 for name in "$@"; do
232 if is_instance $name; then
234 case $op in
235 "start")
236 start_indexer $name
238 "stop")
239 stop_indexer $name
241 "restart")
242 restart_indexer $name
244 "status")
245 indexer_status $name
246 esac
248 else
249 if [ "$quiet" = "no" ]; then
250 log_daemon_msg "Error: Invalid instance name $name"
251 log_end_msg 1
255 done
256 else
257 if [ "$quiet" = "no" ]; then
258 warn "Error: you must provide at least one instance name"
262 exit 0