Bug 8918: Add a unit test for CalculatePriority
[koha.git] / debian / scripts / koha-stop-zebra
blobe60f2b37896eafef4908b3cd31238678e2b00843
1 #!/bin/sh
3 # koha-stop-zebra - Stop Zebra for named Koha instances
4 # Copyright 2010 Catalyst IT, Ltd
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.
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 die()
23 echo "$@" 1>&2
24 exit 1
27 warn()
29 echo "$@" 1>&2
32 is_enabled()
34 local instancename=$1
36 if ! is_instance $instancename; then
37 return 1
40 if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \
41 "/etc/apache2/sites-available/$instancename" ; then
42 return 1
43 else
44 return 0
48 is_instance()
50 local instancename=$1
52 if find /etc/koha/sites -mindepth 1 -maxdepth 1 \
53 -type d -printf '%f\n'\
54 | grep -q -x $instancename ; then
55 return 0
56 else
57 return 1
61 is_zebra_running()
63 local instancename=$1
65 if daemon --name="$instancename-koha-zebra" \
66 --user="$instancename-koha.$instancename-koha" \
67 --running ; then
68 return 0
69 else
70 return 1
74 stop_zebra_instance()
76 local instancename=$1
78 if is_zebra_running $instancename; then
79 echo "Stopping Zebra server for $instancename"
80 daemon \
81 --name="$instancename-koha-zebra" \
82 --errlog="/var/log/koha/$instancename/zebra-error.log" \
83 --stdout="/var/log/koha/$instancename/zebra.log" \
84 --output="/var/log/koha/$instancename/zebra-output.log" \
85 --verbose=1 \
86 --respawn \
87 --delay=30 \
88 --user="$instancename-koha.$instancename-koha" \
89 --stop \
90 -- \
91 zebrasrv \
92 -v none,fatal,warn \
93 -f "/etc/koha/sites/$instancename/koha-conf.xml" && \
94 return 0
95 else
96 return 1
100 usage()
102 local scriptname=$0
103 cat <<EOF
104 Stops Zebra for Koha instances.
106 Usage: $scriptname instancename1 instancename2...
111 # Parse command line.
112 #[ $# -ge 1 ] || ( usage ; die "Missing instance name..." )
114 # Loop through the instance names
115 for name in "$@"
117 if is_instance $name ; then
118 if is_enabled $name ; then
119 if is_zebra_running $name; then
120 if ! stop_zebra_instance $name; then
121 warn "Something went wrong stopping Zebra for $name."
123 else
124 warn "Zebra already stopped for instance $name."
126 else
127 warn "Instance $name disabled. No action taken."
129 else
130 warn "Unknown instance $name."
132 done
134 exit 0