3 # Copyright 2015 Theke Solutions
4 # Copyright 2016 Koha-Suomi
5 # Copyright 2018 The National Library of Finland, University of Helsinki
7 # This file is part of Koha.
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 . /lib/lsb/init-functions
26 # Read configuration variable file if it is present
27 [ -r /etc/default/koha-common ] && . /etc/default/koha-common
29 # include helper functions
30 if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
31 . "/usr/share/koha/bin/koha-functions.sh"
33 echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
39 local scriptname=$(basename $0)
44 This script lets you manage the Z39.50/SRU daemons for your Koha instances.
47 $scriptname --start|--stop|--restart [--quiet|-q] instancename1 [instancename2...]
48 $scriptname --enable|--disable instancename1 [instancename2]
51 --start Start the Z39.50/SRU daemon for the specified instances
52 --stop Stop the Z39.50/SRU daemon for the specified instances
53 --restart Restart the Z39.50/SRU daemon for the specified instances
54 --enable Enable Z39.50/SRU for the specified instances
55 --disable Disable Z39.50/SRU for the specified instances
56 --debugger Enable running Z39.50/SRU in debug mode
57 --debugger-key Specify the key the IDE is expecting
58 --debugger-location Specify the host:port for your debugger tool (defaults
60 --debugger-path Specify the path for the debugger library
61 --quiet|-q Make the script quiet about non existent instance names
62 (useful for calling from another scripts).
63 --help|-h Display this help message
72 local PIDFILE="/var/run/koha/${instancename}/z3950-responder.pid"
73 local NAME="${instancename}-koha-z3950-responder"
74 local CONFIGDIR="/etc/koha/z3950"
76 if [ -e "/etc/koha/sites/${instancename}/z3950/config.xml" ]; then
77 # pick instance-specific config dir
78 CONFIGDIR="/etc/koha/sites/${instancename}/z3950"
79 fi # else stick with the default one
81 _check_and_fix_perms $instancename
83 instance_user="${instancename}-koha"
85 daemonize="-D -d ${instancename}-koha-z3950"
86 logging="-l /var/log/koha/${instancename}/z3950.log"
88 if [ "$DEV_INSTALL" = "1" ]; then
89 MISCDIR=$KOHA_HOME/misc
91 MISCDIR=/usr/share/koha/bin
94 Z3950RESPONDER="/usr/bin/perl $MISCDIR/z3950_responder.pl"
95 if [ "$debug_mode" = "yes" ]; then
96 if [ "$DEV_INSTALL" = "1" ]; then
97 warn "Not a dev install, disabling debug mode"
99 environment="development"
101 logging="" # remote debugger takes care
102 Z3950RESPONDER="/usr/bin/perl -d ${MISCDIR}/z3950_responder.pl"
106 Z3950OPTS="-c ${CONFIGDIR} \
107 -u ${instance_user} \
108 -p ${PIDFILE} ${daemonize} ${logging}"
110 if ! is_z3950_running ${instancename}; then
111 export KOHA_CONF="/etc/koha/sites/${instancename}/koha-conf.xml"
113 Z3950_ADDITIONAL_OPTS="$( xmlstarlet sel -t -v 'yazgfs/config/z3950_responder_options' $KOHA_CONF )"
115 log_daemon_msg "Starting Z39.50/SRU daemon for ${instancename}"
117 # Change to the instance's user dir
119 eval cd ~$instance_user
121 if ${Z3950RESPONDER} ${Z3950_ADDITIONAL_OPTS} ${Z3950OPTS}; then
126 # Go back to the original dir
130 log_daemon_msg "Error: Z39.50/SRU already running for ${instancename}"
137 local instancename=$1
139 local PIDFILE="/var/run/koha/${instancename}/z3950-responder.pid"
141 if is_z3950_running ${instancename}; then
143 log_daemon_msg "Stopping Z39.50/SRU daemon for ${instancename}"
145 if start-stop-daemon --pidfile ${PIDFILE} --stop --retry=TERM/30/KILL/5; then
151 log_daemon_msg "Error: Z39.50/SRU not running for ${instancename}"
158 local instancename=$1
160 local PIDFILE="/var/run/koha/${instancename}/z3950.pid"
162 if is_z3950_running ${instancename}; then
164 log_daemon_msg "Restarting Z39.50/SRU daemon for ${instancename}"
166 if stop_z3950 $instancename && start_z3950 $instancename; then
172 log_warning_msg "Z39.50/SRU not running for ${instancename}."
173 start_z3950 $instancename
179 local instancename=$1
181 if [ ! -e /etc/koha/sites/${instancename}/koha-conf.xml ] ;
183 echo "No such instance: ${instancename}" > /dev/stderr
187 local configdir=/etc/koha/sites/${instancename}/z3950
188 if [ -e ${configdir}/config.xml ]
190 [ "${quiet}" != "yes" ] && warn "Z39.50/SRU already enabled for $name"
194 if [ ! -e ${configdir} ]
198 cp /etc/koha/z3950/* ${configdir}/
199 chown ${name}-koha:${name}-koha ${configdir}/*
200 chmod 600 ${configdir}/*
202 [ "${quiet}" != "yes" ] && warn "Z39.50/SRU enabled for $name - edit files in ${configdir} to configure"
208 local instancename=$1
210 if is_z3950_enabled $instancename; then
211 local configdir=/etc/koha/sites/${instancename}/z3950
212 mv ${configdir} ${configdir}.`date +%F_%T`
213 [ "${quiet}" != "yes" ] && warn "Z39.50/SRU disabled for ${instancename}"
216 [ "${quiet}" != "yes" ] && warn "Z39.50/SRU already disabled for ${instancename}"
221 _check_and_fix_perms()
225 local files="/var/log/koha/${instance}/z3950.log"
229 if [ ! -e "${file}" ]; then
232 chown "${instance}-koha":"${instance}-koha" ${file}
238 if [ "$op" = "" ]; then
241 die "Error: only one action can be specified."
249 debugger_location="localhost:9000"
252 # Read command line parameters
253 while [ $# -gt 0 ]; do
283 debugger_location="$2"
289 die "Error: invalid option switch ($1)" ;;
291 # We expect the remaining stuff are the instance names
297 if [ $# -gt 0 ]; then
298 # We have at least one instance name
301 if is_instance $name; then
303 adjust_paths_dev_install $name
306 PERL5LIB=$PERL5LIB:$KOHA_HOME/installer:$KOHA_HOME/lib/installer
307 # If debug mode is enabled, add the debugger lib path
308 # to PERL5LIB if appropriate
309 if [ "$debug_mode" = "yes" ]; then
310 if [ "$debugger_path" != "" ]; then
311 PERL5LIB="${debugger_path}":$PERL5LIB
313 export PERL5DB="BEGIN { require q(${debugger_path}/perl5db.pl) }"
314 export PERLDB_OPTS="RemotePort=${debugger_location} async=1 LogFile=/var/log/koha/${name}/z3950-debug.log"
315 export DBGP_IDEKEY=${debugger_key}
343 if [ "$quiet" = "no" ]; then
344 log_daemon_msg "Error: Invalid instance name $name"
351 if [ "$quiet" = "no" ]; then
352 warn "Error: you must provide at least one instance name"