From 95d07b25770338256d5702560f6d19b17db8e0bc Mon Sep 17 00:00:00 2001 From: Ere Maijala Date: Fri, 11 Jan 2019 11:27:56 +0200 Subject: [PATCH] Bug 13937: Add support for Z39.50 responder to the Debian scripts --- debian/koha-common.init | 20 ++ debian/scripts/koha-create | 5 +- debian/scripts/koha-functions.sh | 23 ++ debian/scripts/koha-list | 43 +++- debian/scripts/koha-z3950-responder | 354 ++++++++++++++++++++++++++++ etc/z3950/config.xml | 1 + misc/z3950_responder.pl | 5 - 7 files changed, 443 insertions(+), 8 deletions(-) create mode 100755 debian/scripts/koha-z3950-responder diff --git a/debian/koha-common.init b/debian/koha-common.init index a223ec6076..b5bf26b6bf 100755 --- a/debian/koha-common.init +++ b/debian/koha-common.init @@ -60,6 +60,7 @@ do_start() koha-zebra --start $(koha-list --enabled) koha-start-sip $(koha-list --enabled) koha-plack --start $(koha-list --enabled --plack) + koha-z3950-responder --start $(koha-list --enabled --z3950) if [ "$USE_INDEXER_DAEMON" = "yes" ]; then koha-indexer --start --quiet $(koha-list --enabled) @@ -149,6 +150,24 @@ plack_status() done } +# +# Function that shows the status of the Z39.50/SRU server daemon for +# enabled instances +# +z3950_status() +{ + for instance in $(koha-list --enabled --z3950); do + + log_daemon_msg "Z39.50/SRU daemon running for instance ${instance}" + + if is_z3950_running $instance ; then + log_end_msg 0 + else + log_end_msg 1 + fi + done +} + case "$1" in start) [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" @@ -191,6 +210,7 @@ case "$1" in zebra_status sip_status plack_status + z3950_status ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2 diff --git a/debian/scripts/koha-create b/debian/scripts/koha-create index 5e60f7cd77..ad1ff9db3c 100755 --- a/debian/scripts/koha-create +++ b/debian/scripts/koha-create @@ -55,8 +55,9 @@ Options: values are cs, en (default), es, fr, gr, nb, ru and uk. --memcached-servers str Set a comma-separated list of host:port memcached servers. --memcached-prefix str Set the desired prefix for the instance memcached namespace. - --enable-sru Enable the Z39.50/SRU server (default: disabled). - --sru-port Specifiy a TCP port number for the Z39.50/SRU server + --enable-sru Enable the Z39.50/SRU server in Zebra search engine + (default: disabled). + --sru-port Specify a TCP port number for Zebra's Z39.50/SRU server to listen on. (default: 7090). --defaultsql some.sql Specify a default SQL file to be loaded on the DB. --configfile cfg_file Specify an alternate config file for reading default values. diff --git a/debian/scripts/koha-functions.sh b/debian/scripts/koha-functions.sh index 6e189b6c94..fb6490b222 100755 --- a/debian/scripts/koha-functions.sh +++ b/debian/scripts/koha-functions.sh @@ -216,6 +216,29 @@ is_plack_running() fi } +is_z3950_enabled() +{ + local instancename=$1 + + if [ -e /etc/koha/sites/$instancename/z3950/config.xml ]; then + return 0 + else + return 1 + fi +} + +is_z3950_running() +{ + local instancename=$1 + + if start-stop-daemon --pidfile "/var/run/koha/${instancename}/z3950-responder.pid" \ + --status ; then + return 0 + else + return 1 + fi +} + adjust_paths_dev_install() { # Adjust KOHA_HOME, PERL5LIB for dev installs, as indicated by diff --git a/debian/scripts/koha-list b/debian/scripts/koha-list index 0dd72e1a94..a88d37b892 100755 --- a/debian/scripts/koha-list +++ b/debian/scripts/koha-list @@ -39,6 +39,7 @@ show_instances() if instance_filter_email $instance $show_email && \ instance_filter_letsencrypt $instance $show_letsencrypt && \ instance_filter_plack $instance $show_plack && \ + instance_filter_z3950 $instance $show_z3950 && \ instance_filter_sip $instance $show_sip; then echo $instance fi ;; @@ -47,6 +48,7 @@ show_instances() if instance_filter_email $instance $show_email && \ instance_filter_letsencrypt $instance $show_letsencrypt && \ instance_filter_plack $instance $show_plack && \ + instance_filter_z3950 $instance $show_z3950 && \ instance_filter_sip $instance $show_sip; then echo $instance fi @@ -56,6 +58,7 @@ show_instances() if instance_filter_email $instance $show_email && \ instance_filter_letsencrypt $instance $show_letsencrypt && \ instance_filter_plack $instance $show_plack && \ + instance_filter_z3950 $instance $show_z3950 && \ instance_filter_sip $instance $show_sip; then echo $instance fi @@ -153,6 +156,28 @@ instance_filter_email() return 1 } +instance_filter_z3950() +{ + local instancename=$1 + local show_z3950=$2; + + case $show_z3950 in + "all") + return 0 ;; + "enabled") + if is_z3950_enabled $instancename; then + return 0 + fi ;; + "disabled") + if ! is_z3950_enabled $instancename; then + return 0 + fi ;; + esac + + # Didn't match any criteria + return 1 +} + set_show() { local show_param=$1 @@ -208,6 +233,17 @@ set_show_sip() fi } +set_show_z3950() +{ + local z3950_param=$1 + + if [ "$show_z3950" = "all" ]; then + show_z3950=$z3950_param + else + die "Error: --z3950 and --noz3950 are mutually exclusive." + fi +} + usage() { local scriptname=$0 @@ -228,6 +264,8 @@ Options: --noplack Show instances with Plack disabled --letsencrypt Show instances with letsencrypt enabled --noletsencrypt Show instances with letsencrypt disabled + --z3950 Show instances with Z39.50/SRU enabled + --noz3950 Show instances with Z39.50/SRU disabled --help | -h Show this help The filtering options can be combined, and you probably want to do this @@ -240,8 +278,9 @@ show_email="all" show_sip="all" show_plack="all" show_letsencrypt="all" +show_z3950="all" -args=$(getopt -l help,enabled,disabled,email,noemail,sip,nosip,plack,noplack,letsencrypt,noletsencrypt -o h -n $0 -- "$@") +args=$(getopt -l help,enabled,disabled,email,noemail,sip,nosip,plack,noplack,letsencrypt,noletsencrypt,z3950,noz3950 -o h -n $0 -- "$@") set -- $args while [ ! -z "$1" ] @@ -256,6 +295,8 @@ do --noplack) set_show_plack "disabled" ;; --letsencrypt) set_show_letsencrypt "enabled" ;; --noletsencrypt) set_show_letsencrypt "disabled" ;; + --z3950) set_show_z3950 "enabled" ;; + --noz3950) set_show_z3950 "disabled" ;; --enabled) set_show "enabled" ;; --disabled) set_show "disabled" ;; *) break;; diff --git a/debian/scripts/koha-z3950-responder b/debian/scripts/koha-z3950-responder new file mode 100755 index 0000000000..7ac55ab6e0 --- /dev/null +++ b/debian/scripts/koha-z3950-responder @@ -0,0 +1,354 @@ +#!/bin/bash +# +# Copyright 2015 Theke Solutions +# Copyright 2016 Koha-Suomi +# Copyright 2018 The National Library of Finland, University of Helsinki +# +# This file is part of Koha. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +set -e + +. /lib/lsb/init-functions + +# Read configuration variable file if it is present +[ -r /etc/default/koha-common ] && . /etc/default/koha-common + +# include helper functions +if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then + . "/usr/share/koha/bin/koha-functions.sh" +else + echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2 + exit 1 +fi + +usage() +{ + local scriptname=$(basename $0) + + cat < /dev/stderr + return 1 + fi + + local configdir=/etc/koha/sites/${instancename}/z3950 + if [ -e ${configdir}/config.xml ] + then + [ "${quiet}" != "yes" ] && warn "Z39.50/SRU already enabled for $name" + return 1 + fi + + if [ ! -e ${configdir} ] + then + mkdir ${configdir} + fi + cp /etc/koha/z3950/* ${configdir}/ + chown ${name}-koha:${name}-koha ${configdir}/* + chmod 600 ${configdir}/* + + [ "${quiet}" != "yes" ] && warn "Z39.50/SRU enabled for $name - edit files in ${configdir} to configure" + return 0 +} + +disable_z3950() +{ + local instancename=$1 + + if is_z3950_enabled $instancename; then + local configdir=/etc/koha/sites/${instancename}/z3950 + mv ${configdir} ${configdir}.`date +%F_%T` + [ "${quiet}" != "yes" ] && warn "Z39.50/SRU disabled for ${instancename}" + return 0 + else + [ "${quiet}" != "yes" ] && warn "Z39.50/SRU already disabled for ${instancename}" + return 1 + fi +} + +_check_and_fix_perms() +{ + local instance=$1 + + local files="/var/log/koha/${instance}/z3950.log" + + for file in ${files} + do + if [ ! -e "${file}" ]; then + touch ${file} + fi + chown "${instance}-koha":"${instance}-koha" ${file} + done +} + +set_action() +{ + if [ "$op" = "" ]; then + op=$1 + else + die "Error: only one action can be specified." + fi +} + +op="" +quiet="no" +debug_mode="no" +debugger_key="" +debugger_location="localhost:9000" +debugger_path="" + +# Read command line parameters +while [ $# -gt 0 ]; do + + case "$1" in + -h|--help) + usage ; exit 0 ;; + -q|--quiet) + quiet="yes" + shift ;; + --start) + set_action "start" + shift ;; + --stop) + set_action "stop" + shift ;; + --restart) + set_action "restart" + shift ;; + --enable) + set_action "enable" + shift ;; + --disable) + set_action "disable" + shift ;; + --debugger) + debug_mode="yes" + shift ;; + --debugger-key) + debugger_key="$2" + shift 2 ;; + --debugger-location) + debugger_location="$2" + shift 2 ;; + --debugger-path) + debugger_path="$2" + shift 2 ;; + -*) + die "Error: invalid option switch ($1)" ;; + *) + # We expect the remaining stuff are the instance names + break ;; + esac + +done + +if [ $# -gt 0 ]; then + # We have at least one instance name + for name in "$@"; do + + if is_instance $name; then + + adjust_paths_dev_install $name + export DEV_INSTALL + export KOHA_HOME + PERL5LIB=$PERL5LIB:$KOHA_HOME/installer:$KOHA_HOME/lib/installer + # If debug mode is enabled, add the debugger lib path + # to PERL5LIB if appropriate + if [ "$debug_mode" = "yes" ]; then + if [ "$debugger_path" != "" ]; then + PERL5LIB="${debugger_path}":$PERL5LIB + fi + export PERL5DB="BEGIN { require q(${debugger_path}/perl5db.pl) }" + export PERLDB_OPTS="RemotePort=${debugger_location} async=1 LogFile=/var/log/koha/${name}/z3950-debug.log" + export DBGP_IDEKEY=${debugger_key} + export PERL5OPT="-d" + fi + + export PERL5LIB + + case $op in + "start") + start_z3950 $name + ;; + "stop") + stop_z3950 $name + ;; + "restart") + restart_z3950 $name + ;; + "enable") + enable_z3950 $name + ;; + "disable") + disable_z3950 $name + ;; + *) + usage + ;; + esac + + else + if [ "$quiet" = "no" ]; then + log_daemon_msg "Error: Invalid instance name $name" + log_end_msg 1 + fi + fi + + done +else + if [ "$quiet" = "no" ]; then + warn "Error: you must provide at least one instance name" + fi +fi + +exit 0 diff --git a/etc/z3950/config.xml b/etc/z3950/config.xml index bb9c2a6eff..7433851f8b 100644 --- a/etc/z3950/config.xml +++ b/etc/z3950/config.xml @@ -1,4 +1,5 @@ + tcp:@:2100 pqf.properties diff --git a/misc/z3950_responder.pl b/misc/z3950_responder.pl index e6fa623a62..871fca676f 100755 --- a/misc/z3950_responder.pl +++ b/misc/z3950_responder.pl @@ -156,11 +156,6 @@ GetOptions( pod2usage(1) if $help; pod2usage( -verbose => 2 ) if $man; -if (!@ARGV || $ARGV[-1] =~ /^-/) { - # No bind address specified. Use @:2100 by default. - push(@ARGV, '@:2100'); -} - # If config_dir is not defined, default to z3950 under the Koha config directory if (!$config_dir) { (undef, $config_dir) = fileparse(Koha::Config->guess_koha_conf); -- 2.17.1