Line 0
Link Here
|
0 |
- |
1 |
#!/bin/bash |
|
|
2 |
# |
3 |
# koha-indexer - Manage Indexer Daemons for Koha instances |
4 |
# Copyright 2012 Tomás Cohen Arazi @ Universidad Nacional de Córdoba |
5 |
# |
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. |
10 |
# |
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. |
15 |
# |
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/>. |
18 |
|
19 |
set -e |
20 |
|
21 |
. /lib/lsb/init-functions |
22 |
|
23 |
# Read configuration variable file if it is present |
24 |
[ -r /etc/default/koha-common ] && . /etc/default/koha-common |
25 |
|
26 |
warn() |
27 |
{ |
28 |
echo "$@" 1>&2 |
29 |
} |
30 |
|
31 |
die() |
32 |
{ |
33 |
echo "$@" 1>&2 |
34 |
exit 1 |
35 |
} |
36 |
|
37 |
usage() |
38 |
{ |
39 |
local scriptname=$(basename $0) |
40 |
|
41 |
cat <<EOF |
42 |
$scriptname |
43 |
|
44 |
This script lets you manage the indexer daemon for your Koha instances. |
45 |
|
46 |
Usage: |
47 |
$scriptname [--start|--stop|--restart] [--quiet|-q] instancename1 [instancename2...] |
48 |
$scriptname -h|--help |
49 |
|
50 |
--start Start the indexer daemon for the specified instances |
51 |
--stop Stop the indexer daemon for the specified instances |
52 |
--restart Restart the indexer daemon for the specified instances |
53 |
--quiet|-q Make the script quiet about non existent instance names |
54 |
--help|-h Display this help message |
55 |
|
56 |
EOF |
57 |
} |
58 |
|
59 |
is_instance() |
60 |
{ |
61 |
local instancename=$1 |
62 |
|
63 |
if find /etc/koha/sites -mindepth 1 -maxdepth 1 \ |
64 |
-type d -printf '%f\n'\ |
65 |
| grep -q -x -e "$instancename" ; then |
66 |
return 0 |
67 |
else |
68 |
return 1 |
69 |
fi |
70 |
} |
71 |
|
72 |
is_indexer_running() |
73 |
{ |
74 |
local instancename=$1 |
75 |
|
76 |
if daemon --name="$instancename-koha-indexer" \ |
77 |
--user="$instancename-koha.$instancename-koha" \ |
78 |
--running ; then |
79 |
return 0 |
80 |
else |
81 |
return 1 |
82 |
fi |
83 |
} |
84 |
|
85 |
start_indexer() |
86 |
{ |
87 |
local name=$1 |
88 |
|
89 |
if ! is_indexer_running $name; then |
90 |
export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" |
91 |
|
92 |
INDEXDAEMON_OPTS="--timeout $INDEXER_TIMEOUT \ |
93 |
--conf $KOHA_CONF \ |
94 |
--directory /var/tmp/koha-indexer-daemon-$name" |
95 |
|
96 |
DAEMONOPTS="--name=$name-koha-indexer \ |
97 |
--errlog=/var/log/koha/$name/indexer-error.log \ |
98 |
--stdout=/var/log/koha/$name/indexer.log \ |
99 |
--output=/var/log/koha/$name/indexer-output.log \ |
100 |
--verbose=1 --respawn --delay=30 \ |
101 |
--user=$name-koha.$name-koha" |
102 |
|
103 |
log_daemon_msg "Starting Koha indexing daemon for $name" |
104 |
|
105 |
if daemon $DAEMONOPTS -- $INDEXER_DAEMON $INDEXDAEMON_OPTS; then |
106 |
log_end_msg 0 |
107 |
else |
108 |
log_end_msg 1 |
109 |
fi |
110 |
else |
111 |
log_daemon_msg "Error: Indexer already running for $name" |
112 |
log_end_msg 1 |
113 |
fi |
114 |
} |
115 |
|
116 |
stop_indexer() |
117 |
{ |
118 |
local name=$1 |
119 |
|
120 |
if is_indexer_running $name; then |
121 |
export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" |
122 |
|
123 |
INDEXDAEMON_OPTS="--timeout 30 \ |
124 |
--conf $KOHA_CONF \ |
125 |
--directory /var/tmp/koha-indexer-daemon-$name" |
126 |
|
127 |
DAEMONOPTS="--name=$name-koha-indexer \ |
128 |
--errlog=/var/log/koha/$name/indexer-error.log \ |
129 |
--stdout=/var/log/koha/$name/indexer.log \ |
130 |
--output=/var/log/koha/$name/indexer-output.log \ |
131 |
--verbose=1 --respawn --delay=30 \ |
132 |
--user=$name-koha.$name-koha" |
133 |
|
134 |
log_daemon_msg "Stopping Koha indexing daemon for $name" |
135 |
|
136 |
if daemon $DAEMONOPTS --stop -- $INDEXER_DAEMON $INDEXDAEMON_OPTS; then |
137 |
log_end_msg 0 |
138 |
else |
139 |
log_end_msg 1 |
140 |
fi |
141 |
else |
142 |
log_daemon_msg "Error: Indexer not running for $name" |
143 |
log_end_msg 1 |
144 |
fi |
145 |
} |
146 |
|
147 |
restart_indexer() |
148 |
{ |
149 |
local name=$1 |
150 |
|
151 |
if is_indexer_running $name; then |
152 |
export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" |
153 |
|
154 |
INDEXDAEMON_OPTS="--timeout 30 \ |
155 |
--conf $KOHA_CONF \ |
156 |
--directory /var/tmp/koha-indexer-daemon-$name" |
157 |
|
158 |
DAEMONOPTS="--name=$name-koha-indexer \ |
159 |
--errlog=/var/log/koha/$name/indexer-error.log \ |
160 |
--stdout=/var/log/koha/$name/indexer.log \ |
161 |
--output=/var/log/koha/$name/indexer-output.log \ |
162 |
--verbose=1 --respawn --delay=30 \ |
163 |
--user=$name-koha.$name-koha" |
164 |
|
165 |
log_daemon_msg "Stopping Koha indexing daemon for $name" |
166 |
|
167 |
if daemon $DAEMONOPTS --restart -- $INDEXER_DAEMON $INDEXDAEMON_OPTS; then |
168 |
log_end_msg 0 |
169 |
else |
170 |
log_end_msg 1 |
171 |
fi |
172 |
else |
173 |
log_daemon_msg "Error: Indexer not running for $name" |
174 |
log_end_msg 1 |
175 |
fi |
176 |
} |
177 |
|
178 |
set_action() |
179 |
{ |
180 |
if [ "$op" = "" ]; then |
181 |
op=$1 |
182 |
else |
183 |
die "Error: only one action can be specified." |
184 |
fi |
185 |
} |
186 |
|
187 |
op="" |
188 |
quiet="no" |
189 |
|
190 |
# Read command line parameters |
191 |
while [ $# -gt 0 ]; do |
192 |
|
193 |
case "$1" in |
194 |
-h|--help) |
195 |
usage ; exit 0 ;; |
196 |
-q|--quiet) |
197 |
quiet="yes" |
198 |
shift ;; |
199 |
--start) |
200 |
set_action "start" |
201 |
shift ;; |
202 |
--stop) |
203 |
set_action "stop" |
204 |
shift ;; |
205 |
--restart) |
206 |
set_action "restart" |
207 |
shift ;; |
208 |
-*) |
209 |
die "Error: invalid option switch ($1)" ;; |
210 |
*) |
211 |
# We expect the remaining stuff are the instance names |
212 |
break ;; |
213 |
esac |
214 |
|
215 |
done |
216 |
|
217 |
# Some default variables |
218 |
if [ -z $INDEXER_DAEMON ]; then |
219 |
INDEXER_DAEMON="koha-index-daemon" |
220 |
fi |
221 |
|
222 |
if [ -z $PERL5LIB ]; then |
223 |
PERL5LIB="/usr/share/koha/lib" |
224 |
fi |
225 |
|
226 |
export PERL5LIB |
227 |
|
228 |
if [ $INDEXER_TIMEOUT -lt 1 ]; then |
229 |
# Something's wrong, default to 30 |
230 |
INDEXER_TIMEOUT=30 |
231 |
fi |
232 |
|
233 |
|
234 |
if [ ! -e /usr/share/perl5/Koha/Contrib/Tamil/IndexerDaemon.pm ] ; then |
235 |
MSG=`cat <<EOF |
236 |
Koha::Contrib::Tamil::IndexerDaemon was not found. See |
237 |
http://wiki.koha-community.org/wiki/PackagesIndexDaemon |
238 |
for instructions on setting up the indexer daemon. |
239 |
EOF` |
240 |
|
241 |
die $MSG |
242 |
fi |
243 |
|
244 |
|
245 |
if [ $# -gt 0 ]; then |
246 |
# We have at least one instance name |
247 |
for name in "$@"; do |
248 |
|
249 |
if is_instance $name; then |
250 |
|
251 |
case $op in |
252 |
"start") |
253 |
start_indexer $name |
254 |
;; |
255 |
"stop") |
256 |
stop_indexer $name |
257 |
;; |
258 |
"restart") |
259 |
restart_indexer $name |
260 |
;; |
261 |
esac |
262 |
|
263 |
else |
264 |
if [ "$quiet" = "no" ]; then |
265 |
log_daemon_msg "Error: Invalid instance name $name" |
266 |
log_end_msg 1 |
267 |
fi |
268 |
fi |
269 |
|
270 |
done |
271 |
else |
272 |
if [ "$quiet" = "no" ]; then |
273 |
warn "Error: you must provide at least one instance name" |
274 |
fi |
275 |
fi |
276 |
|
277 |
exit 0 |