3 # koha-zebra - Manage Zebra daemons for Koha instances
4 # Copyright 2016 Theke Solutions
5 # Copyright 2010 Catalyst IT, Ltd
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 . /lib/lsb/init-functions
24 # Read configuration variable file if it is present
25 [ -r /etc/default/koha-common ] && . /etc/default/koha-common
27 # include helper functions
28 if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
29 . "/usr/share/koha/bin/koha-functions.sh"
31 echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
37 local scriptname=$(basename $0)
42 This script lets you manage the Zebra daemon for your Koha instances.
45 $scriptname [--start|--stop|--restart] instancename1 [instancename2...]
48 --start Start the Zebra daemon for the specified instance(s)
49 --stop Stop the Zebra daemon for the specified instance(s)
50 --restart Restart the Zebra daemon for the specified instance(s)
51 --status Show the status of the Zebra daemon for the specified instance(s)
52 --verbose|-v Display progress and actions messages
53 --help|-h Display this help message
62 # get zebra log levels from koha-conf.xml
63 local loglevels=$(get_loglevels ${name})
65 if ! is_zebra_running $name; then
67 _check_and_fix_perms ${name}
69 DAEMONOPTS="--name=${name}-koha-zebra \
70 --pidfiles=/var/run/koha/${name}/ \
71 --errlog=/var/log/koha/${name}/zebra-error.log \
72 --output=/var/log/koha/${name}/zebra-output.log \
76 --user=${name}-koha.${name}-koha"
78 ZEBRA_PARAMS="-v $loglevels \
79 -f /etc/koha/sites/${name}/koha-conf.xml"
81 [ "$verbose" != "no" ] && \
82 log_daemon_msg "Starting Koha Zebra daemon for ${name}"
84 if daemon $DAEMONOPTS -- $ZEBRA_DAEMON $ZEBRA_PARAMS; then
85 [ "$verbose" != "no" ] && \
88 [ "$verbose" != "no" ] && \
92 if [ "$verbose" != "no" ]; then
93 log_daemon_msg "Error: Zebra already running for ${name}"
103 if is_zebra_running $name; then
105 DAEMONOPTS="--name=${name}-koha-zebra \
106 --pidfiles=/var/run/koha/${name}/ \
107 --errlog=/var/log/koha/${name}/zebra-error.log \
108 --output=/var/log/koha/${name}/zebra-output.log \
112 --user=${name}-koha.${name}-koha"
114 [ "$verbose" != "no" ] && \
115 log_daemon_msg "Stopping Koha Zebra daemon for ${name}"
117 if daemon $DAEMONOPTS --stop -- $ZEBRA_DAEMON $ZEBRA_PARAMS; then
118 [ "$verbose" != "no" ] && \
121 [ "$verbose" != "no" ] && \
125 if [ "$verbose" != "no" ]; then
126 log_daemon_msg "Error: Zebra not running for ${name}"
136 if is_zebra_running ${name}; then
138 stop_zebra ${name} && \
141 if [ "$verbose" != "no" ]; then
142 log_daemon_msg "Error: Zebra not running for ${name}"
152 if is_zebra_running; then
153 log_daemon_msg "Zebra running for ${name}"
156 log_daemon_msg "Zebra not running for ${name}"
161 _check_and_fix_perms()
165 local files="/var/log/koha/${name}/zebra-output.log \
166 /var/log/koha/${name}/zebra-error.log"
170 if [ ! -e "${file}" ]; then
173 chown "${name}-koha":"${name}-koha" ${file}
179 if [ "$op" = "" ]; then
182 die "Error: only one action can be specified."
189 # Backwards compatible with old koha-*-zebra scripts
190 # TODO: Remove once there's consensus to remove the legacy scripts
191 used_script_name=$(basename $0)
193 if [ "$used_script_name" != "koha-zebra" ]; then
194 warn "Deprecated script used (${used_script_name})"
196 case "$used_script_name" in
198 set_action "start" ;;
202 set_action "restart" ;;
207 # / Backwards compatible handling code
209 # Read command line parameters
210 while [ $# -gt 0 ]; do
228 die "Error: invalid option switch ($1)" ;;
230 # We expect the remaining stuff are the instance names
236 ZEBRA_DAEMON=$(which zebrasrv)
238 if [ $# -gt 0 ]; then
239 # We have at least one instance name
242 if is_instance $name; then
259 if [ "$verbose" != "no" ]; then
260 log_daemon_msg "Error: Invalid instance name $name"
267 if [ "$verbose" != "no" ]; then
268 warn "Error: you must provide at least one instance name"